aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorVexu <git@vexu.eu>2020-12-02 14:05:56 +0200
committerAndrew Kelley <andrew@ziglang.org>2020-12-02 16:33:27 -0800
commitd4c167f3cd09533995aa66109b86a1a28cd21c18 (patch)
tree15befbcab967588c39cbafd6800d1cd024513488 /lib/std
parent41387e1822d5eff75ec88681c14e1f0c7f181af5 (diff)
downloadzig-d4c167f3cd09533995aa66109b86a1a28cd21c18.tar.gz
zig-d4c167f3cd09533995aa66109b86a1a28cd21c18.zip
std.build: addBuildOption special handling for SemanticVersion
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/build.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig
index 4475241cb8..d820ec639b 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -1808,6 +1808,29 @@ pub const LibExeObjStep = struct {
}
return;
},
+ std.SemanticVersion => {
+ out.print(
+ \\pub const {z}: @import("std").SemanticVersion = .{{
+ \\ .major = {d},
+ \\ .minor = {d},
+ \\ .patch = {d},
+ \\
+ , .{
+ name,
+
+ value.major,
+ value.minor,
+ value.patch,
+ }) catch unreachable;
+ if (value.pre) |some| {
+ out.print(" .pre = \"{Z}\",\n", .{some}) catch unreachable;
+ }
+ if (value.build) |some| {
+ out.print(" .build = \"{Z}\",\n", .{some}) catch unreachable;
+ }
+ out.writeAll("};\n") catch unreachable;
+ return;
+ },
else => {},
}
switch (@typeInfo(T)) {
@@ -2774,12 +2797,20 @@ test "LibExeObjStep.addBuildOption" {
exe.addBuildOption(?usize, "option2", null);
exe.addBuildOption([]const u8, "string", "zigisthebest");
exe.addBuildOption(?[]const u8, "optional_string", null);
+ exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
std.testing.expectEqualStrings(
\\pub const option1: usize = 1;
\\pub const option2: ?usize = null;
\\pub const string: []const u8 = "zigisthebest";
\\pub const optional_string: ?[]const u8 = null;
+ \\pub const semantic_version: @import("std").SemanticVersion = .{
+ \\ .major = 0,
+ \\ .minor = 1,
+ \\ .patch = 2,
+ \\ .pre = "foo",
+ \\ .build = "bar",
+ \\};
\\
, exe.build_options_contents.items);
}