| author | |
| committer | |
| log | ca57115da7c4603dbcefce1dc9395617e28a86f8 |
| tree | 04a179eddd93b043e65cf3db5eb2fea955e739a2 |
| parent | 2c1a349fb9bc9965e309257262665564cff64a79 |
4 files changed, 39 insertions(+), 4 deletions(-)
lib/std/Build.zig+7| ... | ... | @@ -450,6 +450,13 @@ fn addUserInputOptionFromArg( |
| 450 | 450 | .used = false, |
| 451 | 451 | }) catch @panic("OOM"); |
| 452 | 452 | }, |
| 453 | std.zig.BuildId => return if (maybe_value) |v| { | |
| 454 | map.put(field.name, .{ | |
| 455 | .name = field.name, | |
| 456 | .value = .{ .scalar = std.fmt.allocPrint(arena, "{f}", .{v}) catch @panic("OOM") }, | |
| 457 | .used = false, | |
| 458 | }) catch @panic("OOM"); | |
| 459 | }, | |
| 453 | 460 | LazyPath => return if (maybe_value) |v| { |
| 454 | 461 | map.put(field.name, .{ |
| 455 | 462 | .name = field.name, |
lib/std/zig.zig+21| ... | ... | @@ -321,6 +321,27 @@ pub const BuildId = union(enum) { |
| 321 | 321 | try std.testing.expectError(error.InvalidCharacter, parse("0xfoobbb")); |
| 322 | 322 | try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx")); |
| 323 | 323 | } |
| 324 | ||
| 325 | pub fn format(id: BuildId, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 326 | switch (id) { | |
| 327 | .none, .fast, .uuid, .sha1, .md5 => { | |
| 328 | try writer.writeAll(@tagName(id)); | |
| 329 | }, | |
| 330 | .hexstring => |hs| { | |
| 331 | try writer.print("0x{x}", .{hs.toSlice()}); | |
| 332 | }, | |
| 333 | } | |
| 334 | } | |
| 335 | ||
| 336 | test format { | |
| 337 | try std.testing.expectFmt("none", "{f}", .{@as(BuildId, .none)}); | |
| 338 | try std.testing.expectFmt("fast", "{f}", .{@as(BuildId, .fast)}); | |
| 339 | try std.testing.expectFmt("uuid", "{f}", .{@as(BuildId, .uuid)}); | |
| 340 | try std.testing.expectFmt("sha1", "{f}", .{@as(BuildId, .sha1)}); | |
| 341 | try std.testing.expectFmt("md5", "{f}", .{@as(BuildId, .md5)}); | |
| 342 | try std.testing.expectFmt("0x", "{f}", .{BuildId.initHexString("")}); | |
| 343 | try std.testing.expectFmt("0x1234cdef", "{f}", .{BuildId.initHexString("\x12\x34\xcd\xef")}); | |
| 344 | } | |
| 324 | 345 | }; |
| 325 | 346 | |
| 326 | 347 | pub const LtoMode = enum { none, full, thin }; |
test/standalone/dependency_options/build.zig+8-4| ... | ... | @@ -51,7 +51,8 @@ pub fn build(b: *std.Build) !void { |
| 51 | 51 | }), |
| 52 | 52 | .@"enum" = @as(Enum, .alfa), |
| 53 | 53 | .enum_list = @as([]const Enum, &.{ .alfa, .bravo, .charlie }), |
| 54 | //.build_id = @as(std.zig.BuildId, .uuid), | |
| 54 | .build_id = @as(std.zig.BuildId, .uuid), | |
| 55 | .hex_build_id = std.zig.BuildId.initHexString("\x12\x34\xcd\xef"), | |
| 55 | 56 | }); |
| 56 | 57 | |
| 57 | 58 | const all_specified_mod = all_specified.module("dummy"); |
| ... | ... | @@ -76,7 +77,8 @@ pub fn build(b: *std.Build) !void { |
| 76 | 77 | }), |
| 77 | 78 | .@"enum" = @as(?Enum, .alfa), |
| 78 | 79 | .enum_list = @as(?[]const Enum, &.{ .alfa, .bravo, .charlie }), |
| 79 | //.build_id = @as(?std.zig.BuildId, .uuid), | |
| 80 | .build_id = @as(?std.zig.BuildId, .uuid), | |
| 81 | .hex_build_id = @as(?std.zig.BuildId, .initHexString("\x12\x34\xcd\xef")), | |
| 80 | 82 | }); |
| 81 | 83 | |
| 82 | 84 | if (all_specified_optional != all_specified) return error.TestFailed; |
| ... | ... | @@ -97,7 +99,8 @@ pub fn build(b: *std.Build) !void { |
| 97 | 99 | }, |
| 98 | 100 | .@"enum" = .alfa, |
| 99 | 101 | .enum_list = &[_]Enum{ .alfa, .bravo, .charlie }, |
| 100 | //.build_id = @as(std.zig.BuildId, .uuid), | |
| 102 | .build_id = .uuid, | |
| 103 | .hex_build_id = std.zig.BuildId.initHexString("\x12\x34\xcd\xef"), | |
| 101 | 104 | }); |
| 102 | 105 | |
| 103 | 106 | if (all_specified_literal != all_specified) return error.TestFailed; |
| ... | ... | @@ -130,7 +133,8 @@ pub fn build(b: *std.Build) !void { |
| 130 | 133 | .lazy_path_list = mut_lazy_path_list, |
| 131 | 134 | .@"enum" = "alfa", |
| 132 | 135 | .enum_list = mut_enum_list, |
| 133 | //.build_id = @as(std.zig.BuildId, .uuid), | |
| 136 | .build_id = "uuid", | |
| 137 | .hex_build_id = "0x1234cdef", | |
| 134 | 138 | }); |
| 135 | 139 | |
| 136 | 140 | if (all_specified_alt != all_specified) return error.TestFailed; |
test/standalone/dependency_options/other/build.zig+3| ... | ... | @@ -20,6 +20,7 @@ pub fn build(b: *std.Build) !void { |
| 20 | 20 | const expected_enum: Enum = .alfa; |
| 21 | 21 | const expected_enum_list: []const Enum = &.{ .alfa, .bravo, .charlie }; |
| 22 | 22 | const expected_build_id: std.zig.BuildId = .uuid; |
| 23 | const expected_hex_build_id: std.zig.BuildId = .initHexString("\x12\x34\xcd\xef"); | |
| 23 | 24 | |
| 24 | 25 | const @"bool" = b.option(bool, "bool", "bool") orelse expected_bool; |
| 25 | 26 | const int = b.option(i64, "int", "int") orelse expected_int; |
| ... | ... | @@ -31,6 +32,7 @@ pub fn build(b: *std.Build) !void { |
| 31 | 32 | const @"enum" = b.option(Enum, "enum", "enum") orelse expected_enum; |
| 32 | 33 | const enum_list = b.option([]const Enum, "enum_list", "enum_list") orelse expected_enum_list; |
| 33 | 34 | const build_id = b.option(std.zig.BuildId, "build_id", "build_id") orelse expected_build_id; |
| 35 | const hex_build_id = b.option(std.zig.BuildId, "hex_build_id", "hex_build_id") orelse expected_hex_build_id; | |
| 34 | 36 | |
| 35 | 37 | if (@"bool" != expected_bool) return error.TestFailed; |
| 36 | 38 | if (int != expected_int) return error.TestFailed; |
| ... | ... | @@ -47,6 +49,7 @@ pub fn build(b: *std.Build) !void { |
| 47 | 49 | if (@"enum" != expected_enum) return error.TestFailed; |
| 48 | 50 | if (!std.mem.eql(Enum, enum_list, expected_enum_list)) return error.TestFailed; |
| 49 | 51 | if (!std.meta.eql(build_id, expected_build_id)) return error.TestFailed; |
| 52 | if (!hex_build_id.eql(expected_hex_build_id)) return error.TestFailed; | |
| 50 | 53 | |
| 51 | 54 | _ = b.addModule("dummy", .{ |
| 52 | 55 | .root_source_file = b.path("build.zig"), |