1

run bazel test

This simplifies the tests somewhat.
This commit is contained in:
Motiejus Jakštys 2022-02-03 22:38:43 +02:00
parent 78a77ebbe5
commit 5871171549
2 changed files with 26 additions and 58 deletions

View File

@ -1,8 +1,8 @@
image: debian/stable image: debian/stable
packages: packages:
- direnv - direnv
- file
- shellcheck - shellcheck
- qemu-user
sources: sources:
- https://git.sr.ht/~motiejus/bazel-zig-cc - https://git.sr.ht/~motiejus/bazel-zig-cc
environment: environment:
@ -19,12 +19,9 @@ tasks:
shellcheck -x $(awk '/#!\/bin\/(ba)?sh/&&FNR==1{print FILENAME}' $(git ls-files)) shellcheck -x $(awk '/#!\/bin\/(ba)?sh/&&FNR==1{print FILENAME}' $(git ls-files))
bazel run //:buildifier bazel run //:buildifier
git diff --exit-code git diff --exit-code
- test_native: |
cd bazel-zig-cc; . .envrc
bazel test //...
- test_list_toolchains: | - test_list_toolchains: |
cd bazel-zig-cc; . .envrc; echo "Available toolchains:" cd bazel-zig-cc; . .envrc; echo "Available toolchains:"
bazel query @zig_sdk//... | sed -En '/.*_toolchain$/ s/.*:(.*)_toolchain$/\1/p' bazel query @zig_sdk//... | sed -En '/.*_toolchain$/ s/.*:(.*)_toolchain$/\1/p'
- test_hello_on_toolchains: | - test_hello_on_toolchains: |
cd bazel-zig-cc cd bazel-zig-cc
./ci/test ./ci/test --color=yes --curses=yes

77
ci/test
View File

@ -1,65 +1,36 @@
#!/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
. .envrc . .envrc
_build_and_file() {
file "$(bazel run --color=yes --curses=yes --run_under=echo "$@")" | \
tee /dev/stderr
}
_run() { _run() {
>&2 echo
>&2 echo " $*" >&2 echo " $*"
>&2 echo
"$@" "$@"
} }
_build() { while read -r action platform toolchain run_under; do
local name=$1 args=("$@")
local glob=$2 if [[ $run_under != : ]]; then
shift; shift; args+=(--run_under="$run_under")
>&2 echo "================================================================"
>&2 echo "Building everything under //test/... for $name"
>&2 echo
_run bazel build --color=yes --curses=yes "$@" //test/...
>&2 echo
>&2 echo "Testing $name and looking for '$glob':"
>&2 echo
if _run _build_and_file "$@" //test/go:go | grep -q "$glob"; then
>&2 echo "OK $name"
return 0
else
>&2 echo "FAIL $name: glob does not match"
return 1
fi fi
} args+=(--platforms "@zig_sdk//:${platform}_platform")
args+=(--extra_toolchains "@zig_sdk//:${toolchain}_toolchain")
args+=(//test/...)
_run bazel "$action" "${args[@]}"
done <<EOF
test linux_amd64 linux_amd64_gnu.2.19 :
test linux_amd64 linux_amd64_musl :
build linux_arm64 linux_arm64_musl :
build linux_arm64 linux_arm64_gnu.2.28 :
build darwin_amd64 darwin_amd64 :
EOF
_build "Host" \ # TODO:
"ELF 64-bit.* x86-64.* dynamically linked" # works locally, fails on srht:
# test linux_arm64 linux_arm64_musl qemu-aarch64
_build "darwin_amd64" \ #
"Mach-O 64-bit x86_64 executable" \ # fails locally, qemu-aarch64 can't find the files in /usr
--platforms @zig_sdk//:darwin_amd64_platform # test linux_arm64 linux_arm64_gnu.2.28 qemu-aarch64 -L /usr/aarch64-linux-gnu
# hello world on darwin/arm64 requires OSX SDK via `zig cc --sysroot=<...>`.
# see https://github.com/ziglang/zig/issues/10299#issuecomment-989595215
#_build "darwin_arm64" \
# "Mach-O 64-bit arm64 executable" \
# --platforms @zig_sdk//:darwin_arm64_platform
_build "linux_amd64_gnu" \
"ELF 64-bit.* x86-64.* dynamically linked" \
--platforms @zig_sdk//:linux_amd64_platform
_build "linux_amd64_musl" \
"ELF 64-bit.* x86-64.* statically linked" \
--platforms @zig_sdk//:linux_amd64_platform \
--extra_toolchains @zig_sdk//:linux_amd64_musl_toolchain
_build "linux_arm64_gnu" \
"ELF 64-bit.* ARM aarch64.* dynamically linked" \
--platforms @zig_sdk//:linux_arm64_platform
_build "linux_arm64_musl" \
"ELF 64-bit.* ARM aarch64.* statically linked" \
--platforms @zig_sdk//:linux_arm64_platform \
--extra_toolchains @zig_sdk//:linux_arm64_musl_toolchain