Skip to content

Commit

Permalink
tests: run on more platforms, avoid shell scripts
Browse files Browse the repository at this point in the history
- run all tests on all platforms.
- enable more CI checks on more platforms. Turns out I just missed quite
  a few.
- replace `test.sh` with `test.go`, which will be useful in uber#165.
  • Loading branch information
Motiejus Jakštys committed Feb 21, 2024
1 parent 361dbd1 commit 51bd381
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 171 deletions.
24 changes: 16 additions & 8 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
try-import %workspace%/.bazelrc.ci

test --sandbox_default_allow_network=false
test --test_output=errors
common --enable_platform_specific_config

build --incompatible_disallow_empty_glob
build --verbose_failures
build --worker_sandboxing

# TODO: turn this back on when Zig can build CGo (https://github.com/uber/hermetic_cc_toolchain/issues/10)
#build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp

build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
build:darwin_toolchains --extra_toolchains @zig_sdk//toolchain:darwin_amd64,@zig_sdk//toolchain:darwin_arm64

build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp

build:macos_toolchains --extra_toolchains @zig_sdk//toolchain:darwin_amd64,@zig_sdk//toolchain:darwin_arm64
build:macos_toolchains --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:macos_toolchains --build_tag_filters=

build:linux --config=macos_toolchains
build:windows --config=macos_toolchains
build:macos --build_tag_filters=-darwin_c

test --sandbox_default_allow_network=false
test --test_output=errors
39 changes: 15 additions & 24 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,28 @@ jobs:
/tmp/zig-cache
~/.cache/bazelisk
- run: echo "common --announce_rc" >> .bazelrc.ci

- run: brew install bash
if: runner.os == 'macOS'

- run: echo "common --announce_rc" >> .bazelrc.ci
- run: echo "build --sandbox_add_mount_pair=C:\\Temp" >> .bazelrc.ci
if: runner.os == 'Windows'

# Linux, macOS and Windows
- run: tools/bazel test //...
- run: ci/list_toolchains_platforms
- run: ci/zig-utils

# Linux and macOS
- run: ci/release
if: runner.os == 'Linux' || runner.os == 'macOS'
# Test the Zig toolchain for Darwin on Darwin.
- run: tools/bazel build --config=macos_toolchains --@rules_go//go/config:static --@rules_go//go/config:pure //test/c/...
if: runner.os == 'macOS'

# Windows problems:
# protoc does not compile due to `-lpthread`.
- run: ci/lint
if: runner.os == 'Linux' || runner.os == 'macOS'
# TODO: releaser is broken on windows
if: runner.os != 'Windows'
# releaser fails to write `README.md` for some reason.
- run: ci/release
if: runner.os != 'Windows'
- run: ci/prepare_git && ci/test_example rules_cc override_repository
if: runner.os == 'Linux' || runner.os == 'macOS'

# Linux and Windows
- run: tools/bazel build --config=darwin_toolchains //...
if: runner.os == 'Linux' || runner.os == 'Windows'

# Linux
- run: ci/test --config=darwin_toolchains
if: runner.os == 'Linux'
# TODO windows: broken releaser. MacOS: cgo.
if: runner.os != 'Windows'
- run: ci/prepare_git && ci/test_example bzlmod override_module
if: runner.os == 'Linux'

# macOS
- run: tools/bazel build --config=darwin_toolchains --build_tag_filters=darwin_c //...
if: runner.os == 'macOS'
if: runner.os != 'Windows'
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ zig_toolchains()
And this to `.bazelrc` on a Unix-y systems:

```
build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp
```

Windows:

```
build --sandbox_add_mount_pair=C:\Temp
common --enable_platform_specific_config
build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp
```

