init
All checks were successful
CMake on a single platform / build (push) Successful in 13s

This commit is contained in:
2025-10-10 22:01:22 +04:00
commit bd66a42b95
5 changed files with 231 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake on a single platform
on:
push:
branches: [ "master" ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
runs-on: archlinux
steps:
- uses: actions/checkout@v4
- name: Stop previous server if running
run: ~/stop.sh test-server || echo service was not started
- name: clear old installation
run: xargs rm < ~/build/test-server/install_manifest.txt || echo previous installation not found
- name: clear old builddir
run: rm -rf ~/build/test-server || echo previous installation not found
- name: update submodule
run: git submodule update --init --recursive
- name: Configure CMake
run: cmake -B ~/build/test-server -DCMAKE_INSTALL_PREFIX=~/.local
- name: Build
run: cmake --build ~/build/test-server
- name: install
run: make -C ~/build/test-server install
- name: Start server
run: ~/start.sh test-server

82
.gitignore vendored Normal file
View File

@@ -0,0 +1,82 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
*.qbs.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# Directories with generated files
.moc/
.obj/
.pch/
.rcc/
.uic/
/build*/

49
CMakeLists.txt Normal file
View File

@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.16)
project(server-example LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Wt REQUIRED
Wt
HTTP
)
include(GNUInstallDirs)
include_directories(
"src"
${CMAKE_CURRENT_BINARY_DIR})
add_executable(${PROJECT_NAME}
src/main.cpp
)
target_link_libraries(${PROJECT_NAME}
Wt::Wt
Wt::HTTP
)
configure_file(
${PROJECT_NAME}.sh.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.wt
)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.wt
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)

25
server-example.sh.in Normal file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
pid=''
run=true
start() {
@CMAKE_INSTALL_FULL_BINDIR@/@PROJECT_NAME@ \
--docroot=/var/empty;/favicon.ico,/resources,/style,/node_modules \
--http-address 0.0.0.0 --http-port 8087 \
--config /etc/Wt/wt_config.xml \
--resources-dir /usr/share/Wt/resources &> >(logger --tag @PROJECT_NAME@) & pid="$!"
}
shutdown() {
run=false
(( $pid )) && kill "$pid"
}
trap shutdown EXIT
start
while $run
do
wait "$pid" || { logger --tag @PROJECT_NAME@ -p 3 "restarting server after error"; start; }
done

32
src/main.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <Wt/WServer.h>
#include <Wt/WResource.h>
#include <Wt/Http/Request.h>
#include <Wt/Http/Response.h>
using namespace std;
using namespace Wt;
class TestResource : public WResource {
public:
void handleRequest(const Http::Request& request, Http::Response& response) override {
if ( const string* name = request.getParameter("name") ) {
response.out() << ( *name == string{"Heisenberg"}
? "You god damn right."
: "nope." )
<< endl;
} else {
response.setStatus(400);
response.out() << "say. my. name." << endl;
}
}
};
int main(int argc, char** argv) {
WServer server{argc, argv};
server.addResource(make_shared<TestResource>(), "/say-my-name");
server.run();
return 0;
}