Skip to content

Commit

Permalink
test: Do testing of clang-cl with the same script setup as for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
mstorsjo committed Jun 16, 2023
1 parent 450012b commit b61cceb
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 25 deletions.
26 changes: 1 addition & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,7 @@ jobs:
./install.sh $(pwd)/msvc
- name: Test using the installed tools
run: |
for arch in i686 x86_64 armv7 aarch64; do
clang-cl --target=$arch-windows-msvc test/hello.c -Fehello-$arch.exe -winsysroot $(pwd)/msvc -fuse-ld=lld
case $arch in
i*86) msvcarch=x86 ;;
x86_64) msvcarch=x64 ;;
arm*) msvcarch=arm ;;
aarch64) msvcarch=arm64 ;;
esac
(BIN=$(pwd)/msvc/bin/$msvcarch . ./msvcenv-native.sh
clang-cl --target=$TARGET_TRIPLE test/hello.c -c -Fohello-$arch.obj
lld-link hello-$arch.obj -out:hello-$arch.exe
)
done
ls -l *.exe
- name: Test building with CMake
run: |
for arch in x86 x64 arm arm64; do
mkdir test/build-$arch
cd test/build-$arch
(BIN=$(pwd)/../../msvc/bin/$arch . ../../msvcenv-native.sh
CC="clang-cl --target=$TARGET_TRIPLE" CXX="clang-cl --target=$TARGET_TRIPLE" RC="llvm-rc" cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_MT=/usr/bin/llvm-mt
ninja -v
)
cd ../..
done
test/test-clang-cl.sh $(pwd)/msvc
# Intentionally not storing any artifacts with the downloaded tools;
# the installed files aren't redistributable!

Expand Down
40 changes: 40 additions & 0 deletions test/test-clang-cl-cmds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
#
# Copyright (c) 2023 Martin Storsjo
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

. "${0%/*}/test.sh"

# ${BIN} set up by the caller
if [ -z "$BIN" ]; then
echo Must set the BIN env variable pointing to the MSVC bin directory
exit 1
fi

BASE_UNIX=$(. "${BIN}msvcenv.sh" && echo $BASE_UNIX)
TARGET_ARCH=$(. "${TESTS}../msvcenv-native.sh" && echo $TARGET_ARCH)

# Since Clang 13, it's possible to point out the installed MSVC/WinSDK with
# the /winsysroot parameter. LLD also provides the same parameter since
# version 15. (For versions 13 and 14, this parameter can still be used
# for linking, as long as linking is done via Clang.)
EXEC "" clang-cl --target=$TARGET_ARCH-windows-msvc "${TESTS}hello.c" -Fehello.exe -winsysroot "$BASE_UNIX" -fuse-ld=lld

# Set up the INCLUDE/LIB env variables for compilation without directly
# pointing at the installation.
. ${TESTS}../msvcenv-native.sh
EXEC "" clang-cl --target=$TARGET_TRIPLE "${TESTS}hello.c" -c -Fohello.obj
EXEC "" lld-link hello.obj -out:hello.exe

EXIT
31 changes: 31 additions & 0 deletions test/test-clang-cl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright (c) 2023 Martin Storsjo
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

. "${0%/*}/test.sh"

cd "$TESTS"

for arch in x86 x64 arm arm64; do
BIN="${1:-/opt/msvc}/bin/$arch/"
if [ ! -d "$BIN" ]; then
continue
fi

EXEC "" BIN=$BIN ./test-clang-cl-cmds.sh
EXEC "" BIN=$BIN ./test-cmake-clang-cl.sh
done

EXIT
45 changes: 45 additions & 0 deletions test/test-cmake-clang-cl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
#
# Copyright (c) 2023 Martin Storsjo
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

. "${0%/*}/test.sh"

# ${BIN} set up by the caller
if [ -z "$BIN" ]; then
echo Must set the BIN env variable pointing to the MSVC bin directory
exit 1
fi

. ${TESTS}/../msvcenv-native.sh

CMAKE_ARGS=(
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DCMAKE_SYSTEM_NAME=Windows
-DCMAKE_MT=$(which llvm-mt)
)

EXEC "" CC="clang-cl --target=$TARGET_TRIPLE" CXX="clang-cl --target=$TARGET_TRIPLE" RC="llvm-rc" cmake -S"$TESTS" -GNinja "${CMAKE_ARGS[@]}"
EXEC "" ninja -v

# Rerun ninja to make sure that dependencies aren't broken.
EXEC ninja-rerun ninja -d explain -v
DIFF ninja-rerun.err - <<EOF
EOF
DIFF ninja-rerun.out - <<EOF
ninja: no work to do.
EOF


EXIT

0 comments on commit b61cceb

Please sign in to comment.