authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-15 14:17:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-15 20:04:08-04:00
log8d8d568854d33be7bcc2bc9874029d1082914af7
tree5f586a97c22f088515f9291e37f3af229aa28db3
parent66d76cc4f938209470fedd8e52f71267f0e0d0e4

stage2: implement zig version


3 files changed, 26 insertions(+), 6 deletions(-)

build.zig+20
......@@ -10,6 +10,8 @@ const io = std.io;
1010const fs = std.fs;
1111const InstallDirectoryOptions = std.build.InstallDirectoryOptions;
1212
13const zig_version = std.builtin.Version{ .major = 0, .minor = 6, .patch = 0 };
14
1315pub fn build(b: *Builder) !void {
1416 b.setPreferredReleaseMode(.ReleaseFast);
1517 const mode = b.standardReleaseOptions();
......@@ -79,6 +81,24 @@ pub fn build(b: *Builder) !void {
7981
8082 const log_scopes = b.option([]const []const u8, "log", "Which log scopes to enable") orelse &[0][]const u8{};
8183
84 const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git.");
85 const version = if (opt_version_string) |version| version else v: {
86 var code: u8 = undefined;
87 const version_untrimmed = b.execAllowFail(&[_][]const u8{
88 "git", "-C", b.build_root, "name-rev", "HEAD",
89 "--tags", "--name-only", "--no-undefined", "--always",
90 }, &code, .Ignore) catch |err| {
91 std.debug.print(
92 \\Unable to determine zig version string: {}
93 \\Provide the zig version string explicitly using the `version-string` build option.
94 , .{err});
95 std.process.exit(1);
96 };
97 const trimmed = mem.trim(u8, version_untrimmed, " \n\r");
98 break :v b.fmt("{}.{}.{}+{}", .{ zig_version.major, zig_version.minor, zig_version.patch, trimmed });
99 };
100 exe.addBuildOption([]const u8, "version", version);
101
82102 exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);
83103 exe.addBuildOption(bool, "enable_tracy", tracy != null);
84104 if (tracy) |tracy_path| {
src-self-hosted/link.zig+4-1
......@@ -15,6 +15,9 @@ const leb128 = std.debug.leb;
1515const Package = @import("Package.zig");
1616const Value = @import("value.zig").Value;
1717const Type = @import("type.zig").Type;
18const build_options = @import("build_options");
19
20const producer_string = if (std.builtin.is_test) "zig test" else "zig " ++ build_options.version;
1821
1922// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
2023// zig fmt: off
......@@ -1132,7 +1135,7 @@ pub const File = struct {
11321135 // Write the form for the compile unit, which must match the abbrev table above.
11331136 const name_strp = try self.makeDebugString(self.base.options.root_pkg.root_src_path);
11341137 const comp_dir_strp = try self.makeDebugString(self.base.options.root_pkg.root_src_dir_path);
1135 const producer_strp = try self.makeDebugString("zig (TODO version here)");
1138 const producer_strp = try self.makeDebugString(producer_string);
11361139 // Currently only one compilation unit is supported, so the address range is simply
11371140 // identical to the main program header virtual address and memory size.
11381141 const text_phdr = &self.program_headers.items[self.phdr_load_re_index.?];
src-self-hosted/main.zig+2-5
......@@ -95,11 +95,8 @@ pub fn main() !void {
9595 const stdout = io.getStdOut().outStream();
9696 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, info.target);
9797 } else if (mem.eql(u8, cmd, "version")) {
98 // Need to set up the build script to give the version as a comptime value.
99 // TODO when you solve this, also take a look at link.zig, there is a placeholder
100 // that says "TODO version here".
101 std.debug.print("TODO version command not implemented yet\n", .{});
102 return error.Unimplemented;
98 std.io.getStdOut().writeAll(build_options.version ++ "\n") catch process.exit(1);
99 return;
103100 } else if (mem.eql(u8, cmd, "zen")) {
104101 try io.getStdOut().writeAll(info_zen);
105102 } else if (mem.eql(u8, cmd, "help")) {