Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target-prefixed executables to the installation bin directory #388

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shame that we have to resort for this kind of Makefile magic, but I am not well versed enough to suggest anything better :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed :(

I went through a number of iterations of "copy some bits and pieces from stack overflow" until I found this which ended up working well enough.


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 \
Expand Down
34 changes: 16 additions & 18 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ set -ueo pipefail
# <runwasi> 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="<wasi-sdk>/bin/clang++ --sysroot <wasi-sdk>/share/wasi-sysroot"
# export CC="<wasi-sdk>/bin/clang --sysroot <wasi-sdk>/share/wasi-sysroot"
#
# The compiler used during testing is loaded from `<path to wasi-sdk>`.
if [ $# -lt 1 ]; then
echo "Path to WASI SDK is required"
exit 1
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/testcase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading