mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Support passing std.zig.BuildId to b.dependency()
This commit is contained in:
parent
2c1a349fb9
commit
ca57115da7
4 changed files with 39 additions and 4 deletions
|
|
@ -450,6 +450,13 @@ fn addUserInputOptionFromArg(
|
|||
.used = false,
|
||||
}) catch @panic("OOM");
|
||||
},
|
||||
std.zig.BuildId => return if (maybe_value) |v| {
|
||||
map.put(field.name, .{
|
||||
.name = field.name,
|
||||
.value = .{ .scalar = std.fmt.allocPrint(arena, "{f}", .{v}) catch @panic("OOM") },
|
||||
.used = false,
|
||||
}) catch @panic("OOM");
|
||||
},
|
||||
LazyPath => return if (maybe_value) |v| {
|
||||
map.put(field.name, .{
|
||||
.name = field.name,
|
||||
|
|
|
|||
|
|
@ -321,6 +321,27 @@ pub const BuildId = union(enum) {
|
|||
try std.testing.expectError(error.InvalidCharacter, parse("0xfoobbb"));
|
||||
try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx"));
|
||||
}
|
||||
|
||||
pub fn format(id: BuildId, writer: *std.io.Writer) std.io.Writer.Error!void {
|
||||
switch (id) {
|
||||
.none, .fast, .uuid, .sha1, .md5 => {
|
||||
try writer.writeAll(@tagName(id));
|
||||
},
|
||||
.hexstring => |hs| {
|
||||
try writer.print("0x{x}", .{hs.toSlice()});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
test format {
|
||||
try std.testing.expectFmt("none", "{f}", .{@as(BuildId, .none)});
|
||||
try std.testing.expectFmt("fast", "{f}", .{@as(BuildId, .fast)});
|
||||
try std.testing.expectFmt("uuid", "{f}", .{@as(BuildId, .uuid)});
|
||||
try std.testing.expectFmt("sha1", "{f}", .{@as(BuildId, .sha1)});
|
||||
try std.testing.expectFmt("md5", "{f}", .{@as(BuildId, .md5)});
|
||||
try std.testing.expectFmt("0x", "{f}", .{BuildId.initHexString("")});
|
||||
try std.testing.expectFmt("0x1234cdef", "{f}", .{BuildId.initHexString("\x12\x34\xcd\xef")});
|
||||
}
|
||||
};
|
||||
|
||||
pub const LtoMode = enum { none, full, thin };
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ pub fn build(b: *std.Build) !void {
|
|||
}),
|
||||
.@"enum" = @as(Enum, .alfa),
|
||||
.enum_list = @as([]const Enum, &.{ .alfa, .bravo, .charlie }),
|
||||
//.build_id = @as(std.zig.BuildId, .uuid),
|
||||
.build_id = @as(std.zig.BuildId, .uuid),
|
||||
.hex_build_id = std.zig.BuildId.initHexString("\x12\x34\xcd\xef"),
|
||||
});
|
||||
|
||||
const all_specified_mod = all_specified.module("dummy");
|
||||
|
|
@ -76,7 +77,8 @@ pub fn build(b: *std.Build) !void {
|
|||
}),
|
||||
.@"enum" = @as(?Enum, .alfa),
|
||||
.enum_list = @as(?[]const Enum, &.{ .alfa, .bravo, .charlie }),
|
||||
//.build_id = @as(?std.zig.BuildId, .uuid),
|
||||
.build_id = @as(?std.zig.BuildId, .uuid),
|
||||
.hex_build_id = @as(?std.zig.BuildId, .initHexString("\x12\x34\xcd\xef")),
|
||||
});
|
||||
|
||||
if (all_specified_optional != all_specified) return error.TestFailed;
|
||||
|
|
@ -97,7 +99,8 @@ pub fn build(b: *std.Build) !void {
|
|||
},
|
||||
.@"enum" = .alfa,
|
||||
.enum_list = &[_]Enum{ .alfa, .bravo, .charlie },
|
||||
//.build_id = @as(std.zig.BuildId, .uuid),
|
||||
.build_id = .uuid,
|
||||
.hex_build_id = std.zig.BuildId.initHexString("\x12\x34\xcd\xef"),
|
||||
});
|
||||
|
||||
if (all_specified_literal != all_specified) return error.TestFailed;
|
||||
|
|
@ -130,7 +133,8 @@ pub fn build(b: *std.Build) !void {
|
|||
.lazy_path_list = mut_lazy_path_list,
|
||||
.@"enum" = "alfa",
|
||||
.enum_list = mut_enum_list,
|
||||
//.build_id = @as(std.zig.BuildId, .uuid),
|
||||
.build_id = "uuid",
|
||||
.hex_build_id = "0x1234cdef",
|
||||
});
|
||||
|
||||
if (all_specified_alt != all_specified) return error.TestFailed;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ pub fn build(b: *std.Build) !void {
|
|||
const expected_enum: Enum = .alfa;
|
||||
const expected_enum_list: []const Enum = &.{ .alfa, .bravo, .charlie };
|
||||
const expected_build_id: std.zig.BuildId = .uuid;
|
||||
const expected_hex_build_id: std.zig.BuildId = .initHexString("\x12\x34\xcd\xef");
|
||||
|
||||
const @"bool" = b.option(bool, "bool", "bool") orelse expected_bool;
|
||||
const int = b.option(i64, "int", "int") orelse expected_int;
|
||||
|
|
@ -31,6 +32,7 @@ pub fn build(b: *std.Build) !void {
|
|||
const @"enum" = b.option(Enum, "enum", "enum") orelse expected_enum;
|
||||
const enum_list = b.option([]const Enum, "enum_list", "enum_list") orelse expected_enum_list;
|
||||
const build_id = b.option(std.zig.BuildId, "build_id", "build_id") orelse expected_build_id;
|
||||
const hex_build_id = b.option(std.zig.BuildId, "hex_build_id", "hex_build_id") orelse expected_hex_build_id;
|
||||
|
||||
if (@"bool" != expected_bool) return error.TestFailed;
|
||||
if (int != expected_int) return error.TestFailed;
|
||||
|
|
@ -47,6 +49,7 @@ pub fn build(b: *std.Build) !void {
|
|||
if (@"enum" != expected_enum) return error.TestFailed;
|
||||
if (!std.mem.eql(Enum, enum_list, expected_enum_list)) return error.TestFailed;
|
||||
if (!std.meta.eql(build_id, expected_build_id)) return error.TestFailed;
|
||||
if (!hex_build_id.eql(expected_hex_build_id)) return error.TestFailed;
|
||||
|
||||
_ = b.addModule("dummy", .{
|
||||
.root_source_file = b.path("build.zig"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue