Skip to content

Commit f31745f

Browse files
authored
#1538 Add emscripten build to CI
* Start work on #1538 * Refactor type casting and improve cache handling in various components, added Emscripten jobs for building and testing * Revert "Refactor type casting and improve cache handling in various components, added Emscripten jobs for building and testing" This reverts commit b24d632. * Add Emscripten build and test workflows to CI configuration * add emscriptten flag to cmake * Enhance CI workflow for Emscripten: add mock headers for backtrace and ptrace, enable tests, and improve test output logging * Enable Node.js tests in CI workflow for Emscripten builds * Also show js files generated * Improve CI test output and summary reporting for Emscripten builds * Refined output * Update node.js version to support wasm flag * Didn't realize 'act' on local was using node 18, we dont need wasm flag in node 20+ * Fixed double test output
1 parent 0d6b3ce commit f31745f

File tree

2 files changed

+168
-2
lines changed

2 files changed

+168
-2
lines changed

.github/workflows/ci.yml

+158-1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,163 @@ jobs:
454454
- name: build flecs
455455
run: ${{ matrix.compiler }} distr/flecs.c --shared -fPIC -pedantic -Wall -Wextra -Wno-unused-parameter -Werror -Wshadow -Wconversion -Wno-missing-field-initializers
456456

457+
build-emscripten:
458+
needs: build-linux
459+
runs-on: ubuntu-latest
460+
timeout-minutes: 30
461+
strategy:
462+
fail-fast: false
463+
464+
steps:
465+
- uses: actions/checkout@v4
466+
467+
- name: Setup Emscripten
468+
uses: mymindstorm/setup-emsdk@v14
469+
with:
470+
version: latest
471+
actions-cache-folder: 'emsdk-cache'
472+
473+
- name: Build flecs (debug)
474+
run: |
475+
emcmake cmake -B build_debug -DCMAKE_BUILD_TYPE=Debug -DFLECS_STRICT=ON
476+
emmake make -C build_debug -j 4
477+
478+
- name: Build flecs (release)
479+
run: |
480+
emcmake cmake -B build_release -DCMAKE_BUILD_TYPE=Release -DFLECS_STRICT=ON
481+
emmake make -C build_release -j 4
482+
483+
- name: Build C examples
484+
run: |
485+
cd examples/c
486+
emcmake cmake -B build -DFLECS_STRICT=ON
487+
emmake make -C build -j 4
488+
489+
- name: Build C++ examples
490+
run: |
491+
cd examples/cpp
492+
emcmake cmake -B build -DFLECS_STRICT=ON
493+
emmake make -C build -j 4
494+
495+
test-emscripten:
496+
needs: build-linux
497+
runs-on: ubuntu-latest
498+
timeout-minutes: 30
499+
strategy:
500+
fail-fast: false
501+
502+
steps:
503+
- uses: actions/checkout@v4
504+
505+
- name: Clone bake repository for test driver
506+
run: |
507+
git clone https://github.com/SanderMertens/bake
508+
make -C bake/build-$(uname) CFLAGS="-fPIC"
509+
bake/bake setup
510+
511+
- name: Setup Emscripten
512+
uses: mymindstorm/setup-emsdk@v14
513+
with:
514+
version: latest
515+
actions-cache-folder: 'emsdk-cache'
516+
517+
- name: Build tests
518+
run: |
519+
mkdir -p test/build
520+
mkdir -p test/build/include/sys && \
521+
echo "#include <stdlib.h>
522+
__attribute__((weak)) int backtrace(void **buffer, int size) { return 0; }
523+
__attribute__((weak)) char **backtrace_symbols(void *const *buffer, int size) { return NULL; }
524+
__attribute__((weak)) void backtrace_symbols_fd(void *const *buffer, int size, int fd) {}" > test/build/include/execinfo.h && \
525+
echo "#include <unistd.h>
526+
#define PTRACE_TRACEME 0
527+
#define PTRACE_ATTACH 1
528+
#define PTRACE_DETACH 2
529+
__attribute__((weak)) long ptrace(int request, pid_t pid, void *addr, void *data) { return 0; }" > test/build/include/sys/ptrace.h && \
530+
export CFLAGS="-isystem $(pwd)/test/build/include -D__linux__ -D__x86_64__ -pthread" && \
531+
export CXXFLAGS="-isystem $(pwd)/test/build/include -D__linux__ -D__x86_64__ -pthread" && \
532+
emcmake cmake -B test/build \
533+
-DCMAKE_BUILD_TYPE=Debug \
534+
-DFLECS_STATIC=ON \
535+
-DFLECS_PIC=ON \
536+
-DFLECS_STRICT=ON \
537+
-DFLECS_TESTS=ON \
538+
-DBAKE_DIRECTORY=bake \
539+
-DNODE_JS_TEST=ON \
540+
-DCMAKE_EXECUTABLE_SUFFIX=".js" \
541+
-DCMAKE_EXE_LINKER_FLAGS="-s DISABLE_EXCEPTION_CATCHING=0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=2"
542+
cd test/build
543+
emmake make -j 4
544+
545+
- name: Validate test files
546+
run: |
547+
cd test/build
548+
echo "Validating test files..."
549+
# Show directory contents for debugging
550+
echo "Directory contents:"
551+
ls -la
552+
echo "-------------------------"
553+
# First list all JS files
554+
echo "Found JS files:"
555+
find . -name "*.js" -type f
556+
echo "-------------------------"
557+
# Then check each file individually
558+
for file in $(find . -name "*.js" -type f); do
559+
if [ -f "$file" ]; then
560+
echo ""
561+
echo "Checking $file..."
562+
echo "File contents preview (first 10 lines):"
563+
head -n 10 "$file"
564+
echo "-------------------------"
565+
# Validate file is a proper JavaScript/Emscripten output
566+
if ! grep -q "var Module" "$file"; then
567+
echo "Error: $file does not appear to be a valid Emscripten JavaScript output file"
568+
exit 1
569+
fi
570+
echo "$file validated successfully"
571+
fi
572+
done
573+
echo "All test files validated successfully"
574+
575+
- name: Setup Node.js
576+
uses: actions/setup-node@v4
577+
with:
578+
node-version: '22.14.0'
579+
580+
- name: Run tests with Node.js
581+
run: |
582+
cd test/build
583+
export BAKE_TEST_INPLACE=1
584+
export BAKE_VERBOSITY=DEBUG
585+
echo "Running tests..."
586+
failed_tests=()
587+
588+
for test in test/*.js; do
589+
if [ -f "$test" ]; then
590+
echo "=== Running $test ==="
591+
if ! stdbuf -oL -eL node --expose-gc "$test" 2>&1 | grep -v "unsupported syscall" | sed '/^[[:space:]]*$/d' | tee "${test%.js}.log"; then
592+
failed_tests+=("$test")
593+
echo "❌ $test failed"
594+
else
595+
echo "✅ $test passed"
596+
fi
597+
echo "=== End test output ==="
598+
fi
599+
done
600+
601+
echo "=== Test Summary ==="
602+
total_tests=$(find test -name "*.js" -type f | wc -l)
603+
passed_tests=$((total_tests - ${#failed_tests[@]}))
604+
echo "Total tests: $total_tests"
605+
echo "Passed tests: $passed_tests"
606+
echo "Failed tests: ${#failed_tests[@]}"
607+
608+
if [ ${#failed_tests[@]} -ne 0 ]; then
609+
echo "Failed tests:"
610+
printf '%s\n' "${failed_tests[@]}"
611+
exit 1
612+
fi
613+
457614
test-amalgamated:
458615
needs: build-linux
459616
runs-on: ubuntu-latest
@@ -951,4 +1108,4 @@ jobs:
9511108
9521109
- name: run tests
9531110
run: |
954-
ctest -C Debug --verbose
1111+
ctest -C Debug --verbose

cmake/target_default_compile_warnings.cmake

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ function(target_default_compile_warnings_c THIS)
22

33
if (FLECS_STRICT)
44

5-
if (CMAKE_C_COMPILER_ID STREQUAL "Clang"
5+
if (EMSCRIPTEN)
6+
# Less strict warnings for emscripten builds
7+
target_compile_options(${THIS} PRIVATE
8+
-Wall -Wextra
9+
-Wno-shadow
10+
-Wno-unused-parameter
11+
-Wno-missing-field-initializers
12+
-Wno-strict-prototypes)
13+
14+
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang"
615
OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
716

817
target_compile_options(${THIS} PRIVATE

0 commit comments

Comments
 (0)