Skip to content

Commit 9ee7080

Browse files
authored
Add a CI check for testing toolchains as-distributed (#449)
* Add a CI check for testing toolchains as-distributed One aspect of testing lost in the CMake-based migration is the ability to test the toolchains as distributed in release artifacts. Tests use `--sysroot` and `-resource-dir` (soon) to customize how the host compiler runs but this means that it would be possible to regress the default sysroot theoretically. To rectify this situation this commit adds a new CI test which uses the release artifacts of previous steps to build a `wasi-sdk-*.tar.gz` tarball which is then extracted and tested as-is. A new flag was added to the cmake configuration to avoid depending on fresh sysroot libraries for tests and instead test the host toolchain. * Fix version.py script running * Fix artifact download * Add ninja * Update submodules in new test job * Only add extra options for libcxx build Otherwise the test directory seems like it inherits these options which isn't desired when testing the host toolchain.
1 parent 08be2d4 commit 9ee7080

File tree

4 files changed

+63
-11
lines changed

4 files changed

+63
-11
lines changed

.github/workflows/main.yml

+36
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,39 @@ jobs:
211211
run: gh release create --draft --prerelease --generate-notes ${{ github.ref_name }} ./dist/*
212212
env:
213213
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
214+
215+
# Test the final artifacts as-is without passing `--sysroot` or
216+
# `-resource-dir` or any extra flags. This exercises running the compiler
217+
# as-is from the distribution tarballs and ensuring that it can build and pass
218+
# all tests.
219+
test-standalone:
220+
name: Test standalone toolchain
221+
needs: build
222+
runs-on: ubuntu-latest
223+
steps:
224+
- uses: actions/checkout@v4
225+
with:
226+
fetch-depth: 0
227+
- run: git fetch --tags --force
228+
name: Force-fetch tags to work around actions/checkout#290
229+
- run: git submodule update --init --depth 32 --jobs 3
230+
- name: Setup `wasmtime` for tests
231+
uses: bytecodealliance/actions/wasmtime/setup@v1
232+
with:
233+
version: "18.0.2"
234+
- name: Install ninja
235+
run: sudo apt-get install -y ninja-build
236+
if: runner.os == 'Linux'
237+
- uses: actions/download-artifact@v4
238+
with:
239+
name: dist-x86_64-linux
240+
path: dist-x86_64-linux
241+
- run: ./ci/merge-artifacts.sh
242+
- run: tar xf dist/wasi-sdk-*.tar.gz
243+
- run: |
244+
cmake -G Ninja -B build -S . \
245+
-DWASI_SDK_INCLUDE_TESTS=ON \
246+
-DWASI_SDK_TEST_HOST_TOOLCHAIN=ON \
247+
-DCMAKE_TOOLCHAIN_FILE=$(ls ./wasi-sdk-*/share/cmake/wasi-sdk.cmake)
248+
- run: ninja -C build build-tests
249+
- run: ctest --output-on-failure --parallel 10 --test-dir build/tests

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ in compiling WebAssembly code. Supported CMake flags are:
8585
* `-DWASI_SDK_DEBUG_PREFIX_MAKE=OFF` - disable `-fdebug-prefix-map` when
8686
building C/C++ code to use full host paths instead.
8787
* `-DWASI_SDK_INCLUDE_TESTS=ON` - used for building tests.
88+
* `-DWASI_SDK_TEST_HOST_TOOLCHAIN=ON` - test the host toolchain's wasi-libc and
89+
sysroot libraries, don't build or use fresh libraries for tests.
8890
* `-DWASI_SDK_TARGETS=..` - a list of targets to build, by default all WASI
8991
targets are compiled.
9092

cmake/wasi-sdk-sysroot.cmake

+10-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ set(wasi_tmp_install ${CMAKE_CURRENT_BINARY_DIR}/install)
1414
set(wasi_sysroot ${wasi_tmp_install}/share/wasi-sysroot)
1515
set(wasi_resource_dir ${wasi_tmp_install}/lib/clang/${clang_version})
1616

