Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update Zig versions to 0.11.0 #108

Merged
merged 14 commits into from
Nov 25, 2023
Merged
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.6")

zig = use_extension("//zig:extensions.bzl", "zig")
zig.toolchain(zig_version = "0.10.1")
zig.toolchain(zig_version = "0.11.0")
use_repo(zig, "zig_toolchains")

register_toolchains("@rules_zig//zig/target:all")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ rules_zig_dependencies()

zig_register_toolchains(
name = "zig",
zig_version = "0.10.1",
zig_version = "0.11.0",
)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md

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

2 changes: 1 addition & 1 deletion e2e/workspace/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ rules_zig_dependencies()

zig_register_toolchains(
name = "zig",
zig_version = "0.10.1",
zig_version = "0.11.0",
)
2 changes: 1 addition & 1 deletion e2e/workspace/configure-mode/binary.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ const builtin = @import("builtin");
pub fn main() void {
std.io.getStdOut().writer().print(
"{s}\n",
.{std.meta.tagName(builtin.mode)},
.{@tagName(builtin.mode)},
) catch unreachable;
}
11 changes: 1 addition & 10 deletions e2e/workspace/configure-target/read_pe32_arch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ pub fn main() !void {
fn printMachineType(allocator: std.mem.Allocator, binary_path: []const u8) !void {
const content = try std.fs.cwd().readFileAlloc(allocator, binary_path, 1048576);

var coff = std.coff.Coff{ .allocator = allocator };
defer coff.deinit();

{
// coff.parse takes ownership of the data,
// but does not free on error during parsing itself.
// Note, this will be fixed in Zig 0.11.
errdefer allocator.free(content);
try coff.parse(content);
}
var coff = try std.coff.Coff.init(content);

try std.io.getStdOut().writer().print("{s}\n", .{@tagName(coff.getCoffHeader().machine)});
}
2 changes: 1 addition & 1 deletion e2e/workspace/zig_version.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.1
0.11.0
2 changes: 2 additions & 0 deletions util/update_zig_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
_ZIG_INDEX_URL = "https://ziglang.org/download/index.json"

_UNSUPPORTED_VERSIONS = [
"0.10.1",
"0.10.0",
"0.9.1",
"0.9.0",
"0.8.1",
Expand Down
10 changes: 9 additions & 1 deletion zig/private/providers/zig_package_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ FIELDS = {
"main": "File, The main source file of the package.",
"srcs": "list of File, Other Zig source files that belong to the package.",
"flags": "list of string, Zig compiler flags requried when depending on the package.",
"all_mods": "depset of string, All module CLI specifications required when depending on the package.",
"all_srcs": "depset of File, All source files required when depending on the package.",
}

Expand All @@ -31,9 +32,16 @@ def zig_package_dependencies(*, deps, inputs, args):
inputs: List of depset of File; mutable, Append the needed inputs to this list.
args: Args; mutable, Append the needed Zig compiler flags to this object.
"""
mods = []
names = []

for dep in deps:
if not ZigPackageInfo in dep:
continue
package = dep[ZigPackageInfo]
names.append(package.name)
mods.append(package.all_mods)
inputs.append(package.all_srcs)
args.add_all(package.flags)

args.add_all(depset(transitive = mods), before_each = "--mod")
args.add_joined("--deps", names, join_with = ",")
56 changes: 19 additions & 37 deletions zig/private/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,38 @@ Generated from https://ziglang.org/download/index.json.
"""

TOOL_VERSIONS = {
"0.10.1": {
"0.11.0": {
"aarch64-linux": struct(
url = "https://ziglang.org/download/0.10.1/zig-linux-aarch64-0.10.1.tar.xz",
integrity = "sha256-2wdhZk9fIqpbvXRCoWF91pbAdtVxfd78ydi5Unj3H10=",
url = "https://ziglang.org/download/0.11.0/zig-linux-aarch64-0.11.0.tar.xz",
integrity = "sha256-lW6wldi6RKxuvSf3yZVuR9kpN8EDv3VHRdCjnNql1MY=",
),
"aarch64-macos": struct(
url = "https://ziglang.org/download/0.10.1/zig-macos-aarch64-0.10.1.tar.xz",
integrity = "sha256-ubAEd+xfofG4nzWn0qWGiOAZkQq4CmXqwqdBcWJzdlY=",
url = "https://ziglang.org/download/0.11.0/zig-macos-aarch64-0.11.0.tar.xz",
integrity = "sha256-xuv5J7sTpwfXQmdHSp9VMnTmSQb9Ib8cdaIL3oyt97I=",
),
"aarch64-windows": struct(
url = "https://ziglang.org/download/0.10.1/zig-windows-aarch64-0.10.1.zip",
integrity = "sha256-7Ok7DXeyqwPEDbme98y8Y+C2vWWK8SuXiYlg9iEwVCg=",
url = "https://ziglang.org/download/0.11.0/zig-windows-aarch64-0.11.0.zip",
integrity = "sha256-XUvRPbXssN3HSSMeAPElwdMQh9cI6f+bRcT04T5IxmE=",
),
"x86_64-linux": struct(
url = "https://ziglang.org/download/0.10.1/zig-linux-x86_64-0.10.1.tar.xz",
integrity = "sha256-Zpnw5ykwgbQkKPMsnZyYOFQJS9Ff7lSJ8SxM9FGMw4A=",
),
"x86_64-macos": struct(
url = "https://ziglang.org/download/0.10.1/zig-macos-x86_64-0.10.1.tar.xz",
integrity = "sha256-Akg1ULidKjBwwu0AM1f9bmowWXB7juP7wMZ/g8qJhDc=",
"x86-linux": struct(
url = "https://ziglang.org/download/0.11.0/zig-linux-x86-0.11.0.tar.xz",
integrity = "sha256-ew3D4OBwrg4NIkCxiSr2ofn6rDUWyuJOV/eg57BGYqg=",
),
"x86_64-windows": struct(
url = "https://ziglang.org/download/0.10.1/zig-windows-x86_64-0.10.1.zip",
integrity = "sha256-V2gATl4nTHlpw4kuiRWW5Rxd8rQi15iGVHHgUEmYgSU=",
),
},
"0.10.0": {
"aarch64-linux": struct(
url = "https://ziglang.org/download/0.10.0/zig-linux-aarch64-0.10.0.tar.xz",
integrity = "sha256-Ce9QyL5zOAeZgEFpGXgg7nh2ByOwQw+oI/Vu1CsG6g8=",
),
"aarch64-macos": struct(
url = "https://ziglang.org/download/0.10.0/zig-macos-aarch64-0.10.0.tar.xz",
integrity = "sha256-Aveng5tqHhJ+6uIupyyHYD+3KYxYvDWCKpUUedU8dVc=",
),
"aarch64-windows": struct(
url = "https://ziglang.org/download/0.10.0/zig-windows-aarch64-0.10.0.zip",
integrity = "sha256-G72o0SPUTzrk+pDQ2gSx6Qk8P53a40KaSr7OHhwL8Zo=",
"x86-windows": struct(
url = "https://ziglang.org/download/0.11.0/zig-windows-x86-0.11.0.zip",
integrity = "sha256-5ys2KJfyjGcWM+ZQqgUony5isVTvzKl3CURWyNrDrvo=",
),
"x86_64-linux": struct(
url = "https://ziglang.org/download/0.10.0/zig-linux-x86_64-0.10.0.tar.xz",
integrity = "sha256-Yx7HvLZJzWeVq+QN8ETSRztZtE4QvmicFWMqBFjd6lU=",
url = "https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz",
integrity = "sha256-LQDnif7E9xeQpue/g/+R1WSUPF7oQ8X9lm78R0tCMEc=",
),
"x86_64-macos": struct(
url = "https://ziglang.org/download/0.10.0/zig-macos-x86_64-0.10.0.tar.xz",
integrity = "sha256-OiLLbEdJiEFWqU6ptg86KM9OCYpp8IwY+8qBxzPr/to=",
url = "https://ziglang.org/download/0.11.0/zig-macos-x86_64-0.11.0.tar.xz",
integrity = "sha256-HBxrmpBrQrquc2VuJOEI/YREu1C26P0D6eej+LXwVoY=",
),
"x86_64-windows": struct(
url = "https://ziglang.org/download/0.10.0/zig-windows-x86_64-0.10.0.zip",
integrity = "sha256-pm4v9VXG5IeB3hvLBmLvKO5LiK868qV397GVDkMIl+4=",
url = "https://ziglang.org/download/0.11.0/zig-windows-x86_64-0.11.0.zip",
integrity = "sha256-FCyqO4BNhrR1JVbJtrA5t1F6CK+jr4QmRcfi3NEl9lI=",
),
},
}
22 changes: 13 additions & 9 deletions zig/private/zig_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ ATTRS = {
mandatory = False,
),
"deps": attr.label_list(
doc = """\
Other packages required when building the package.

Note, the Zig compiler requires that every package dependency is specified with
its own package dependencies on the command-line, recursively. Meaning the
entire Zig package dependency tree will be represented on the command-line
without deduplication of shared nodes. Keep this in mind when you defined the
granularity of your Zig packages.
""",
doc = "Other packages required when building the package.",
mandatory = False,
providers = [ZigPackageInfo],
),
Expand Down Expand Up @@ -90,12 +82,16 @@ def _zig_package_impl(ctx):

srcs = [ctx.file.main] + ctx.files.srcs + ctx.files.extra_srcs
flags = ["--pkg-begin", ctx.label.name, ctx.file.main.path]
dep_names = []
all_mods = []
all_srcs = []

for dep in ctx.attr.deps:
if ZigPackageInfo in dep:
package = dep[ZigPackageInfo]
flags.extend(package.flags)
dep_names.append(package.name)
all_mods.append(package.all_mods)
all_srcs.append(package.all_srcs)

flags.append("--pkg-end")
Expand All @@ -105,6 +101,14 @@ def _zig_package_impl(ctx):
main = ctx.file.main,
srcs = ctx.files.srcs,
flags = flags,
all_mods = depset(
direct = ["{name}:{deps}:{src}".format(
name = ctx.label.name,
deps = ",".join(dep_names),
src = ctx.file.main.path,
)],
transitive = all_mods,
),
all_srcs = depset(
direct = srcs,
transitive = all_srcs,
Expand Down
2 changes: 1 addition & 1 deletion zig/tests/integration_tests/integration_testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub const BitContext = struct {
var argv = try std.testing.allocator.alloc([]const u8, argc);
defer std.testing.allocator.free(argv);
argv[0] = self.bazel_path;
for (args.argv) |arg, i| {
for (args.argv, 0..) |arg, i| {
argv[i + 1] = arg;
}
if (self.bzlmod_enabled and !args.omit_bzlmod_flag) {
Expand Down
59 changes: 50 additions & 9 deletions zig/tests/integration_tests/integration_tests_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,7 @@ test "can compile to target platform aarch64-linux" {
try std.testing.expectEqual(std.elf.EM.AARCH64, elf_header.machine);
}

test "zig_binary result should not contain the output base path" {
if (builtin.os.tag == .macos) {
// TODO[AH] Avoid output base path on MacOS.
// See https://github.com/aherrmann/rules_zig/issues/79
return error.SkipZigTest;
}

fn testBinaryShouldNotContainOutputBase(mode: []const u8) !void {
const ctx = try BitContext.init();

const info_result = try ctx.exec_bazel(.{
Expand All @@ -135,8 +129,15 @@ test "zig_binary result should not contain the output base path" {

const output_base = std.mem.trim(u8, info_result.stdout, " \n");

const mode_flag = try std.fmt.allocPrint(
std.testing.allocator,
"--@rules_zig//zig/settings:mode={s}",
.{mode},
);
defer std.testing.allocator.free(mode_flag);

const result = try ctx.exec_bazel(.{
.argv = &[_][]const u8{ "build", "//:binary", "--@rules_zig//zig/settings:mode=debug" },
.argv = &[_][]const u8{ "build", "//:binary", mode_flag },
});
defer result.deinit();

Expand All @@ -148,7 +149,7 @@ test "zig_binary result should not contain the output base path" {
const file = try workspace.openFile("bazel-bin/binary", .{});
defer file.close();

const file_content = try file.readToEndAlloc(std.testing.allocator, 1_000_000);
const file_content = try file.readToEndAlloc(std.testing.allocator, 64_000_000);
defer std.testing.allocator.free(file_content);

if (std.mem.indexOf(u8, file_content, output_base)) |start| {
Expand All @@ -158,3 +159,43 @@ test "zig_binary result should not contain the output base path" {
return error.TestExpectNotFound;
}
}

test "zig_binary result should not contain the output base path in debug mode" {
if (true) {
// TODO[AH] Avoid output base path in debug mode.
// See https://github.com/aherrmann/rules_zig/issues/79
return error.SkipZigTest;
}

try testBinaryShouldNotContainOutputBase("debug");
}

test "zig_binary result should not contain the output base path in release_safe mode" {
if (true) {
// TODO[AH] Avoid output base path in release_safe mode.
// See https://github.com/aherrmann/rules_zig/issues/79
return error.SkipZigTest;
}

try testBinaryShouldNotContainOutputBase("release_safe");
}

test "zig_binary result should not contain the output base path in release_fast mode" {
if (builtin.os.tag == .macos) {
// TODO[AH] Avoid output base path on MacOS.
// See https://github.com/aherrmann/rules_zig/issues/79
return error.SkipZigTest;
}

try testBinaryShouldNotContainOutputBase("release_small");
}

test "zig_binary result should not contain the output base path in release_small mode" {
if (true) {
// TODO[AH] Avoid output base path in release_small mode.
// See https://github.com/aherrmann/rules_zig/issues/79
return error.SkipZigTest;
}

try testBinaryShouldNotContainOutputBase("release_fast");
}
2 changes: 1 addition & 1 deletion zig/tests/integration_tests/workspace/print_build_mode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const builtin = @import("builtin");

pub fn main() void {
std.io.getStdOut().writeAll(
std.meta.tagName(builtin.mode),
@tagName(builtin.mode),
) catch unreachable;
}
Loading