Skip to content
Open
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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.2.1
9.0.2
73 changes: 56 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ concurrency:
# Cancels pending runs when a PR gets updated.
group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
cancel-in-progress: true

jobs:

build-and-test:
Expand All @@ -20,23 +21,24 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- uses: actions/cache@v4
name: "Windows: cache bazelisk and zig-cache"
if: runner.os == 'Windows'
with:
key: cache-${{ matrix.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
key: cache-${{ runner.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
restore-keys: cache-${{ runner.os }}-
path: |
C:\Temp\zig-cache
~\AppData\Local\bazelisk'
~\AppData\Local\bazelisk

- uses: actions/cache@v4
name: "MacOS: cache bazelisk and zig-cache"
if: runner.os == 'macOS'
with:
key: cache-${{ matrix.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
key: cache-${{ runner.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
restore-keys: cache-${{ runner.os }}-
path: |
/var/tmp/zig-cache
~/Library/Caches/bazelisk
Expand All @@ -45,31 +47,68 @@ jobs:
name: "Linux: cache bazelisk and zig-cache"
if: runner.os == 'Linux'
with:
key: cache-${{ matrix.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
key: cache-${{ runner.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
restore-keys: cache-${{ runner.os }}-
path: |
/tmp/zig-cache
~/.cache/bazelisk

- run: echo "common --announce_rc" >> .bazelrc.ci

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

# Linux, macOS and Windows
- run: ci/list_toolchains_platforms
- run: tools/bazel test //...
- run: ci/prepare_git && ci/test_example rules_cc override_repository
- run: ci/prepare_git && ci/test_example bzlmod override_module
if: runner.os != 'Windows'
- run: tools/bazel test //test/c:test_libc_windows_amd64 //test/cgo:cgo_test //test/cgo:cgo_windows_amd64 //test/cgo:cgo_windows_arm64
if: runner.os == 'Windows'
- run: ci/zig-utils
if: runner.os != 'Windows'

# Test the Zig toolchain for Darwin on Darwin.
- run: tools/bazel test --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`.
test-examples:
strategy:
matrix:
example:
- {name: rules_cc, override: override_module}
- {name: bzlmod, override: override_module}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true

- uses: actions/cache@v4
name: "Linux: cache bazelisk and zig-cache"
with:
key: cache-${{ runner.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
restore-keys: cache-${{ runner.os }}-
path: |
/tmp/zig-cache
~/.cache/bazelisk

- run: echo "common --announce_rc" >> .bazelrc.ci

- run: ci/prepare_git && ci/test_example ${{ matrix.example.name }} ${{ matrix.example.override }}

lint-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- uses: actions/cache@v4
name: "Linux: cache bazelisk and zig-cache"
with:
key: cache-${{ runner.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
restore-keys: cache-${{ runner.os }}-
path: |
/tmp/zig-cache
~/.cache/bazelisk

- run: echo "common --announce_rc" >> .bazelrc.ci

- run: ci/lint
if: runner.os != 'Windows'
# Releaser emits different hashes
- run: ci/release
if: runner.os != 'Windows'
19 changes: 13 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module(
name = "hermetic_cc_toolchain",
version = "4.1.0",
version = "4.2.0",
)

bazel_dep(name = "bazel_features", version = "1.21.0")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_cc", version = "0.2.14")
bazel_dep(name = "bazel_features", version = "1.45.0")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.2.17")

bazel_dep(name = "rules_go", version = "0.54.0", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.60.0", dev_dependency = True)

go_sdk = use_extension(
"@rules_go//go:extensions.bzl",
Expand All @@ -16,14 +16,21 @@ go_sdk = use_extension(
)
use_repo(go_sdk, "go_default_sdk")

bazel_dep(name = "gazelle", version = "0.43.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.50.0", dev_dependency = True)

go_deps = use_extension(
"@gazelle//:extensions.bzl",
"go_deps",
dev_dependency = True,
)
go_deps.from_file(go_mod = "//:go.mod")
go_deps.gazelle_override(
build_file_generation = "clean",
directives = [
"gazelle:proto disable",
],
path = "github.com/bazelbuild/buildtools",
)
use_repo(
go_deps,
"com_github_bazelbuild_buildtools",
Expand Down
Empty file removed WORKSPACE
Empty file.
4 changes: 4 additions & 0 deletions ci/release
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ cd "$(git rev-parse --show-toplevel)"

>&2 echo "--- releaser :flag-lt:"
TAG=$(git -c 'versionsort.suffix=-rc' tag --sort=v:refname | tail -1)
if [ -z "$TAG" ]; then
>&2 echo "no git tags found, skipping release validation"
exit 0
fi
tools/bazel run //tools/releaser -- -tag "$TAG" -skipBranchCheck

>&2 echo "--- git diff :git:"
Expand Down
4 changes: 2 additions & 2 deletions examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module(
)

bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_go", version = "0.54.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "hermetic_cc_toolchain", version = "3.2.0")
bazel_dep(name = "rules_go", version = "0.60.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "hermetic_cc_toolchain", version = "4.1.0")

toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(toolchains, "zig_sdk")
Expand Down
Empty file removed examples/bzlmod/WORKSPACE
Empty file.
1 change: 0 additions & 1 deletion examples/rules_cc/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
try-import %workspace%/../../.bazelrc.ci

common --enable_platform_specific_config
common --noenable_bzlmod --enable_workspace

build --incompatible_disallow_empty_glob
build --verbose_failures
Expand Down
3 changes: 3 additions & 0 deletions examples/rules_cc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright 2023 Uber Technologies, Inc.
# Licensed under the MIT License

load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

cc_binary(
name = "hello_world",
srcs = ["hello_world.cc"],
Expand Down
20 changes: 20 additions & 0 deletions examples/rules_cc/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module(
name = "hermetic_cc_toolchain_rules_cc_example",
version = "0.1.0",
)

bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "hermetic_cc_toolchain", version = "4.1.0")

toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(toolchains, "zig_sdk")

register_toolchains(
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64",
"@zig_sdk//toolchain:windows_amd64",
"@zig_sdk//toolchain:windows_arm64",
)
31 changes: 0 additions & 31 deletions examples/rules_cc/WORKSPACE

This file was deleted.

13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
module github.com/uber/hermetic_cc_toolchain

go 1.22.0
go 1.25.0

toolchain go1.23.6
toolchain go1.26.2

require (
github.com/bazelbuild/buildtools v0.0.0-20240918101019-be1c24cc9a44
github.com/bazelbuild/rules_go v0.54.0
github.com/stretchr/testify v1.8.2
github.com/tetratelabs/wazero v1.6.0
github.com/bazelbuild/rules_go v0.60.0
github.com/stretchr/testify v1.11.1
github.com/tetratelabs/wazero v1.11.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
google.golang.org/protobuf v1.36.3 // indirect
golang.org/x/sys v0.43.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 12 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
github.com/bazelbuild/buildtools v0.0.0-20240918101019-be1c24cc9a44 h1:FGzENZi+SX9I7h9xvMtRA3rel8hCEfyzSixteBgn7MU=
github.com/bazelbuild/buildtools v0.0.0-20240918101019-be1c24cc9a44/go.mod h1:PLNUetjLa77TCCziPsz0EI8a6CUxgC+1jgmWv0H25tg=
github.com/bazelbuild/rules_go v0.54.0 h1:D9aCU7j5rdRxg2rXOZX5zHZ395XC0KbgC4rnyaQ3ofM=
github.com/bazelbuild/rules_go v0.54.0/go.mod h1:T90Gpyq4HDFlsrvtQa2CBdHNJ2P4rAu/uUTmQbanzf0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/bazelbuild/rules_go v0.60.0 h1:apGSxTTrFUyLNvX9NQmF4CbntWAO0/S5eALeVgB/6Qk=
github.com/bazelbuild/rules_go v0.60.0/go.mod h1:CYcohJVxs4n7eftbC39GCqaEJm3E1EME+6QAkGguKoI=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g=
github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
18 changes: 11 additions & 7 deletions rules/cp.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const std = @import("std");

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const argv = try std.process.argsAlloc(gpa.allocator());
defer std.process.argsFree(gpa.allocator(), argv);

if (argv.len != 3) return error.InvalidUsage;
try std.fs.cwd().copyFile(argv[1], std.fs.cwd(), argv[2], .{});
pub fn main(init: std.process.Init) !void {
const arena = init.arena.allocator();
var argv_it = try std.process.Args.Iterator.initAllocator(
init.minimal.args,
arena,
);
_ = argv_it.next();
const src = argv_it.next() orelse return error.InvalidUsage;
const dst = argv_it.next() orelse return error.InvalidUsage;
if (argv_it.next() != null) return error.InvalidUsage;
try std.Io.Dir.copyFile(std.Io.Dir.cwd(), src, std.Io.Dir.cwd(), dst, init.io, .{});
}
4 changes: 2 additions & 2 deletions test/c/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@hermetic_cc_toolchain//rules:platform.bzl", "platform_binary")
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_go//go:def.bzl", "go_library", "go_test")

cc_binary(
Expand Down Expand Up @@ -99,7 +99,7 @@ _WINDOWS_AMD64 = [
(
"wasip1_wasm32",
"//platform:wasip1_wasm",
HOST_CONSTRAINTS,
[],
"^wasi non-glibc",
[],
"WASI",
Expand Down
7 changes: 7 additions & 0 deletions test/colon_link/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
# In Zig 0.14.0, this syntax was broken and the linker incorrectly reported:
# ld.lld: error: unable to find library -l:mylib.so
#
# This is still broken as of Zig 0.16.0 and tracked upstream at:
# https://codeberg.org/ziglang/zig/issues/31823
#
# See https://github.com/ziglang/zig/issues/23287

load("@hermetic_cc_toolchain//rules:platform.bzl", "platform_binary")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")

# Build a versioned shared library "libgreeter.so.1". The standard "-lgreeter"
# flag looks for "libgreeter.so" (unversioned), so the colon syntax is required
Expand Down Expand Up @@ -43,11 +47,14 @@ cc_binary(

# Only glibc targets are tested here. musl uses static linking by default,
# which is incompatible with dynamically linking a .so file.
# Tagged manual: colon-link is broken in Zig 0.16.0.
# Remove manual tag when upstream fix lands.
[
platform_binary(
name = "main_{}".format(name),
src = "main",
platform = platform,
tags = ["manual"],
)
for name, platform in [
("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28"),
Expand Down
Loading
Loading