The directories can be narrowed down to `/tmp/zig-cache` (Linux),
Expand Down Expand Up @@ -375,9 +371,9 @@ A standalone Docker environment to play with `hermetic_cc_toolchain`:
$ docker run -e CC=/usr/bin/false -ti --rm -v "$PWD:/x" -w /x debian:bookworm-slim
# apt update && apt install --no-install-recommends -y shellcheck ca-certificates python3 git
# git config --global --add safe.directory /x
# tools/bazel test ...
# ./ci/lint
# ./ci/release
# ./ci/test
# ./ci/zig-wrapper
```
## Communication
Expand Down
2 changes: 1 addition & 1 deletion ci/release
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -xeuo pipefail
cd "$(git rev-parse --show-toplevel)"

>&2 echo "--- releaser :flag-lt:"
TAG=$(git -c 'versionsort.suffix=-rc' tag --sort=v:refname | grep -vE '2\.2\.(2|3)' | tail -1)
TAG=$(git -c 'versionsort.suffix=-rc' tag --sort=v:refname | tail -1)
tools/bazel run //tools/releaser -- -tag "$TAG" -skipBranchCheck

>&2 echo "--- git diff :git:"
Expand Down
44 changes: 0 additions & 44 deletions ci/test

This file was deleted.

16 changes: 9 additions & 7 deletions examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Copyright 2023 Uber Technologies, Inc.
# Licensed under the MIT License
test --sandbox_default_allow_network=false
test --test_output=errors
try-import %workspace%/../../.bazelrc.ci

common --enable_platform_specific_config

build --incompatible_disallow_empty_glob
build --verbose_failures
build --worker_sandboxing
build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline

build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp
build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp

build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
test --sandbox_default_allow_network=false
test --test_output=errors
15 changes: 9 additions & 6 deletions examples/rules_cc/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright 2023 Uber Technologies, Inc.
# Licensed under the MIT License
test --sandbox_default_allow_network=false
test --test_output=errors
try-import %workspace%/../../.bazelrc.ci

common --enable_platform_specific_config

build --incompatible_disallow_empty_glob
build --verbose_failures
build --worker_sandboxing

build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp

build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp
build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
test --sandbox_default_allow_network=false
test --test_output=errors
90 changes: 68 additions & 22 deletions test/c/BUILD
Original file line number Diff line number Diff line change
@@ -1,55 +1,101 @@
load("@hermetic_cc_toolchain//rules:platform.bzl", "platform_binary")
load("@rules_go//go:def.bzl", "go_library", "go_test")

cc_binary(
name = "which_libc",
srcs = ["main.c"],
)

_LINUX_AMD64 = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
]

_DARWIN_AMD64 = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
]

_DARWIN_ARM64 = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
]

_WINDOWS_AMD64 = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
]

[
(
platform_binary(
name = "which_libc_{}".format(name),
src = "which_libc",
platform = platform,
tags = tags,
),
sh_test(
go_test(
name = "test_libc_{}".format(name),
srcs = ["test.sh"],
data = ["which_libc_{}".format(name)],
data = [":which_libc_{}".format(name)],
embed = [":c_test"],
env = {
"WANT": want,
"BINARY": "$(location which_libc_{})".format(name),
"BINARY": "$(rlocationpath which_libc_{})".format(name),
},
target_compatible_with = compatible_with,
),
)
for name, platform, want in [
("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl", "linux non-glibc"),
("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28", "linux glibc_2.28"),
("linux_amd64", "//platform:linux_amd64", "linux glibc_2.28"),
]
]

[
(
platform_binary(
name = "which_libc_{}".format(name),
src = "which_libc",
platform = platform,
tags = tags,
for name, platform, compatible_with, want, tags in [
(
"linux_amd64_musl",
"//libc_aware/platform:linux_amd64_musl",
_LINUX_AMD64,
"^linux non-glibc",
[],
),
(
"linux_amd64_gnu.2.28",
"//libc_aware/platform:linux_amd64_gnu.2.28",
_LINUX_AMD64,
"^linux glibc_2.28",
[],
),
(
"linux_amd64",
"//platform:linux_amd64",
_LINUX_AMD64,
"^linux glibc_2.28",
[],
),
(
"windows_amd64",
"//platform:windows_amd64",
_WINDOWS_AMD64,
"^windows ",
[],
),
)
for name, platform, tags in [
(
"darwin_amd64",
"//platform:darwin_amd64",
_DARWIN_AMD64,
"^macos non-glibc",
["darwin_c"],
),
(
"darwin_arm64",
"//platform:darwin_arm64",
_DARWIN_ARM64,
"^macos non-glibc",
["darwin_c"],
),
("windows_amd64", "//platform:windows_amd64", []),
("windows_arm64", "//platform:windows_arm64", []),
]
]

go_library(
name = "c_test",
srcs = ["c_test.go"],
deps = [
"@com_github_stretchr_testify//assert",
"@rules_go//go/runfiles",
],
)
26 changes: 26 additions & 0 deletions test/c/c_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package c_test

import (
"os"
"os/exec"
"testing"

"github.com/bazelbuild/rules_go/go/runfiles"
"github.com/stretchr/testify/assert"
)

func TestYadda(t *testing.T) {
want := os.Getenv("WANT")

binary, err := runfiles.Rlocation(os.Getenv("BINARY"))
if err != nil {
t.Fatalf("unable to locate guest binary: %v", err)
}

got, err := exec.Command(binary).CombinedOutput()
if err != nil {
t.Fatalf("run %q: %v", binary, err)
}

assert.Regexp(t, string(want), string(got))
}
20 changes: 0 additions & 20 deletions test/c/test.sh

This file was deleted.

Loading

0 comments on commit 51bd381

Please sign in to comment.