From ee6cd23ab272537c86450971de33c01cadcfbbc7 Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Wed, 10 Dec 2025 09:59:15 +0100 Subject: [PATCH] CI: add wasm test build We can not actually run the test, but building it is a good start. --- .github/workflows/test.yaml | 19 +++++++++++++++++++ test/CMakeLists.txt | 19 ++++++++++++++++++- test/test_basic.cpp | 16 +++++++++++++--- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a6ab952..ae254f1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,3 +40,22 @@ jobs: cmake -D CMAKE_BUILD_TYPE=Debug .. cmake --build . ctest . -C Debug + + embuild: + # Just build with emscripten. There is no way to test the build yet. + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup emsdk + uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 + with: + version: 4.0.21 + actions-cache-folder: 'emsdk-cache' + - name: Verify emsdk + run: emcc -v + - name: build + run: | + mkdir build + cd build/ + emcmake cmake .. + emmake make diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 331c619..ab6b460 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,9 +10,16 @@ FetchContent_Declare( FetchContent_Declare( websocketpp URL https://github.com/zaphoyd/websocketpp/archive/4dfe1be74e684acca19ac1cf96cce0df9eac2a2d.zip) +# Desktop-only, without submodule: +#FetchContent_Declare( +# wswrap +# URL https://github.com/black-sliver/wswrap/archive/e71695c80e0338d0aa4f18e7e0f45b67681206be.zip) +# Complete, with submodule: FetchContent_Declare( wswrap - URL https://github.com/black-sliver/wswrap/archive/e71695c80e0338d0aa4f18e7e0f45b67681206be.zip) + GIT_REPOSITORY https://github.com/black-sliver/wswrap.git + GIT_TAG e71695c80e0338d0aa4f18e7e0f45b67681206be) + FetchContent_MakeAvailable(asio json websocketpp wswrap) add_executable(TestBasic test_basic.cpp) @@ -65,6 +72,16 @@ set_target_properties(TestBasic PROPERTIES CXX_EXTENSIONS NO ) +if(EMSCRIPTEN) + message("Configuring TestBasic for emscripten") + # embind requires C++17 + set_target_properties(TestBasic PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES + ) + target_link_options(TestBasic BEFORE PRIVATE "--bind") +endif() + # enable more warnings if(MSVC) target_compile_options(TestBasic PRIVATE /W4) diff --git a/test/test_basic.cpp b/test/test_basic.cpp index 8ef8864..6b541e2 100644 --- a/test/test_basic.cpp +++ b/test/test_basic.cpp @@ -4,11 +4,13 @@ #include #include #include -#include -#include #define usleep(usec) std::this_thread::sleep_for(std::chrono::microseconds(usec)) +#ifndef EMSCRIPTEN // we can not run websocket server in wasm +#include +#include + typedef websocketpp::server Server; class TestServer final { @@ -85,9 +87,11 @@ class TestServer final { server.send(hdl, roomInfo, websocketpp::frame::opcode::text); } }; +#endif // ndef EMSCRIPTEN int main(int, char**) { +#ifndef EMSCRIPTEN // we can not run websocket server in wasm printf("Starting server...\n"); TestServer server{38281, 38291}; std::thread serverThread(&TestServer::run, &server); @@ -99,13 +103,17 @@ int main(int, char**) if (!server.is_listening()) throw std::runtime_error("Timeout starting server"); printf("Server listening on %d\n", static_cast(server.get_port())); + const auto port = server.get_port(); +#else // !ndef EMSCRIPTEN + const uint16_t port = 38281; +#endif // ndef EMSCRIPTEN bool error = false; bool connected = false; bool roomInfo = false; bool releaseMode = false; { - const std::string uri = "ws://localhost:" + std::to_string(server.get_port()); + const std::string uri = "ws://localhost:" + std::to_string(port); printf("Starting client for %s...\n", uri.c_str()); APClient ap{"", "", uri}; @@ -141,9 +149,11 @@ int main(int, char**) // FIXME: ~APClient can throw } +#ifndef EMSCRIPTEN // we can not run websocket server in wasm printf("Stopping server...\n"); server.stop(); serverThread.join(); +#endif // ndef EMSCRIPTEN if (!connected) { fprintf(stderr, "FAIL: Could not connect socket\n");