authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-12-02 14:05:56+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-02 16:33:27-08:00
logd4c167f3cd09533995aa66109b86a1a28cd21c18
tree15befbcab967588c39cbafd6800d1cd024513488
parent41387e1822d5eff75ec88681c14e1f0c7f181af5

std.build: addBuildOption special handling for SemanticVersion


1 files changed, 31 insertions(+), 0 deletions(-)

lib/std/build.zig+31
......@@ -1808,6 +1808,29 @@ pub const LibExeObjStep = struct {
18081808 }
18091809 return;
18101810 },
1811 std.SemanticVersion => {
1812 out.print(
1813 \\pub const {z}: @import("std").SemanticVersion = .{{
1814 \\ .major = {d},
1815 \\ .minor = {d},
1816 \\ .patch = {d},
1817 \\
1818 , .{
1819 name,
1820
1821 value.major,
1822 value.minor,
1823 value.patch,
1824 }) catch unreachable;
1825 if (value.pre) |some| {
1826 out.print(" .pre = \"{Z}\",\n", .{some}) catch unreachable;
1827 }
1828 if (value.build) |some| {
1829 out.print(" .build = \"{Z}\",\n", .{some}) catch unreachable;
1830 }
1831 out.writeAll("};\n") catch unreachable;
1832 return;
1833 },
18111834 else => {},
18121835 }
18131836 switch (@typeInfo(T)) {
......@@ -2774,12 +2797,20 @@ test "LibExeObjStep.addBuildOption" {
27742797 exe.addBuildOption(?usize, "option2", null);
27752798 exe.addBuildOption([]const u8, "string", "zigisthebest");
27762799 exe.addBuildOption(?[]const u8, "optional_string", null);
2800 exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
27772801
27782802 std.testing.expectEqualStrings(
27792803 \\pub const option1: usize = 1;
27802804 \\pub const option2: ?usize = null;
27812805 \\pub const string: []const u8 = "zigisthebest";
27822806 \\pub const optional_string: ?[]const u8 = null;
2807 \\pub const semantic_version: @import("std").SemanticVersion = .{
2808 \\ .major = 0,
2809 \\ .minor = 1,
2810 \\ .patch = 2,
2811 \\ .pre = "foo",
2812 \\ .build = "bar",
2813 \\};
27832814 \\
27842815 , exe.build_options_contents.items);
27852816}