Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import %workspace%/.bazelrc.flags
# Deleted packages for integration tests.
# To update these lines, execute
# `bazel run @contrib_rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=e2e/workspace,e2e/workspace/configure-mode,e2e/workspace/configure-threaded,e2e/workspace/linker-script,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/simple-binary,e2e/workspace/simple-library,e2e/workspace/simple-test,e2e/workspace/transitive-zig-packages-binary,e2e/workspace/transitive-zig-packages-binary/hello-world,e2e/workspace/transitive-zig-packages-binary/hello-world/data,e2e/workspace/transitive-zig-packages-binary/hello-world/data/hello,e2e/workspace/transitive-zig-packages-binary/hello-world/data/world,e2e/workspace/transitive-zig-packages-binary/hello-world/io,e2e/workspace/zig-package-binary,e2e/workspace/zig-package-binary/data,e2e/workspace/zig-package-binary/io,zig/tests/integration_tests/workspace
query --deleted_packages=e2e/workspace,e2e/workspace/configure-mode,e2e/workspace/configure-threaded,e2e/workspace/linker-script,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/simple-binary,e2e/workspace/simple-library,e2e/workspace/simple-test,e2e/workspace/transitive-zig-packages-binary,e2e/workspace/transitive-zig-packages-binary/hello-world,e2e/workspace/transitive-zig-packages-binary/hello-world/data,e2e/workspace/transitive-zig-packages-binary/hello-world/data/hello,e2e/workspace/transitive-zig-packages-binary/hello-world/data/world,e2e/workspace/transitive-zig-packages-binary/hello-world/io,e2e/workspace/zig-package-binary,e2e/workspace/zig-package-binary/data,e2e/workspace/zig-package-binary/io,zig/tests/integration_tests/workspace
build --deleted_packages=e2e/workspace,e2e/workspace/configure-mode,e2e/workspace/configure-target,e2e/workspace/configure-threaded,e2e/workspace/linker-script,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/simple-binary,e2e/workspace/simple-library,e2e/workspace/simple-test,e2e/workspace/transitive-zig-packages-binary,e2e/workspace/transitive-zig-packages-binary/hello-world,e2e/workspace/transitive-zig-packages-binary/hello-world/data,e2e/workspace/transitive-zig-packages-binary/hello-world/data/hello,e2e/workspace/transitive-zig-packages-binary/hello-world/data/world,e2e/workspace/transitive-zig-packages-binary/hello-world/io,e2e/workspace/zig-package-binary,e2e/workspace/zig-package-binary/data,e2e/workspace/zig-package-binary/io,zig/tests/integration_tests/workspace
query --deleted_packages=e2e/workspace,e2e/workspace/configure-mode,e2e/workspace/configure-target,e2e/workspace/configure-threaded,e2e/workspace/linker-script,e2e/workspace/multiple-sources-and-packages-test,e2e/workspace/multiple-sources-binary,e2e/workspace/simple-binary,e2e/workspace/simple-library,e2e/workspace/simple-test,e2e/workspace/transitive-zig-packages-binary,e2e/workspace/transitive-zig-packages-binary/hello-world,e2e/workspace/transitive-zig-packages-binary/hello-world/data,e2e/workspace/transitive-zig-packages-binary/hello-world/data/hello,e2e/workspace/transitive-zig-packages-binary/hello-world/data/world,e2e/workspace/transitive-zig-packages-binary/hello-world/io,e2e/workspace/zig-package-binary,e2e/workspace/zig-package-binary/data,e2e/workspace/zig-package-binary/io,zig/tests/integration_tests/workspace

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
Expand Down
9 changes: 6 additions & 3 deletions docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions e2e/workspace/configure-target/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AARCH64
5 changes: 5 additions & 0 deletions e2e/workspace/configure-target/main.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const std = @import("std");

pub fn main() !void {
try std.io.getStdOut().writer().print("Hello world!\n", .{});
}
23 changes: 23 additions & 0 deletions e2e/workspace/configure-target/read_elf_arch.zig
Original file line number Diff line number Diff line change
@@ -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} <binary_path>\n", .{args[0]});
return;
}

try printMachineType(args[1]);
}

fn printMachineType(binary_path: []const u8) !void {
const file = try std.fs.cwd().openFile(binary_path, .{});
defer file.close();

const elf_header = try elf.Header.read(file);

try std.io.getStdOut().writer().print("{s}\n", .{@tagName(elf_header.machine)});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AARCH64
8 changes: 8 additions & 0 deletions zig/private/zig_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ DOC = """\

def _zig_transition_impl(settings, attr):
result = dict(settings)
if attr.target:
result["//command_line_option:platforms"] = str(attr.target)
if attr.mode:
result["//zig/settings:mode"] = attr.mode
if attr.threaded:
Expand All @@ -17,10 +19,12 @@ def _zig_transition_impl(settings, attr):
_zig_transition = transition(
implementation = _zig_transition_impl,
inputs = [
"//command_line_option:platforms",
"//zig/settings:mode",
"//zig/settings:threaded",
],
outputs = [
"//command_line_option:platforms",
"//zig/settings:mode",
"//zig/settings:threaded",
],
Expand All @@ -34,6 +38,10 @@ def _make_attrs(*, executable, test):
executable = executable,
mandatory = True,
),
"target": attr.label(
doc = "The target platform",
mandatory = False,
),
"mode": attr.string(
doc = "The build mode setting",
mandatory = False,
Expand Down