From a13a90ab2b6672e013ef5eab0f0daed680aa0e19 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Jul 2024 14:32:16 -0700 Subject: [PATCH 1/6] 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. --- .github/workflows/main.yml | 27 +++++++++++++++++++++++++++ README.md | 2 ++ tests/CMakeLists.txt | 19 +++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a23beb1f8..b7e31e73e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -211,3 +211,30 @@ jobs: run: gh release create --draft --prerelease --generate-notes ${{ github.ref_name }} ./dist/* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Test the final artifacts as-is without passing `--sysroot` or + # `-resource-dir` or any extra flags. This exercises running the compiler + # as-is from the distribution tarballs and ensuring that it can build and pass + # all tests. + test-standalone: + name: Test standalone toolchain + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup `wasmtime` for tests + uses: bytecodealliance/actions/wasmtime/setup@v1 + with: + version: "18.0.2" + - uses: actions/download-artifact@v4 + with: + name: dist-x86_64-linux + - run: ./ci/merge-artifacts.sh + - run: tar xf dist/wasi-sdk-*.tar.gz + - run: | + cmake -G Ninja -B build -S . \ + -DWASI_SDK_INCLUDE_TESTS=ON \ + -DWASI_SDK_TEST_HOST_TOOLCHAIN=ON \ + -DCMAKE_TOOLCHAIN_FILE=$(ls ./wasi-sdk-*/share/cmake/wasi-sdk.cmake) + - run: ninja -C build build-tests + - run: ctest --output-on-failure --parallel 10 --test-dir build/tests diff --git a/README.md b/README.md index 9632be985..a594f40f7 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ in compiling WebAssembly code. Supported CMake flags are: * `-DWASI_SDK_DEBUG_PREFIX_MAKE=OFF` - disable `-fdebug-prefix-map` when building C/C++ code to use full host paths instead. * `-DWASI_SDK_INCLUDE_TESTS=ON` - used for building tests. +* `-DWASI_SDK_TEST_HOST_TOOLCHAIN=ON` - test the host toolchain's wasi-libc and + sysroot libraries, don't build or use fresh libraries for tests. * `-DWASI_SDK_TARGETS=..` - a list of targets to build, by default all WASI targets are compiled. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fb6a03bc7..c5e7edd39 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,8 +5,12 @@ include(CTest) enable_testing() set(CMAKE_EXECUTABLE_SUFFIX ".wasm") -add_compile_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir}) -add_link_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir}) +option(WASI_SDK_TEST_HOST_TOOLCHAIN "Test against the host toolchain, not a fresh sysroot" OFF) + +if(NOT WASI_SDK_TEST_HOST_TOOLCHAIN) + add_compile_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir}) + add_link_options(--sysroot=${wasi_sysroot} -resource-dir ${wasi_resource_dir}) +endif() # Sanity check setup if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL WASI) @@ -22,6 +26,8 @@ set(WASI_SDK_RUNWASI "wasmtime" CACHE STRING "Runner for tests") # Test everything at O0, O2, and O2+LTO set(opt_flags -O0 -O2 "-O2 -flto") +add_custom_target(build-tests) + # Executes a single `test` specified. # # This will compile `test` for all the various targets and with various @@ -35,6 +41,7 @@ function(add_testcase runwasi test) # Add a new test executable based on `test` add_executable(${target_name} ${test}) + add_dependencies(build-tests ${target_name}) # Configure all the compile options necessary. For example `--target` here # 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) # Apply language-specific options and dependencies. if(test MATCHES "cc$") target_compile_options(${target_name} PRIVATE -fno-exceptions) - add_dependencies(${target_name} libcxx-${target}) + if(NOT WASI_SDK_TEST_HOST_TOOLCHAIN) + add_dependencies(${target_name} libcxx-${target}) + endif() else() - add_dependencies(${target_name} wasi-libc-${target}) + if(NOT WASI_SDK_TEST_HOST_TOOLCHAIN) + add_dependencies(${target_name} wasi-libc-${target}) + endif() endif() # Apply target-specific options. From babe59ea1584091e4c38f538c218a892ab252b27 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Jul 2024 15:08:48 -0700 Subject: [PATCH 2/6] Fix version.py script running --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b7e31e73e..8eb9c8e47 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -222,6 +222,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: git fetch --tags --force + name: Force-fetch tags to work around actions/checkout#290 - name: Setup `wasmtime` for tests uses: bytecodealliance/actions/wasmtime/setup@v1 with: From 6a5dae6b24390a15df321e67648ec502662dd872 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Jul 2024 16:52:03 -0700 Subject: [PATCH 3/6] Fix artifact download --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8eb9c8e47..1cd65aed9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -233,6 +233,7 @@ jobs: - uses: actions/download-artifact@v4 with: name: dist-x86_64-linux + path: dist-x86_64-linux - run: ./ci/merge-artifacts.sh - run: tar xf dist/wasi-sdk-*.tar.gz - run: | From f64334651276a75d182c8117a01261fec4fe0410 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Jul 2024 17:37:20 -0700 Subject: [PATCH 4/6] Add ninja --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1cd65aed9..99ff6965b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -230,6 +230,9 @@ jobs: uses: bytecodealliance/actions/wasmtime/setup@v1 with: version: "18.0.2" + - name: Install ninja + run: sudo apt-get install -y ninja-build + if: runner.os == 'Linux' - uses: actions/download-artifact@v4 with: name: dist-x86_64-linux From f1d95ab593b41b57eef90c40bd1535ef7f06ef2c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Jul 2024 07:25:40 -0700 Subject: [PATCH 5/6] Update submodules in new test job --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 99ff6965b..bdd237262 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -226,6 +226,7 @@ jobs: fetch-depth: 0 - run: git fetch --tags --force name: Force-fetch tags to work around actions/checkout#290 + - run: git submodule update --init --depth 32 --jobs 3 - name: Setup `wasmtime` for tests uses: bytecodealliance/actions/wasmtime/setup@v1 with: From 7e8d130c02cfdd7b0da551c22e46e18d2af751d9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Jul 2024 08:11:12 -0700 Subject: [PATCH 6/6] 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. --- cmake/wasi-sdk-sysroot.cmake | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmake/wasi-sdk-sysroot.cmake b/cmake/wasi-sdk-sysroot.cmake index 1ba204a47..eea357a38 100644 --- a/cmake/wasi-sdk-sysroot.cmake +++ b/cmake/wasi-sdk-sysroot.cmake @@ -14,11 +14,6 @@ set(wasi_tmp_install ${CMAKE_CURRENT_BINARY_DIR}/install) set(wasi_sysroot ${wasi_tmp_install}/share/wasi-sysroot) set(wasi_resource_dir ${wasi_tmp_install}/lib/clang/${clang_version}) -# Force usage of the custom-built resource-dir and sysroot for the rest of the -# wasi compiles. -add_compile_options(-resource-dir ${wasi_resource_dir}) -add_compile_options(--sysroot ${wasi_sysroot}) - if(WASI_SDK_DEBUG_PREFIX_MAP) add_compile_options( -fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=wasisdk://v${wasi_sdk_version}) @@ -167,9 +162,17 @@ function(define_libcxx target) get_property(dir_compile_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS) get_property(dir_link_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_OPTIONS) - set(extra_cflags_list ${CMAKE_C_FLAGS} ${target_flags} --target=${target} ${dir_compile_opts} ${dir_link_opts}) + set(extra_flags + ${target_flags} + --target=${target} + ${dir_compile_opts} + ${dir_link_opts} + --sysroot ${wasi_sysroot} + -resource-dir ${wasi_resource_dir}) + + set(extra_cflags_list ${CMAKE_C_FLAGS} ${extra_flags}) list(JOIN extra_cflags_list " " extra_cflags) - set(extra_cxxflags_list ${CMAKE_CXX_FLAGS} ${target_flags} --target=${target} ${dir_compile_opts} ${dir_link_opts}) + set(extra_cxxflags_list ${CMAKE_CXX_FLAGS} ${extra_flags}) list(JOIN extra_cxxflags_list " " extra_cxxflags) ExternalProject_Add(libcxx-${target}-build