Skip to content

Commit fde5b75

Browse files
authored
Speed up testing the C API in CI (#11765)
* Speed up testing the C API in CI * Use `ninja` on all platforms to avoid the overhead of `make` or whatever is used by default on Windows. * Using `ninja` additionally enables building C/C++ objects in parallel by default. * Enable parallelism when running tests to avoid running just a single test at a time. * Move building of Rust examples out of `ctest` and into the "main build". This won't actually speed things up but avoids misattributing the first Rust test with minutes of runtime (as it's just building code). * Use dynamic linking to speed up the linking phase of examples. * Keep a configuration though that tests static linking. * Also add a `prtest:capi` directive to enable C API tests in a PR. prtest:capi * Tweak CI matrix * Use MSVC, not MinGW. Also run examples * Do I know what yaml is? no. * Still don't know yaml * I know neither GHA nor yml * Try to fix Windows * Another windows fix * Skip rpath on macos * Try a windows fix
1 parent da63361 commit fde5b75

File tree

3 files changed

+74
-35
lines changed

3 files changed

+74
-35
lines changed

.github/workflows/main.yml

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ jobs:
200200
echo platform-checks=true >> $GITHUB_OUTPUT
201201
elif grep -q 'prtest:miri' commits.log; then
202202
echo test-miri=true >> $GITHUB_OUTPUT
203+
elif grep -q 'prtest:capi' commits.log; then
204+
echo test-capi=true >> $GITHUB_OUTPUT
203205
fi
204206
if grep -q crates.c-api names.log; then
205207
echo test-capi=true >> $GITHUB_OUTPUT
@@ -622,31 +624,56 @@ jobs:
622624
# Perform all tests of the c-api
623625
test_capi:
624626
needs: determine
625-
name: Test C-API ${{ matrix.os }}
627+
name: Test C-API ${{ matrix.name }}
626628
runs-on: ${{ matrix.os }}
627629
if: needs.determine.outputs.test-capi
628630

629631
strategy:
630632
fail-fast: ${{ github.event_name != 'pull_request' }}
631633
matrix:
632-
os: [ubuntu-24.04, macos-15, windows-2025]
633-
634+
include:
635+
# This configuration will build C/C++ tests, examples, and Rust tests.
636+
# Everything is linked against the C shared library to speed up
637+
# linking, and this is intended to be the "main set of tests".
638+
#
639+
# Run this on windows/mac/linux
640+
- os: ubuntu-24.04
641+
flags: -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=ON -DBUILD_RUST_EXAMPLES=ON
642+
name: Linux
643+
- os: macos-15
644+
flags: -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=ON -DBUILD_RUST_EXAMPLES=ON
645+
name: macOS
646+
- os: windows-2025
647+
# Note that dynamic linking is disabled here because I don't want to
648+
# have to deal with figuring out how to get `wasmtime.dll` onto
649+
# `PATH` for various tests.
650+
flags: -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=ON -DBUILD_RUST_EXAMPLES=ON
651+
name: Windows
652+
653+
# This tests using static linking for examples but skips building the
654+
# Rust examples as well as C/C++ tests. Intended to be a faster build
655+
# which mostly just tests static linking.
656+
- os: ubuntu-24.04
657+
flags: -DBUILD_SHARED_LIBS=OFF -DBUILD_RUST_EXAMPLES=OFF
658+
name: Linux (static linking)
634659
steps:
635660
- uses: actions/checkout@v4
636661
with:
637662
submodules: true
638663
- uses: ./.github/actions/install-rust
664+
- run: rustup target add wasm32-wasip2
639665

640-
# Build and test the C API with example C programs along with the example
641-
# Rust programs. Note that this only executes if the `determine` step told
642-
# us to test the capi which is off-by-default for PRs.
643-
- run: rustup target add wasm32-wasip2 # wasip2 target needed by example programs
644-
- run: cmake -Sexamples -Bexamples/build -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=ON
645-
- run: cmake --build examples/build --config Debug
646-
- run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target RUN_TESTS
666+
- uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756
667+
# An ode to MinGW: man you're a pain to work around sometimes
668+
- run: rm /usr/bin/link
647669
if: runner.os == 'Windows'
648-
- run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target test
649-
if: runner.os != 'Windows'
670+
671+
- run: cmake -G Ninja -Sexamples -DCMAKE_BUILD_TYPE=Debug -Bexamples/build ${{ matrix.flags }}
672+
- run: ninja -C examples/build
673+
- run: ninja -C examples/build test
674+
env:
675+
CTEST_OUTPUT_ON_FAILURE: 1
676+
CTEST_PARALLEL_LEVEL: 4
650677

651678
# Perform all tests (debug mode) for `wasmtime`.
652679
#

crates/c-api/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ add_dependencies(wasmtime wasmtime-crate)
8686

