- add rules to run tests for a specific platform - use downloaded buildifier - move lint to a script - rename ci tasks - stop running under qemu-aarch64-static as it doesn't do anythingmain
parent
557e75efda
commit
7a81e2a129
@ -1,27 +1,45 @@ |
||||
set -eu |
||||
|
||||
export PATH="$(git rev-parse --show-toplevel)/bin:$PATH" |
||||
_u=https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk- |
||||
BIN_DIR="$(git rev-parse --show-toplevel)/bin" |
||||
export PATH="$BIN_DIR:$PATH" |
||||
|
||||
#for os in linux darwin; do |
||||
# for arch in amd64 arm64; do |
||||
# hash=$(direnv fetchurl "${_u}$os-$arch") |
||||
# echo -e "$os-$arch\t$hash" |
||||
# done |
||||
#done |
||||
_u_bzl=https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk- |
||||
_u_bldf=https://github.com/bazelbuild/buildtools/releases/download/5.0.1/buildifier- |
||||
|
||||
if [[ "${PRINT_TOOL_HASHES:-no}" = "yes" ]]; then |
||||
for os in linux darwin; do |
||||
for arch in amd64 arm64; do |
||||
hash_bzl=$(direnv fetchurl "${_u_bzl}$os-$arch") |
||||
hash_bldf=$(direnv fetchurl "${_u_bldf}$os-$arch") |
||||
echo -e "bzl: $os-$arch\t$hash_bzl" |
||||
echo -e "bldf: $os-$arch\t$hash_bldf" |
||||
done |
||||
done |
||||
fi |
||||
|
||||
# to fetch the hashes, run: |
||||
# $ PRINT_TOOL_HASHES=yes bash .envrc |
||||
case "$(uname | tr A-Z a-z)-$(uname -m)" in |
||||
linux-x86_64) |
||||
bzl=$(direnv fetchurl "${_u}linux-amd64" sha256-TLU0xSzdR6YiPUWW1TDnyceFQ4qzsKSf80fpkcIQss0=);; |
||||
bzl=$(direnv fetchurl "${_u_bzl}linux-amd64" sha256-TLU0xSzdR6YiPUWW1TDnyceFQ4qzsKSf80fpkcIQss0=) |
||||
bldf=$(direnv fetchurl "${_u_bldf}linux-amd64" sha256-Ptc1jHxqHKIW3FZukFT9C5ehSCywt+YQkr6IfUJhXF0=) |
||||
;; |
||||
linux-aarch64) |
||||
bzl=$(direnv fetchurl "${_u}linux-arm64" sha256-wd5oYN1PjV4uwnAJe9RtaiEblxoLizhVl4S9BR6pUKE=);; |
||||
bzl=$(direnv fetchurl "${_u_bzl}linux-arm64" sha256-wd5oYN1PjV4uwnAJe9RtaiEblxoLizhVl4S9BR6pUKE=) |
||||
bldf=$(direnv fetchurl "${_u_bldf}linux-arm64" sha256-xlfGKPynK34ERvGlQiMXIqELpDIVl71vYkml2mBgtv8==) |
||||
;; |
||||
darwin-x86_64) |
||||
bzl=$(direnv fetchurl "${_u}darwin-amd64" sha256-5IW7+EUy0CpgsOsjxwJhC1QI3zoZkIek8rXgmVu/LVo=);; |
||||
bzl=$(direnv fetchurl "${_u_bzl}darwin-amd64" sha256-5IW7+EUy0CpgsOsjxwJhC1QI3zoZkIek8rXgmVu/LVo=) |
||||
bldf=$(direnv fetchurl "${_u_bldf}darwin-amd64" sha256-LLClRoNjPvbeTgSRBy4i5mrJxjiQUUMrdiAN7u6vk/s=) |
||||
;; |
||||
darwin-arm64) |
||||
bzl=$(direnv fetchurl "${_u}darwin-arm64" sha256-wi1IYBRm2dOwQ8zXQFHy9CMPm59FCfCXAXyXMDqojRM=);; |
||||
bzl=$(direnv fetchurl "${_u_bzl}darwin-arm64" sha256-wi1IYBRm2dOwQ8zXQFHy9CMPm59FCfCXAXyXMDqojRM=) |
||||
bldf=$(direnv fetchurl "${_u_bldf}darwin-arm64" sha256-TaIzFfDcyr+HjIIn/dvM81VFsjs8tiJb/PMQdonMQ2Q=) |
||||
;; |
||||
*) |
||||
>&2 echo "unsupported architecture tuple $(uname | tr A-Z a-z)-$(uname -m)" |
||||
exit 1;; |
||||
esac |
||||
|
||||
ln -sf "${bzl}" bin/bazel |
||||
ln -sf "${bzl}" "$BIN_DIR/bazel" |
||||
ln -sf "${bldf}" "$BIN_DIR/buildifier" |
||||
|
@ -0,0 +1,9 @@ |
||||
#!/bin/bash |
||||
set -euo pipefail |
||||
|
||||
REPO_ROOT=$(git rev-parse --show-toplevel) |
||||
cd "$REPO_ROOT" |
||||
|
||||
# shellcheck disable=SC2046 |
||||
shellcheck -x $(awk '/#!\/bin\/(ba)?sh/&&FNR==1{print FILENAME}' $(git ls-files)) |
||||
find . \( -name 'WORKSPACE' -o -name 'BUILD' -o -name '*.bzl' \) -exec buildifier {} + |
@ -1,34 +1,4 @@ |
||||
#!/bin/bash |
||||
set -euo pipefail |
||||
|
||||
cd "$(dirname "$0")/.." |
||||
. .envrc |
||||
|
||||
_run() { |
||||
>&2 echo |
||||
>&2 echo " $*" |
||||
>&2 echo |
||||
"$@" |
||||
} |
||||
|
||||
while read -r action platform toolchain config; do |
||||
args=("$@") |
||||
if [[ $config != : ]]; then |
||||
args+=(--config="$config") |
||||
fi |
||||
|
||||
args+=(\ |
||||
--platforms "@zig_sdk//platform:${platform}" \ |
||||
--extra_toolchains "@zig_sdk//toolchain:${toolchain}" \ |
||||
//test/... \ |
||||
) |
||||
|
||||
_run bazel "$action" "${args[@]}" |
||||
|
||||
done <<EOF |
||||
test linux_amd64 linux_amd64_musl : |
||||
test linux_amd64 linux_amd64_gnu.2.19 : |
||||
test linux_arm64 linux_arm64_musl qemu-aarch64 |
||||
test linux_arm64 linux_arm64_gnu.2.28 qemu-aarch64 |
||||
build darwin_amd64 darwin_amd64 : |
||||
EOF |
||||
bazel test ... |
||||
|
@ -0,0 +1 @@ |
||||
package(default_visibility = ["//test:__pkg__"]) |
@ -0,0 +1,67 @@ |
||||
def _platform_transition_impl(settings, attr): |
||||
_ignore = settings |
||||
return { |
||||
"//command_line_option:platforms": "@zig_sdk//platform:{}".format(attr.platform), |
||||
"//command_line_option:extra_toolchains": ["@zig_sdk//toolchain:{}".format(tc) for tc in attr.extra_toolchains], |
||||
} |
||||
|
||||
_platform_transition = transition( |
||||
implementation = _platform_transition_impl, |
||||
inputs = [], |
||||
outputs = [ |
||||
"//command_line_option:platforms", |
||||
"//command_line_option:extra_toolchains", |
||||
], |
||||
) |
||||
|
||||
def _platform_binary_impl(ctx): |
||||
source_info = ctx.attr.src[DefaultInfo] |
||||
|
||||
executable = None |
||||
if source_info.files_to_run and source_info.files_to_run.executable: |
||||
executable = ctx.actions.declare_file("{}_{}".format(ctx.file.src.basename, ctx.attr.platform)) |
||||
ctx.actions.run_shell( |
||||
command = "cp {} {}".format(source_info.files_to_run.executable.path, executable.path), |
||||
inputs = [source_info.files_to_run.executable], |
||||
outputs = [executable], |
||||
) |
||||
|
||||
return [DefaultInfo( |
||||
files = depset(ctx.files.src), |
||||
executable = executable, |
||||
)] |
||||
|
||||
_attrs = { |
||||
"src": attr.label( |
||||
allow_single_file = True, |
||||
mandatory = True, |
||||
doc = "Target to build.", |
||||
), |
||||
"platform": attr.string( |
||||
doc = "The platform to build the target for.", |
||||
), |
||||
"extra_toolchains": attr.string_list( |
||||
doc = "The toolchains to provide as extra_toolchains.", |
||||
), |
||||
"_allowlist_function_transition": attr.label( |
||||
default = "@bazel_tools//tools/allowlists/function_transition_allowlist", |
||||
), |
||||
} |
||||
|
||||
# wrap a single exectable and build it for the specified platform passing in |
||||
# the extra_toolchains. |
||||
platform_binary = rule( |
||||
implementation = _platform_binary_impl, |
||||
cfg = _platform_transition, |
||||
attrs = _attrs, |
||||
executable = True, |
||||
) |
||||
|
||||
# wrap a single test target and build it for the specified platform passing in |
||||
# the extra_toolchains. |
||||
platform_test = rule( |
||||
implementation = _platform_binary_impl, |
||||
cfg = _platform_transition, |
||||
attrs = _attrs, |
||||
test = True, |
||||
) |
Loading…
Reference in new issue