Skip to content

Commit dee31bd

Browse files
authored
Merge branch 'main' into use-msvc-on-windows
2 parents ea65e63 + 9ee7080 commit dee31bd

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
@@ -223,3 +223,39 @@ jobs:
223223
run: gh release create --draft --prerelease --generate-notes ${{ github.ref_name }} ./dist/*
224224
env:
225225
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
226+
227+
# Test the final artifacts as-is without passing `--sysroot` or
228+
# `-resource-dir` or any extra flags. This exercises running the compiler
229+
# as-is from the distribution tarballs and ensuring that it can build and pass
230+
# all tests.
231+
test-standalone:
232+
name: Test standalone toolchain
233+
needs: build
234+
runs-on: ubuntu-latest
235+
steps:
236+
- uses: actions/checkout@v4
237+
with:
238+
fetch-depth: 0
239+
- run: git fetch --tags --force
240+
name: Force-fetch tags to work around actions/checkout#290
241+
- run: git submodule update --init --depth 32 --jobs 3
242+
- name: Setup `wasmtime` for tests
243+
uses: bytecodealliance/actions/wasmtime/setup@v1
244+
with:
245+
version: "18.0.2"
246+
- name: Install ninja
247+
run: sudo apt-get install -y ninja-build
248+
if: runner.os == 'Linux'
249+
- uses: actions/download-artifact@v4
250+
with:
251+
name: dist-x86_64-linux
252+
path: dist-x86_64-linux
253+
- run: ./ci/merge-artifacts.sh
254+
- run: tar xf dist/wasi-sdk-*.tar.gz
255+
- run: |
256+
cmake -G Ninja -B build -S . \
257+
-DWASI_SDK_INCLUDE_TESTS=ON \
258+
-DWASI_SDK_TEST_HOST_TOOLCHAIN=ON \
259+
-DCMAKE_TOOLCHAIN_FILE=$(ls ./wasi-sdk-*/share/cmake/wasi-sdk.cmake)
260+
- run: ninja -C build build-tests
261+
- 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)