8787
if(BUILD_SHARED_LIBS)
8888
if(NOT WASMTIME_TARGET MATCHES "windows")
89+
if(NOT WASMTIME_TARGET MATCHES "darwin")
8990
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
91+
endif()
9092
endif()
9193
list(GET WASMTIME_SHARED_FILES 0 WASMTIME_SHARED_LIB_TO_LINK)
9294
target_link_libraries(wasmtime INTERFACE ${WASMTIME_SHARED_LIB_TO_LINK})

examples/CMakeLists.txt

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ function(CREATE_TARGET TARGET TARGET_PATH)
1414
target_compile_options(wasmtime-${TARGET} PRIVATE /W3)
1515
endif()
1616

17-
target_compile_definitions(wasmtime-${TARGET} PRIVATE WASMTIME_TEST_ONLY)
17+
# This is only used in fib-debug.c right now and it only works with static
18+
# linking beacuse the required symbols aren't exported in the shared library, so
19+
# only when shared libs are disabled is this turned on.
20+
if (NOT BUILD_SHARED_LIBS)
21+
target_compile_definitions(wasmtime-${TARGET} PRIVATE WASMTIME_TEST_ONLY)
22+
endif()
1823

1924
set_target_properties(wasmtime-${TARGET} PROPERTIES
2025
OUTPUT_NAME wasmtime-${TARGET}
@@ -24,6 +29,7 @@ function(CREATE_TARGET TARGET TARGET_PATH)
2429

2530
target_include_directories(wasmtime-${TARGET} PUBLIC wasmtime)
2631
target_link_libraries(wasmtime-${TARGET} PUBLIC wasmtime)
32+
2733
add_test(NAME ${TARGET}-c COMMAND wasmtime-${TARGET} WORKING_DIRECTORY ../..)
2834
endfunction()
2935

@@ -34,14 +40,15 @@ function(CREATE_RUST_TEST EXAMPLE)
3440
add_test(NAME ${EXAMPLE}-rust COMMAND cargo run --example ${EXAMPLE} WORKING_DIRECTORY ../..)
3541
endif()
3642
endfunction()
43+
3744
function(CREATE_RUST_WASM EXAMPLE TARGET)
3845
add_custom_target(${EXAMPLE}-wasm-${TARGET} ALL COMMAND cargo build -p example-${EXAMPLE}-wasm --target ${TARGET})
3946
endfunction()
4047

4148
# Enable testing
4249
enable_testing()
4350

44-
# Wasm files required by tests
51+
# Wasm files required by tests, but only built if tests are actually being run.
4552
create_rust_wasm(fib-debug wasm32-unknown-unknown)
4653
create_rust_wasm(tokio wasm32-wasip1)
4754
create_rust_wasm(wasi wasm32-wasip1)
@@ -80,24 +87,27 @@ create_target(wasip1 wasip1/main.c)
8087
create_target(wasip1-cpp wasip1/main.cc)
8188

8289
# Rust examples/tests
83-
create_rust_test(anyref)
84-
create_rust_test(epochs)
85-
create_rust_test(externref)
86-
create_rust_test(fib-debug)
87-
create_rust_test(fuel)
88-
create_rust_test(gcd)
89-
create_rust_test(hello)
90-
create_rust_test(interrupt)
91-
create_rust_test(linking)
92-
create_rust_test(memory)
93-
create_rust_test(multi)
94-
create_rust_test(multimemory)
95-
create_rust_test(serialize)
96-
create_rust_test(threads)
97-
create_rust_test(wasip1)
98-
create_rust_test(wasip1-async)
99-
create_rust_test(wasip2)
100-
create_rust_test(wasip2-async)
101-
create_rust_test(tokio wasi-common/tokio)
102-
create_rust_test(component)
103-
create_rust_test(resource-component)
90+
if (BUILD_RUST_EXAMPLES)
91+
add_custom_target(rust-examples ALL COMMAND cargo build --examples WORKING_DIRECTORY ../..)
92+
create_rust_test(anyref)
93+
create_rust_test(epochs)
94+
create_rust_test(externref)
95+
create_rust_test(fib-debug)
96+
create_rust_test(fuel)
97+
create_rust_test(gcd)
98+
create_rust_test(hello)
99+
create_rust_test(interrupt)
100+
create_rust_test(linking)
101+
create_rust_test(memory)
102+
create_rust_test(multi)
103+
create_rust_test(multimemory)
104+
create_rust_test(serialize)
105+
create_rust_test(threads)
106+
create_rust_test(wasip1)
107+
create_rust_test(wasip1-async)
108+
create_rust_test(wasip2)
109+
create_rust_test(wasip2-async)
110+
create_rust_test(tokio wasi-common/tokio)
111+
create_rust_test(component)
112+
create_rust_test(resource-component)
113+
endif()

0 commit comments

Comments
 (0)