diff --git a/Makefile b/Makefile index 03858eaa6..c17094da3 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,8 @@ override LLVM_CMAKE_FLAGS += -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 endif +TARGETS = wasm32-wasi wasm32-wasip1 wasm32-wasip2 wasm32-wasip1-threads wasm32-wasi-threads + # Only the major version is needed for Clang, see https://reviews.llvm.org/D125860. CLANG_VERSION=$(shell $(BASH) ./llvm_version_major.sh $(LLVM_PROJ_DIR)) VERSION:=$(shell $(BASH) ./version.sh) @@ -51,16 +53,29 @@ default: build @echo "Use -fdebug-prefix-map=$(ROOT_DIR)=wasisdk://v$(VERSION)" check: - CC="clang --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ - CXX="clang++ --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot -fno-exceptions" \ - PATH="$(PATH_PREFIX)/bin:$$PATH" tests/run.sh "$(BUILD_PREFIX)" "$(RUNTIME)" "$(ADAPTER)" "$(WASM_TOOLS)" + TARGETS="$(TARGETS)" tests/run.sh "$(BUILD_PREFIX)" "$(RUNTIME)" "$(ADAPTER)" "$(WASM_TOOLS)" clean: rm -rf build $(DESTDIR) +# Default symlinks that clang creates to the `clang` executable +CLANG_LINKS_TO_CREATE = clang++ clang-cl clang-cpp + +# Add target-prefixed versions of `clang` and `clang++` so they can be used +# without `--target` as it's auto-inferred from the executable name by clang. +CLANG_LINKS_TO_CREATE += $(foreach target,$(TARGETS),$(target)-clang) +CLANG_LINKS_TO_CREATE += $(foreach target,$(TARGETS),$(target)-clang++) + +# Small helper to create a `join-with` function that can join elements of a +# list with a defined separator. +noop = +space = $(noop) $(noop) +join-with = $(subst $(space),$1,$(strip $2)) + build/llvm.BUILT: mkdir -p build/llvm cd build/llvm && cmake -G Ninja \ + -DCLANG_LINKS_TO_CREATE="$(call join-with,;,$(CLANG_LINKS_TO_CREATE))" \ -DCMAKE_BUILD_TYPE=MinSizeRel \ -DLLVM_ENABLE_TERMINFO=OFF \ -DLLVM_ENABLE_ZLIB=OFF \ diff --git a/tests/run.sh b/tests/run.sh index 1d41ff1b5..080eeaee5 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -6,13 +6,7 @@ set -ueo pipefail # is a WASI-capable runtime to run the tests in full compile and # execute mode. # -# By default this script will look for `clang` and `clang++` in $PATH and -# assume that they are correctly configured with the sysroot in the default -# location. Alternatively, exporting $CC and $CXX allow more flexibility. e.g: -# -# export CXX="/bin/clang++ --sysroot /share/wasi-sysroot" -# export CC="/bin/clang --sysroot /share/wasi-sysroot" -# +# The compiler used during testing is loaded from ``. if [ $# -lt 1 ]; then echo "Path to WASI SDK is required" exit 1 @@ -37,44 +31,48 @@ else fi testdir=$(dirname $0) -CC=${CC:=clang} -CXX=${CXX:=clang++} -echo $CC -echo $CXX echo "SDK: $wasi_sdk" -for target in wasm32-wasi wasm32-wasip1 wasm32-wasi-threads wasm32-wasip1-threads wasm32-wasip2; do +# NB: all tests are run with the default `clang` and `clang++` executables +# but they're also executed with the target-prefixed `clang` executables to +# ensure that those work as well when the `--target` option is omitted. + +for target in $TARGETS; do echo "===== Testing target $target =====" cd $testdir/compile-only for options in -O0 -O2 "-O2 -flto"; do echo "===== Testing compile-only with $options =====" for file in *.c; do echo "Testing compile-only $file..." - ../testcase.sh "$target" "" "" "" "$CC" "$options" "$file" + ../testcase.sh "$target" "" "" "" "$wasi_sdk/bin/clang" "$options --target=$target" "$file" + ../testcase.sh "$target" "" "" "" "$wasi_sdk/bin/$target-clang" "$options" "$file" done for file in *.cc; do echo "Testing compile-only $file..." - ../testcase.sh "$target" "" "" "" "$CXX" "$options" "$file" + ../testcase.sh "$target" "" "" "" "$wasi_sdk/bin/clang++" "$options --target=$target -fno-exceptions" "$file" + ../testcase.sh "$target" "" "" "" "$wasi_sdk/bin/$target-clang++" "$options -fno-exceptions" "$file" done done cd - >/dev/null - + cd $testdir/general for options in -O0 -O2 "-O2 -flto"; do echo "===== Testing with $options =====" for file in *.c; do echo "Testing $file..." - ../testcase.sh "$target" "$runwasi" "$adapter" "$wasm_tools" "$CC" "$options" "$file" + ../testcase.sh "$target" "$runwasi" "$adapter" "$wasm_tools" "$wasi_sdk/bin/clang" "$options --target=$target" "$file" + ../testcase.sh "$target" "$runwasi" "$adapter" "$wasm_tools" "$wasi_sdk/bin/$target-clang" "$options" "$file" done for file in *.cc; do echo "Testing $file..." - ../testcase.sh "$target" "$runwasi" "$adapter" "$wasm_tools" "$CXX" "$options" "$file" + ../testcase.sh "$target" "$runwasi" "$adapter" "$wasm_tools" "$wasi_sdk/bin/clang++" "$options --target=$target -fno-exceptions" "$file" + ../testcase.sh "$target" "$runwasi" "$adapter" "$wasm_tools" "$wasi_sdk/bin/$target-clang++" "$options -fno-exceptions" "$file" done done cd - >/dev/null done - + # Test cmake build system for wasi-sdk test_cmake() { local option diff --git a/tests/testcase.sh b/tests/testcase.sh index 285424ff0..b646e2d4a 100755 --- a/tests/testcase.sh +++ b/tests/testcase.sh @@ -37,7 +37,7 @@ fi echo "Testing $input..." # Compile the testcase. -$compiler --target=$target $pthread_options $options $file_options "$input" -o "$wasm" +$compiler $pthread_options $options $file_options "$input" -o "$wasm" # If we don't have a runwasi command, we're just doing compile-only testing. if [ "$runwasi" == "" ]; then @@ -87,7 +87,7 @@ if [ -e "$input.stdout.expected" ]; then stdout_expected="$input.$target.stdout.expected" else stdout_expected="$input.stdout.expected" - fi + fi # Apply output filters. if [ -e "$input.stdout.expected.filter" ]; then @@ -105,7 +105,7 @@ if [ -e "$input.stderr.expected" ]; then stderr_expected="$input.$target.stderr.expected" else stderr_expected="$input.stderr.expected" - fi + fi # Apply output filters. if [ -e "$input.stderr.expected.filter" ]; then