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;...@@ -10,6 +10,8 @@ const io = std.io;
10const fs = std.fs;10const fs = std.fs;
11const InstallDirectoryOptions = std.build.InstallDirectoryOptions;11const InstallDirectoryOptions = std.build.InstallDirectoryOptions;
1212
13const zig_version = std.builtin.Version{ .major = 0, .minor = 6, .patch = 0 };
14
13pub fn build(b: *Builder) !void {15pub fn build(b: *Builder) !void {
14 b.setPreferredReleaseMode(.ReleaseFast);16 b.setPreferredReleaseMode(.ReleaseFast);
15 const mode = b.standardReleaseOptions();17 const mode = b.standardReleaseOptions();
...@@ -79,6 +81,24 @@ pub fn build(b: *Builder) !void {...@@ -79,6 +81,24 @@ pub fn build(b: *Builder) !void {
7981
80 const log_scopes = b.option([]const []const u8, "log", "Which log scopes to enable") orelse &[0][]const u8{};82 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
82 exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);102 exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);
83 exe.addBuildOption(bool, "enable_tracy", tracy != null);103 exe.addBuildOption(bool, "enable_tracy", tracy != null);
84 if (tracy) |tracy_path| {104 if (tracy) |tracy_path| {
src-self-hosted/link.zig+4-1
...@@ -15,6 +15,9 @@ const leb128 = std.debug.leb;...@@ -15,6 +15,9 @@ const leb128 = std.debug.leb;
15const Package = @import("Package.zig");15const Package = @import("Package.zig");
16const Value = @import("value.zig").Value;16const Value = @import("value.zig").Value;
17const Type = @import("type.zig").Type;17const 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
19// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.22// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
20// zig fmt: off23// zig fmt: off
...@@ -1132,7 +1135,7 @@ pub const File = struct {...@@ -1132,7 +1135,7 @@ pub const File = struct {
1132 // Write the form for the compile unit, which must match the abbrev table above.1135 // Write the form for the compile unit, which must match the abbrev table above.
1133 const name_strp = try self.makeDebugString(self.base.options.root_pkg.root_src_path);1136 const name_strp = try self.makeDebugString(self.base.options.root_pkg.root_src_path);
1134 const comp_dir_strp = try self.makeDebugString(self.base.options.root_pkg.root_src_dir_path);1137 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);
1136 // Currently only one compilation unit is supported, so the address range is simply1139 // Currently only one compilation unit is supported, so the address range is simply
1137 // identical to the main program header virtual address and memory size.1140 // identical to the main program header virtual address and memory size.
1138 const text_phdr = &self.program_headers.items[self.phdr_load_re_index.?];1141 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 {...@@ -95,11 +95,8 @@ pub fn main() !void {
95 const stdout = io.getStdOut().outStream();95 const stdout = io.getStdOut().outStream();
96 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, info.target);96 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, info.target);
97 } else if (mem.eql(u8, cmd, "version")) {97 } else if (mem.eql(u8, cmd, "version")) {
98 // Need to set up the build script to give the version as a comptime value.98 std.io.getStdOut().writeAll(build_options.version ++ "\n") catch process.exit(1);
99 // TODO when you solve this, also take a look at link.zig, there is a placeholder99 return;
100 // that says "TODO version here".
101 std.debug.print("TODO version command not implemented yet\n", .{});
102 return error.Unimplemented;
103 } else if (mem.eql(u8, cmd, "zen")) {100 } else if (mem.eql(u8, cmd, "zen")) {
104 try io.getStdOut().writeAll(info_zen);101 try io.getStdOut().writeAll(info_zen);
105 } else if (mem.eql(u8, cmd, "help")) {102 } else if (mem.eql(u8, cmd, "help")) {