From c7d4bf5289793f0f5e990cca3c89d205eb12e255 Mon Sep 17 00:00:00 2001 From: Nicolas Torres Date: Sun, 15 Mar 2026 15:38:34 +0100 Subject: [PATCH 1/7] add e2e custom toolchain glibc version example --- .../toolchain-glibc-version/BUILD.bazel | 59 +++++++++++++++++++ .../toolchain-glibc-version/README.md | 22 +++++++ .../toolchain-glibc-version/main.zig | 16 +++++ 3 files changed, 97 insertions(+) create mode 100644 e2e/workspace/toolchain-glibc-version/BUILD.bazel create mode 100644 e2e/workspace/toolchain-glibc-version/README.md create mode 100644 e2e/workspace/toolchain-glibc-version/main.zig diff --git a/e2e/workspace/toolchain-glibc-version/BUILD.bazel b/e2e/workspace/toolchain-glibc-version/BUILD.bazel new file mode 100644 index 00000000..d6969ddf --- /dev/null +++ b/e2e/workspace/toolchain-glibc-version/BUILD.bazel @@ -0,0 +1,59 @@ +load("@rules_zig//zig:defs.bzl", "zig_binary", "zig_configure_binary") +load("@rules_zig//zig:toolchain.bzl", "zig_target_toolchain") +load("@rules_zig//zig:defs.bzl", "zig_test") + +platform( + name = "x86_64-linux-gnu-2.25", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ":gnu-2.25", + ], +) + +constraint_value( + name = "gnu-2.25", + constraint_setting = "@rules_zig//zig/platforms/abi:abi", + visibility = ["//visibility:public"], +) + +zig_target_toolchain( + name = "glibc-2.25", + target = "x86_64-linux-gnu.2.25", +) + +toolchain( + name = "glibc_2.25_toolchain", + target_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ":gnu-2.25", + ], + toolchain = ":glibc-2.25", + toolchain_type = "@rules_zig//zig/target:toolchain_type", +) + +zig_binary( + name = "main-unconfigured", + main = "main.zig", + deps = [ + "@rules_zig//zig/lib:libc", + ], +) + +zig_configure_binary( + name = "main-2.25", + actual = ":main-unconfigured", + extra_toolchains = [":glibc_2.25_toolchain"], + target = ":x86_64-linux-gnu-2.25", +) + +zig_test( + name = "fallback_glibc.2.17", + size = "small", + main = "main.zig", + visibility = ["//zig/tests:__pkg__"], + deps = [ + "@rules_zig//zig/lib:libc", + ], +) diff --git a/e2e/workspace/toolchain-glibc-version/README.md b/e2e/workspace/toolchain-glibc-version/README.md new file mode 100644 index 00000000..338c1aab --- /dev/null +++ b/e2e/workspace/toolchain-glibc-version/README.md @@ -0,0 +1,22 @@ +By default, `rules_zig` targets a "lowest common denominator" glibc version to ensure broad compatibility. You can find the discussion behind this choice in [this PR](https://github.com/aherrmann/rules_zig/pull/299) and see the implementation [here](https://github.com/aherrmann/rules_zig/blob/main/zig/target/BUILD.bazel#L56). + +This example project demonstrates how to manually configure and use a specific glibc version with `rules_zig`. + + +```bash +# navigate to the workspace directory: +cd e2e/workspace + +# run with the default glibc version +# "main-unconfigured" uses the default glibc version +# note that the runtime glibc version depends on the execution environment +bazel run toolchain-glibc-version:main-unconfigured + +# run with a custom glibc version +# "main-2.25" uses a custom toolchain using glibc 2.25 +bazel run toolchain-glibc-version:main-2.25 + +# verify the fallback behaviour +# this shows the "unconfigured" zig_test still uses the fallback version +bazel test toolchain-glibc-version:fallback_glibc.2.17 +``` diff --git a/e2e/workspace/toolchain-glibc-version/main.zig b/e2e/workspace/toolchain-glibc-version/main.zig new file mode 100644 index 00000000..595407e8 --- /dev/null +++ b/e2e/workspace/toolchain-glibc-version/main.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +const c = @cImport({ + @cInclude("features.h"); +}); + +extern "c" fn gnu_get_libc_version() [*c]const u8; + +pub fn main() !void { + std.debug.print("glibc compile-time version: {d}.{d}\n", .{ c.__GLIBC__, c.__GLIBC_MINOR__ }); + std.debug.print("glibc runtime version: {s}\n", .{gnu_get_libc_version()}); +} + +test "test_fallback_glibc.2.17" { + try std.testing.expectEqual(2, c.__GLIBC__); + try std.testing.expectEqual(17, c.__GLIBC_MINOR__); +} From 786b4a75f187b56e9e223ffc2bce40c94fb23b15 Mon Sep 17 00:00:00 2001 From: Nicolas Torres Date: Sun, 15 Mar 2026 20:54:53 +0100 Subject: [PATCH 2/7] add simple foreign_cc example using cmake --- e2e/workspace/MODULE.bazel | 5 +++ .../simple-cmake-library/BUILD.bazel | 35 +++++++++++++++++++ .../external_library/CMakeLists.txt | 15 ++++++++ .../external_library/hello.c | 7 ++++ .../external_library/hello.h | 3 ++ e2e/workspace/simple-cmake-library/main.zig | 7 ++++ 6 files changed, 72 insertions(+) create mode 100644 e2e/workspace/simple-cmake-library/BUILD.bazel create mode 100644 e2e/workspace/simple-cmake-library/external_library/CMakeLists.txt create mode 100644 e2e/workspace/simple-cmake-library/external_library/hello.c create mode 100644 e2e/workspace/simple-cmake-library/external_library/hello.h create mode 100644 e2e/workspace/simple-cmake-library/main.zig diff --git a/e2e/workspace/MODULE.bazel b/e2e/workspace/MODULE.bazel index 27023e60..6e87de2c 100644 --- a/e2e/workspace/MODULE.bazel +++ b/e2e/workspace/MODULE.bazel @@ -38,3 +38,8 @@ local_path_override( module_name = "runfiles_library_transitive_dependency", path = "runfiles-library/dependency/transitive-dependency", ) + +bazel_dep( + name = "rules_foreign_cc", + version = "0.15.0", +) diff --git a/e2e/workspace/simple-cmake-library/BUILD.bazel b/e2e/workspace/simple-cmake-library/BUILD.bazel new file mode 100644 index 00000000..9d0ac483 --- /dev/null +++ b/e2e/workspace/simple-cmake-library/BUILD.bazel @@ -0,0 +1,35 @@ +load("@rules_zig//zig:defs.bzl", "zig_binary") +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +# -------------------- +# external library using foreign_cc +filegroup( + name = "c-hello-srcs", + srcs = glob(["external_library/**"]), +) + +cmake( + name = "c-hello", + lib_source = ":c-hello-srcs", + out_include_dir = "hello", + out_shared_libs = ["libhello.so"], +) +# -------------------- +# equivalent implementation with cc_rules +# cc_library( +# name = "c-hello", +# srcs = ["external_library/hello.c"], +# hdrs = ["external_library/hello.h"], +# includes = ["external_library"], +# ) +# -------------------- + +zig_binary( + name = "main", + main = "main.zig", + deps = [ + ":c-hello", + "@rules_zig//zig/lib:libc", + ], +) diff --git a/e2e/workspace/simple-cmake-library/external_library/CMakeLists.txt b/e2e/workspace/simple-cmake-library/external_library/CMakeLists.txt new file mode 100644 index 00000000..c08a7156 --- /dev/null +++ b/e2e/workspace/simple-cmake-library/external_library/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.20) +project(hello) + +add_library(hello SHARED hello.c) +target_include_directories(hello PRIVATE ".") + + +install(TARGETS hello EXPORT helloTargets + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) + +install(FILES hello.h + DESTINATION "hello/" +) + diff --git a/e2e/workspace/simple-cmake-library/external_library/hello.c b/e2e/workspace/simple-cmake-library/external_library/hello.c new file mode 100644 index 00000000..475b6826 --- /dev/null +++ b/e2e/workspace/simple-cmake-library/external_library/hello.c @@ -0,0 +1,7 @@ +#include "hello.h" +#include "stdio.h" + +void hello() +{ + printf("Hello World from hello.c!\n"); +} diff --git a/e2e/workspace/simple-cmake-library/external_library/hello.h b/e2e/workspace/simple-cmake-library/external_library/hello.h new file mode 100644 index 00000000..af9bb7f2 --- /dev/null +++ b/e2e/workspace/simple-cmake-library/external_library/hello.h @@ -0,0 +1,3 @@ +#pragma once + +void hello(); diff --git a/e2e/workspace/simple-cmake-library/main.zig b/e2e/workspace/simple-cmake-library/main.zig new file mode 100644 index 00000000..ee966956 --- /dev/null +++ b/e2e/workspace/simple-cmake-library/main.zig @@ -0,0 +1,7 @@ +const c = @cImport({ + @cInclude("hello.h"); +}); + +pub fn main() !void { + c.hello(); +} From 0119ec70222a78dc6110349c6f64c1613da531f5 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Tue, 17 Mar 2026 08:56:46 +0100 Subject: [PATCH 3/7] Set dev_dependency = True for consistency --- e2e/workspace/MODULE.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/workspace/MODULE.bazel b/e2e/workspace/MODULE.bazel index 6e87de2c..84341d1b 100644 --- a/e2e/workspace/MODULE.bazel +++ b/e2e/workspace/MODULE.bazel @@ -42,4 +42,5 @@ local_path_override( bazel_dep( name = "rules_foreign_cc", version = "0.15.0", + dev_dependency = True, ) From 7318b1dd90aab34bb5a51d769c883799efc0f04e Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Tue, 17 Mar 2026 09:09:43 +0100 Subject: [PATCH 4/7] Add a test for the transitioned glibc version --- .../toolchain-glibc-version/BUILD.bazel | 18 ++++++++++++++++-- .../main-2.25-glibc-version.expected | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 e2e/workspace/toolchain-glibc-version/main-2.25-glibc-version.expected diff --git a/e2e/workspace/toolchain-glibc-version/BUILD.bazel b/e2e/workspace/toolchain-glibc-version/BUILD.bazel index d6969ddf..bd7e5eb3 100644 --- a/e2e/workspace/toolchain-glibc-version/BUILD.bazel +++ b/e2e/workspace/toolchain-glibc-version/BUILD.bazel @@ -1,6 +1,6 @@ -load("@rules_zig//zig:defs.bzl", "zig_binary", "zig_configure_binary") +load("@bazel_skylib//rules:diff_test.bzl", "diff_test") +load("@rules_zig//zig:defs.bzl", "zig_binary", "zig_configure_binary", "zig_test") load("@rules_zig//zig:toolchain.bzl", "zig_target_toolchain") -load("@rules_zig//zig:defs.bzl", "zig_test") platform( name = "x86_64-linux-gnu-2.25", @@ -57,3 +57,17 @@ zig_test( "@rules_zig//zig/lib:libc", ], ) + +genrule( + name = "main-2.25-glibc-version", + outs = ["main-2.25-glibc-version.actual"], + cmd = "$(execpath :main-2.25) |& grep compile-time > $(OUTS)", + tools = [":main-2.25"], +) + +diff_test( + name = "main-2.25-glibc-version-test", + size = "small", + file1 = ":main-2.25-glibc-version.expected", + file2 = ":main-2.25-glibc-version.actual", +) diff --git a/e2e/workspace/toolchain-glibc-version/main-2.25-glibc-version.expected b/e2e/workspace/toolchain-glibc-version/main-2.25-glibc-version.expected new file mode 100644 index 00000000..7c6a445d --- /dev/null +++ b/e2e/workspace/toolchain-glibc-version/main-2.25-glibc-version.expected @@ -0,0 +1 @@ +glibc compile-time version: 2.25 From 29882120db1a94a38c758d6fcf3aa1ffacb0a4d4 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Tue, 17 Mar 2026 09:12:29 +0100 Subject: [PATCH 5/7] update generated files --- .bazelrc | 4 ++-- e2e/workspace/simple-cmake-library/BUILD.bazel | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.bazelrc b/.bazelrc index e85840df..760a273d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -18,8 +18,8 @@ build --workspace_status_command=$(pwd)/workspace_status.sh # To update these lines, execute # `bazel run @rules_bazel_integration_test//tools:update_deleted_packages` # docs: https://bazel.build/reference/command-line-reference#flag--deleted_packages -build --deleted_packages=e2e/workspace,e2e/workspace/bazel_builtin,e2e/workspace/c-sources,e2e/workspace/canonical-name-module,e2e/workspace/canonical-name-module/other,e2e/workspace/cc-dependencies,e2e/workspace/cc-dependencies/shared-library,e2e/workspace/cc-dependencies/static-library,e2e/workspace/cc-dependencies/static-library-cdeps,e2e/workspace/configure-mode,e2e/workspace/configure-target,e2e/workspace/configure-threaded,e2e/workspace/configure-use_cc_common_link,e2e/workspace/configure-use_cc_common_link/shared-library,e2e/workspace/configure-use_cc_common_link/static-library,e2e/workspace/configure-version,e2e/workspace/data-dependencies,e2e/workspace/embed-file,e2e/workspace/env-attr,e2e/workspace/import-name-attr,e2e/workspace/include-dependencies,e2e/workspace/include-dependencies/zig-include,e2e/workspace/include-dependencies/zig-include-define,e2e/workspace/include-dependencies/zig-include-isystem,e2e/workspace/include-dependencies/zig-std-include,e2e/workspace/link-dependencies,e2e/workspace/link-dependencies/shared-library,e2e/workspace/link-dependencies/static-library,e2e/workspace/linker-script,e2e/workspace/linkopts-attr,e2e/workspace/location-expansion,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/root-module-from-single-dependency,e2e/workspace/runfiles-library,e2e/workspace/runfiles-library/dependency,e2e/workspace/runfiles-library/dependency/transitive-dependency,e2e/workspace/simple-binary,e2e/workspace/simple-library,e2e/workspace/simple-shared-library,e2e/workspace/simple-test,e2e/workspace/test-runner-attr,e2e/workspace/transitive-zig-modules-binary,e2e/workspace/transitive-zig-modules-binary/hello-world,e2e/workspace/transitive-zig-modules-binary/hello-world/data,e2e/workspace/transitive-zig-modules-binary/hello-world/data/hello,e2e/workspace/transitive-zig-modules-binary/hello-world/data/world,e2e/workspace/transitive-zig-modules-binary/hello-world/io,e2e/workspace/translate-c/transitive-cc-library-zig-binary,e2e/workspace/zig-docs,e2e/workspace/zig-header,e2e/workspace/zig-module-binary,e2e/workspace/zig-module-binary/data,e2e/workspace/zig-module-binary/io,zig/tests/integration_tests/minimal,zig/tests/integration_tests/mirrors,zig/tests/integration_tests/workspace,zig/tests/integration_tests/workspace/custom_interpreter,zig/tests/integration_tests/workspace/env-attr,zig/tests/integration_tests/workspace/runfiles -query --deleted_packages=e2e/workspace,e2e/workspace/bazel_builtin,e2e/workspace/c-sources,e2e/workspace/canonical-name-module,e2e/workspace/canonical-name-module/other,e2e/workspace/cc-dependencies,e2e/workspace/cc-dependencies/shared-library,e2e/workspace/cc-dependencies/static-library,e2e/workspace/cc-dependencies/static-library-cdeps,e2e/workspace/configure-mode,e2e/workspace/configure-target,e2e/workspace/configure-threaded,e2e/workspace/configure-use_cc_common_link,e2e/workspace/configure-use_cc_common_link/shared-library,e2e/workspace/configure-use_cc_common_link/static-library,e2e/workspace/configure-version,e2e/workspace/data-dependencies,e2e/workspace/embed-file,e2e/workspace/env-attr,e2e/workspace/import-name-attr,e2e/workspace/include-dependencies,e2e/workspace/include-dependencies/zig-include,e2e/workspace/include-dependencies/zig-include-define,e2e/workspace/include-dependencies/zig-include-isystem,e2e/workspace/include-dependencies/zig-std-include,e2e/workspace/link-dependencies,e2e/workspace/link-dependencies/shared-library,e2e/workspace/link-dependencies/static-library,e2e/workspace/linker-script,e2e/workspace/linkopts-attr,e2e/workspace/location-expansion,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/root-module-from-single-dependency,e2e/workspace/runfiles-library,e2e/workspace/runfiles-library/dependency,e2e/workspace/runfiles-library/dependency/transitive-dependency,e2e/workspace/simple-binary,e2e/workspace/simple-library,e2e/workspace/simple-shared-library,e2e/workspace/simple-test,e2e/workspace/test-runner-attr,e2e/workspace/transitive-zig-modules-binary,e2e/workspace/transitive-zig-modules-binary/hello-world,e2e/workspace/transitive-zig-modules-binary/hello-world/data,e2e/workspace/transitive-zig-modules-binary/hello-world/data/hello,e2e/workspace/transitive-zig-modules-binary/hello-world/data/world,e2e/workspace/transitive-zig-modules-binary/hello-world/io,e2e/workspace/translate-c/transitive-cc-library-zig-binary,e2e/workspace/zig-docs,e2e/workspace/zig-header,e2e/workspace/zig-module-binary,e2e/workspace/zig-module-binary/data,e2e/workspace/zig-module-binary/io,zig/tests/integration_tests/minimal,zig/tests/integration_tests/mirrors,zig/tests/integration_tests/workspace,zig/tests/integration_tests/workspace/custom_interpreter,zig/tests/integration_tests/workspace/env-attr,zig/tests/integration_tests/workspace/runfiles +build --deleted_packages=e2e/workspace,e2e/workspace/bazel_builtin,e2e/workspace/c-sources,e2e/workspace/canonical-name-module,e2e/workspace/canonical-name-module/other,e2e/workspace/cc-dependencies,e2e/workspace/cc-dependencies/shared-library,e2e/workspace/cc-dependencies/static-library,e2e/workspace/cc-dependencies/static-library-cdeps,e2e/workspace/configure-mode,e2e/workspace/configure-target,e2e/workspace/configure-threaded,e2e/workspace/configure-use_cc_common_link,e2e/workspace/configure-use_cc_common_link/shared-library,e2e/workspace/configure-use_cc_common_link/static-library,e2e/workspace/configure-version,e2e/workspace/data-dependencies,e2e/workspace/embed-file,e2e/workspace/env-attr,e2e/workspace/import-name-attr,e2e/workspace/include-dependencies,e2e/workspace/include-dependencies/zig-include,e2e/workspace/include-dependencies/zig-include-define,e2e/workspace/include-dependencies/zig-include-isystem,e2e/workspace/include-dependencies/zig-std-include,e2e/workspace/link-dependencies,e2e/workspace/link-dependencies/shared-library,e2e/workspace/link-dependencies/static-library,e2e/workspace/linker-script,e2e/workspace/linkopts-attr,e2e/workspace/location-expansion,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/root-module-from-single-dependency,e2e/workspace/runfiles-library,e2e/workspace/runfiles-library/dependency,e2e/workspace/runfiles-library/dependency/transitive-dependency,e2e/workspace/simple-binary,e2e/workspace/simple-cmake-library,e2e/workspace/simple-library,e2e/workspace/simple-shared-library,e2e/workspace/simple-test,e2e/workspace/test-runner-attr,e2e/workspace/toolchain-glibc-version,e2e/workspace/transitive-zig-modules-binary,e2e/workspace/transitive-zig-modules-binary/hello-world,e2e/workspace/transitive-zig-modules-binary/hello-world/data,e2e/workspace/transitive-zig-modules-binary/hello-world/data/hello,e2e/workspace/transitive-zig-modules-binary/hello-world/data/world,e2e/workspace/transitive-zig-modules-binary/hello-world/io,e2e/workspace/translate-c/transitive-cc-library-zig-binary,e2e/workspace/zig-docs,e2e/workspace/zig-header,e2e/workspace/zig-module-binary,e2e/workspace/zig-module-binary/data,e2e/workspace/zig-module-binary/io,zig/tests/integration_tests/minimal,zig/tests/integration_tests/mirrors,zig/tests/integration_tests/workspace,zig/tests/integration_tests/workspace/custom_interpreter,zig/tests/integration_tests/workspace/env-attr,zig/tests/integration_tests/workspace/runfiles +query --deleted_packages=e2e/workspace,e2e/workspace/bazel_builtin,e2e/workspace/c-sources,e2e/workspace/canonical-name-module,e2e/workspace/canonical-name-module/other,e2e/workspace/cc-dependencies,e2e/workspace/cc-dependencies/shared-library,e2e/workspace/cc-dependencies/static-library,e2e/workspace/cc-dependencies/static-library-cdeps,e2e/workspace/configure-mode,e2e/workspace/configure-target,e2e/workspace/configure-threaded,e2e/workspace/configure-use_cc_common_link,e2e/workspace/configure-use_cc_common_link/shared-library,e2e/workspace/configure-use_cc_common_link/static-library,e2e/workspace/configure-version,e2e/workspace/data-dependencies,e2e/workspace/embed-file,e2e/workspace/env-attr,e2e/workspace/import-name-attr,e2e/workspace/include-dependencies,e2e/workspace/include-dependencies/zig-include,e2e/workspace/include-dependencies/zig-include-define,e2e/workspace/include-dependencies/zig-include-isystem,e2e/workspace/include-dependencies/zig-std-include,e2e/workspace/link-dependencies,e2e/workspace/link-dependencies/shared-library,e2e/workspace/link-dependencies/static-library,e2e/workspace/linker-script,e2e/workspace/linkopts-attr,e2e/workspace/location-expansion,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/root-module-from-single-dependency,e2e/workspace/runfiles-library,e2e/workspace/runfiles-library/dependency,e2e/workspace/runfiles-library/dependency/transitive-dependency,e2e/workspace/simple-binary,e2e/workspace/simple-cmake-library,e2e/workspace/simple-library,e2e/workspace/simple-shared-library,e2e/workspace/simple-test,e2e/workspace/test-runner-attr,e2e/workspace/toolchain-glibc-version,e2e/workspace/transitive-zig-modules-binary,e2e/workspace/transitive-zig-modules-binary/hello-world,e2e/workspace/transitive-zig-modules-binary/hello-world/data,e2e/workspace/transitive-zig-modules-binary/hello-world/data/hello,e2e/workspace/transitive-zig-modules-binary/hello-world/data/world,e2e/workspace/transitive-zig-modules-binary/hello-world/io,e2e/workspace/translate-c/transitive-cc-library-zig-binary,e2e/workspace/zig-docs,e2e/workspace/zig-header,e2e/workspace/zig-module-binary,e2e/workspace/zig-module-binary/data,e2e/workspace/zig-module-binary/io,zig/tests/integration_tests/minimal,zig/tests/integration_tests/mirrors,zig/tests/integration_tests/workspace,zig/tests/integration_tests/workspace/custom_interpreter,zig/tests/integration_tests/workspace/env-attr,zig/tests/integration_tests/workspace/runfiles # Load any settings specific to the current user. # Place settings that should affect the integration tests into `.bazelrc.ic.user`. diff --git a/e2e/workspace/simple-cmake-library/BUILD.bazel b/e2e/workspace/simple-cmake-library/BUILD.bazel index 9d0ac483..8fdc7a62 100644 --- a/e2e/workspace/simple-cmake-library/BUILD.bazel +++ b/e2e/workspace/simple-cmake-library/BUILD.bazel @@ -1,6 +1,5 @@ -load("@rules_zig//zig:defs.bzl", "zig_binary") -load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") +load("@rules_zig//zig:defs.bzl", "zig_binary") # -------------------- # external library using foreign_cc From 318e178cead425da7d1a2ada27d2a20d70b3b0a6 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Tue, 17 Mar 2026 09:15:38 +0100 Subject: [PATCH 6/7] glibc tests only work on Linux --- e2e/workspace/toolchain-glibc-version/BUILD.bazel | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/e2e/workspace/toolchain-glibc-version/BUILD.bazel b/e2e/workspace/toolchain-glibc-version/BUILD.bazel index bd7e5eb3..ff29fa79 100644 --- a/e2e/workspace/toolchain-glibc-version/BUILD.bazel +++ b/e2e/workspace/toolchain-glibc-version/BUILD.bazel @@ -36,6 +36,7 @@ toolchain( zig_binary( name = "main-unconfigured", main = "main.zig", + target_compatible_with = ["@platforms//os:linux"], deps = [ "@rules_zig//zig/lib:libc", ], @@ -46,12 +47,14 @@ zig_configure_binary( actual = ":main-unconfigured", extra_toolchains = [":glibc_2.25_toolchain"], target = ":x86_64-linux-gnu-2.25", + target_compatible_with = ["@platforms//os:linux"], ) zig_test( name = "fallback_glibc.2.17", size = "small", main = "main.zig", + target_compatible_with = ["@platforms//os:linux"], visibility = ["//zig/tests:__pkg__"], deps = [ "@rules_zig//zig/lib:libc", @@ -62,6 +65,7 @@ genrule( name = "main-2.25-glibc-version", outs = ["main-2.25-glibc-version.actual"], cmd = "$(execpath :main-2.25) |& grep compile-time > $(OUTS)", + target_compatible_with = ["@platforms//os:linux"], tools = [":main-2.25"], ) @@ -70,4 +74,5 @@ diff_test( size = "small", file1 = ":main-2.25-glibc-version.expected", file2 = ":main-2.25-glibc-version.actual", + target_compatible_with = ["@platforms//os:linux"], ) From 18de50e3bb3beb9a9da0cc04e89b06b57f9a7289 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Tue, 17 Mar 2026 10:09:24 +0100 Subject: [PATCH 7/7] cmake example - MacOS support --- e2e/workspace/simple-cmake-library/BUILD.bazel | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/e2e/workspace/simple-cmake-library/BUILD.bazel b/e2e/workspace/simple-cmake-library/BUILD.bazel index 8fdc7a62..81f50084 100644 --- a/e2e/workspace/simple-cmake-library/BUILD.bazel +++ b/e2e/workspace/simple-cmake-library/BUILD.bazel @@ -12,7 +12,10 @@ cmake( name = "c-hello", lib_source = ":c-hello-srcs", out_include_dir = "hello", - out_shared_libs = ["libhello.so"], + out_shared_libs = select({ + "@platforms//os:macos": ["libhello.dylib"], + "//conditions:default": ["libhello.so"], + }), ) # -------------------- # equivalent implementation with cc_rules