-zig_configure(name, actual, mode, threaded) +zig_configure(name, actual, mode, target, threaded)@@ -42,6 +42,7 @@ zig_configure(name, name | A unique name for this target. | Name | required | | | actual | The target to transition. | Label | required | | | mode | The build mode setting | String | optional |
"" |
+| target | The target platform | Label | optional | None |
| threaded | The threaded setting | String | optional | "" |
@@ -50,7 +51,7 @@ zig_configure(name, name, actual, mode, threaded)
+zig_configure_binary(name, actual, mode, target, threaded)
@@ -63,6 +64,7 @@ zig_configure_binary(name, name | A unique name for this target. | Name | required | |
| actual | The target to transition. | Label | required | |
| mode | The build mode setting | String | optional | "" |
+| target | The target platform | Label | optional | None |
| threaded | The threaded setting | String | optional | "" |
@@ -71,7 +73,7 @@ zig_configure_binary(name, name, actual, mode, threaded)
+zig_configure_test(name, actual, mode, target, threaded)
@@ -84,6 +86,7 @@ zig_configure_test(name, name | A unique name for this target. | Name | required | |
| actual | The target to transition. | Label | required | |
| mode | The build mode setting | String | optional | "" |
+| target | The target platform | Label | optional | None |
| threaded | The threaded setting | String | optional | "" |
diff --git a/e2e/workspace/configure-target/BUILD.bazel b/e2e/workspace/configure-target/BUILD.bazel
new file mode 100644
index 00000000..282c897a
--- /dev/null
+++ b/e2e/workspace/configure-target/BUILD.bazel
@@ -0,0 +1,104 @@
+load("@bazel_skylib//rules:build_test.bzl", "build_test")
+load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
+load(
+ "@rules_zig//zig:defs.bzl",
+ "zig_binary",
+ "zig_configure_binary",
+ "zig_configure_test",
+ "zig_test",
+)
+
+platform(
+ name = "aarch64-linux",
+ constraint_values = [
+ "@platforms//os:linux",
+ "@platforms//cpu:aarch64",
+ ],
+)
+
+zig_binary(
+ name = "read_elf_arch",
+ main = "read_elf_arch.zig",
+)
+
+# TODO[AH] Test target transition on zig_library.
+# Open question: how to extract the target platform from .a file?
+
+# ----------------------------------------------------------
+# zig_configure_binary
+
+zig_binary(
+ name = "binary",
+ main = "main.zig",
+ tags = ["manual"],
+)
+
+zig_configure_binary(
+ name = "binary_aarch64-linux",
+ actual = ":binary",
+ tags = ["manual"],
+ target = ":aarch64-linux",
+)
+
+build_test(
+ name = "binary_aarch64-linux_build_test",
+ targets = [
+ ":binary_aarch64-linux",
+ ],
+)
+
+genrule(
+ name = "binary_aarch64-linux_arch",
+ srcs = [":binary_aarch64-linux"],
+ outs = ["binary_aarch64-linux_arch.actual"],
+ cmd = "$(execpath :read_elf_arch) $(SRCS) > $(OUTS)",
+ tools = [":read_elf_arch"],
+)
+
+diff_test(
+ name = "binary_aarch64-linux_arch_test",
+ file1 = ":binary_aarch64-linux_arch.expected",
+ file2 = ":binary_aarch64-linux_arch.actual",
+)
+
+# TODO[AH] Test another operating system
+
+# ----------------------------------------------------------
+# zig_configure_test
+
+zig_test(
+ name = "test",
+ main = "main.zig",
+ tags = ["manual"],
+)
+
+zig_configure_test(
+ name = "test_aarch64-linux",
+ actual = ":test",
+ tags = ["manual"],
+ target = ":aarch64-linux",
+)
+
+build_test(
+ name = "test_aarch64-linux_build_test",
+ targets = [
+ ":test_aarch64-linux",
+ ],
+)
+
+genrule(
+ name = "test_aarch64-linux_arch",
+ testonly = True,
+ srcs = [":test_aarch64-linux"],
+ outs = ["test_aarch64-linux_arch.actual"],
+ cmd = "$(execpath :read_elf_arch) $(SRCS) > $(OUTS)",
+ tools = [":read_elf_arch"],
+)
+
+diff_test(
+ name = "test_aarch64-linux_arch_test",
+ file1 = ":test_aarch64-linux_arch.expected",
+ file2 = ":test_aarch64-linux_arch.actual",
+)
+
+# TODO[AH] Test another operating system
diff --git a/e2e/workspace/configure-target/binary_aarch64-linux_arch.expected b/e2e/workspace/configure-target/binary_aarch64-linux_arch.expected
new file mode 100644
index 00000000..0a30acdc
--- /dev/null
+++ b/e2e/workspace/configure-target/binary_aarch64-linux_arch.expected
@@ -0,0 +1 @@
+AARCH64
diff --git a/e2e/workspace/configure-target/main.zig b/e2e/workspace/configure-target/main.zig
new file mode 100644
index 00000000..7421521b
--- /dev/null
+++ b/e2e/workspace/configure-target/main.zig
@@ -0,0 +1,5 @@
+const std = @import("std");
+
+pub fn main() !void {
+ try std.io.getStdOut().writer().print("Hello world!\n", .{});
+}
diff --git a/e2e/workspace/configure-target/read_elf_arch.zig b/e2e/workspace/configure-target/read_elf_arch.zig
new file mode 100644
index 00000000..53f702ad
--- /dev/null
+++ b/e2e/workspace/configure-target/read_elf_arch.zig
@@ -0,0 +1,23 @@
+const std = @import("std");
+const elf = std.elf;
+
+pub fn main() !void {
+ var args = try std.process.argsAlloc(std.heap.page_allocator);
+ defer std.process.argsFree(std.heap.page_allocator, args);
+
+ if (args.len < 2) {
+ try std.io.getStdErr().writer().print("Usage: {s}