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 17:54:29-07:00
log401d091fb4c96fd1b63228476d8060705888c386
treeca4fda8a67934448cf3f4564ff5cd5841ca60389
parentb1f52ca7f25c26831abd5e7115c33e8b2433ab8f

std.build: addBuildOption special handling for SemanticVersion


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

lib/std/build.zig+31
...@@ -1805,6 +1805,29 @@ pub const LibExeObjStep = struct {...@@ -1805,6 +1805,29 @@ pub const LibExeObjStep = struct {
1805 }1805 }
1806 return;1806 return;
1807 },1807 },
1808 std.SemanticVersion => {
1809 out.print(
1810 \\pub const {z}: @import("std").SemanticVersion = .{{
1811 \\ .major = {d},
1812 \\ .minor = {d},
1813 \\ .patch = {d},
1814 \\
1815 , .{
1816 name,
1817
1818 value.major,
1819 value.minor,
1820 value.patch,
1821 }) catch unreachable;
1822 if (value.pre) |some| {
1823 out.print(" .pre = \"{Z}\",\n", .{some}) catch unreachable;
1824 }
1825 if (value.build) |some| {
1826 out.print(" .build = \"{Z}\",\n", .{some}) catch unreachable;
1827 }
1828 out.writeAll("};\n") catch unreachable;
1829 return;
1830 },
1808 else => {},1831 else => {},
1809 }1832 }
1810 switch (@typeInfo(T)) {1833 switch (@typeInfo(T)) {
...@@ -2763,12 +2786,20 @@ test "LibExeObjStep.addBuildOption" {...@@ -2763,12 +2786,20 @@ test "LibExeObjStep.addBuildOption" {
2763 exe.addBuildOption(?usize, "option2", null);2786 exe.addBuildOption(?usize, "option2", null);
2764 exe.addBuildOption([]const u8, "string", "zigisthebest");2787 exe.addBuildOption([]const u8, "string", "zigisthebest");
2765 exe.addBuildOption(?[]const u8, "optional_string", null);2788 exe.addBuildOption(?[]const u8, "optional_string", null);
2789 exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
27662790
2767 std.testing.expectEqualStrings(2791 std.testing.expectEqualStrings(
2768 \\pub const option1: usize = 1;2792 \\pub const option1: usize = 1;
2769 \\pub const option2: ?usize = null;2793 \\pub const option2: ?usize = null;
2770 \\pub const string: []const u8 = "zigisthebest";2794 \\pub const string: []const u8 = "zigisthebest";
2771 \\pub const optional_string: ?[]const u8 = null;2795 \\pub const optional_string: ?[]const u8 = null;
2796 \\pub const semantic_version: @import("std").SemanticVersion = .{
2797 \\ .major = 0,
2798 \\ .minor = 1,
2799 \\ .patch = 2,
2800 \\ .pre = "foo",
2801 \\ .build = "bar",
2802 \\};
2772 \\2803 \\
2773 , exe.build_options_contents.items);2804 , exe.build_options_contents.items);
2774}2805}