17-
# Force usage of the custom-built resource-dir and sysroot for the rest of the
18-
# wasi compiles.
19-
add_compile_options(-resource-dir ${wasi_resource_dir})
20-
add_compile_options(--sysroot ${wasi_sysroot})
21-
2217
if(WASI_SDK_DEBUG_PREFIX_MAP)
2318
add_compile_options(
2419
-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=wasisdk://v${wasi_sdk_version})
@@ -167,9 +162,17 @@ function(define_libcxx target)
167162

168163
get_property(dir_compile_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
169164
get_property(dir_link_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_OPTIONS)
170-
set(extra_cflags_list ${CMAKE_C_FLAGS} ${target_flags} --target=${target} ${dir_compile_opts} ${dir_link_opts})
165+
set(extra_flags
166+
${target_flags}
167+
--target=${target}
168+
${dir_compile_opts}
169+
${dir_link_opts}
170+
--sysroot ${wasi_sysroot}
171+
-resource-dir ${wasi_resource_dir})
172+
173+
set(extra_cflags_list ${CMAKE_C_FLAGS} ${extra_flags})
171174
list(JOIN extra_cflags_list " " extra_cflags)
172-
set(extra_cxxflags_list ${CMAKE_CXX_FLAGS} ${target_flags} --target=${target} ${dir_compile_opts} ${dir_link_opts})
175+
set(extra_cxxflags_list ${CMAKE_CXX_FLAGS} ${extra_flags})
173176
list(JOIN extra_cxxflags_list " " extra_cxxflags)
174177

175178
ExternalProject_Add(libcxx-${target}-build

tests/CMakeLists.txt

+15-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ include(CTest)
55
enable_testing()
66
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
77

8-
add_compile_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir})
9-
add_link_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir})
8+
option(WASI_SDK_TEST_HOST_TOOLCHAIN "Test against the host toolchain, not a fresh sysroot" OFF)
9+
10+
if(NOT WASI_SDK_TEST_HOST_TOOLCHAIN)
11+
add_compile_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir})
12+
add_link_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir})
13+
endif()
1014

1115
# Sanity check setup
1216
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL WASI)
@@ -22,6 +26,8 @@ set(WASI_SDK_RUNWASI "wasmtime" CACHE STRING "Runner for tests")
2226
# Test everything at O0, O2, and O2+LTO
2327
set(opt_flags -O0 -O2 "-O2 -flto")
2428

29+
add_custom_target(build-tests)
30+
2531
# Executes a single `test` specified.
2632
#
2733
# This will compile `test` for all the various targets and with various
@@ -35,6 +41,7 @@ function(add_testcase runwasi test)
3541

3642
# Add a new test executable based on `test`
3743
add_executable(${target_name} ${test})
44+
add_dependencies(build-tests ${target_name})
3845

3946
# Configure all the compile options necessary. For example `--target` here
4047
# if the target doesn't look like it's already in the name of the compiler
@@ -60,9 +67,13 @@ function(add_testcase runwasi test)
6067
# Apply language-specific options and dependencies.
6168
if(test MATCHES "cc$")
6269
target_compile_options(${target_name} PRIVATE -fno-exceptions)
63-
add_dependencies(${target_name} libcxx-${target})
70+
if(NOT WASI_SDK_TEST_HOST_TOOLCHAIN)
71+
add_dependencies(${target_name} libcxx-${target})
72+
endif()
6473
else()
65-
add_dependencies(${target_name} wasi-libc-${target})
74+
if(NOT WASI_SDK_TEST_HOST_TOOLCHAIN)
75+
add_dependencies(${target_name} wasi-libc-${target})
76+
endif()
6677
endif()
6778

6879
# Apply target-specific options.

0 commit comments

Comments
 (0)