authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-01 16:34:15-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:15:04-07:00
log7e151cb5e99101012872090480519be65573c9c1
treed1535e3b18b7d33805e5bee5b0504b72eb9f6542
parentfd54a014996e5a602eda26783ebe10589c58ecd1

build: remove -Dwasi-bootstrap; add update-zig1 step

Now it is a single command tdo update zig1.wasm.zst.

1 files changed, 69 insertions(+), 22 deletions(-)

build.zig+69-22
...@@ -14,17 +14,11 @@ const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 };...@@ -14,17 +14,11 @@ const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 };
14const stack_size = 32 * 1024 * 1024;14const stack_size = 32 * 1024 * 1024;
1515
16pub fn build(b: *Builder) !void {16pub fn build(b: *Builder) !void {
17 const wasi_bootstrap = b.option(bool, "wasi-bootstrap", "Produce a WASI build for bootstrapping the compiler") orelse false;17 const release = b.option(bool, "release", "Build in release mode") orelse false;
18 const release = b.option(bool, "release", "Build in release mode") orelse wasi_bootstrap;18 const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
19 const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse wasi_bootstrap;
20 const target = t: {19 const target = t: {
21 var default_target: std.zig.CrossTarget = .{};20 var default_target: std.zig.CrossTarget = .{};
22 if (wasi_bootstrap) {21 if (only_c) {
23 default_target.cpu_arch = .wasm32;
24 default_target.os_tag = .wasi;
25 default_target.cpu_features_add.addFeature(@enumToInt(std.Target.wasm.Feature.bulk_memory));
26 break :t default_target;
27 } else if (only_c) {
28 default_target.ofmt = .c;22 default_target.ofmt = .c;
29 }23 }
30 break :t b.standardTargetOptions(.{ .default_target = default_target });24 break :t b.standardTargetOptions(.{ .default_target = default_target });
...@@ -81,7 +75,7 @@ pub fn build(b: *Builder) !void {...@@ -81,7 +75,7 @@ pub fn build(b: *Builder) !void {
81 if (deprecated_skip_install_lib_files) {75 if (deprecated_skip_install_lib_files) {
82 std.log.warn("-Dskip-install-lib-files is deprecated in favor of -Dno-lib", .{});76 std.log.warn("-Dskip-install-lib-files is deprecated in favor of -Dno-lib", .{});
83 }77 }
84 const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files to installation prefix. Useful for development") orelse (deprecated_skip_install_lib_files or wasi_bootstrap);78 const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files to installation prefix. Useful for development") orelse deprecated_skip_install_lib_files;
8579
86 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;80 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
8781
...@@ -145,7 +139,7 @@ pub fn build(b: *Builder) !void {...@@ -145,7 +139,7 @@ pub fn build(b: *Builder) !void {
145 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);139 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
146 const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);140 const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
147 const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false;141 const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false;
148 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or (only_c and !wasi_bootstrap));142 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or only_c);
149 const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false;143 const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false;
150 const strip = b.option(bool, "strip", "Omit debug information");144 const strip = b.option(bool, "strip", "Omit debug information");
151 const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;145 const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
...@@ -156,20 +150,17 @@ pub fn build(b: *Builder) !void {...@@ -156,20 +150,17 @@ pub fn build(b: *Builder) !void {
156 break :blk 4;150 break :blk 4;
157 };151 };
158152
159 const main_file: ?[]const u8 = "src/main.zig";153 const exe = addCompilerStep(b);
160
161 const exe = b.addExecutable("zig", main_file);
162
163 const compile_step = b.step("compile", "Build the self-hosted compiler");
164 compile_step.dependOn(&exe.step);
165
166 exe.stack_size = stack_size;
167 exe.strip = strip;154 exe.strip = strip;
168 exe.sanitize_thread = sanitize_thread;155 exe.sanitize_thread = sanitize_thread;
169 exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false;156 exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false;
170 exe.install();157 exe.install();
171 exe.setBuildMode(mode);158 exe.setBuildMode(mode);
172 exe.setTarget(target);159 exe.setTarget(target);
160
161 const compile_step = b.step("compile", "Build the self-hosted compiler");
162 compile_step.dependOn(&exe.step);
163
173 if (!skip_stage2_tests) {164 if (!skip_stage2_tests) {
174 test_step.dependOn(&exe.step);165 test_step.dependOn(&exe.step);
175 }166 }
...@@ -205,7 +196,7 @@ pub fn build(b: *Builder) !void {...@@ -205,7 +196,7 @@ pub fn build(b: *Builder) !void {
205 const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false;196 const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false;
206197
207 const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git.");198 const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git.");
208 const version = if (opt_version_string) |version| version else v: {199 const version_slice = if (opt_version_string) |version| version else v: {
209 if (!std.process.can_spawn) {200 if (!std.process.can_spawn) {
210 std.debug.print("error: version info cannot be retrieved from git. Zig version must be provided using -Dversion-string\n", .{});201 std.debug.print("error: version info cannot be retrieved from git. Zig version must be provided using -Dversion-string\n", .{});
211 std.process.exit(1);202 std.process.exit(1);
...@@ -257,7 +248,8 @@ pub fn build(b: *Builder) !void {...@@ -257,7 +248,8 @@ pub fn build(b: *Builder) !void {
257 },248 },
258 }249 }
259 };250 };
260 exe_options.addOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));251 const version = try b.allocator.dupeZ(u8, version_slice);
252 exe_options.addOption([:0]const u8, "version", version);
261253
262 if (enable_llvm) {254 if (enable_llvm) {
263 const cmake_cfg = if (static_llvm) null else blk: {255 const cmake_cfg = if (static_llvm) null else blk: {
...@@ -347,7 +339,7 @@ pub fn build(b: *Builder) !void {...@@ -347,7 +339,7 @@ pub fn build(b: *Builder) !void {
347 test_cases_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2);339 test_cases_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2);
348 test_cases_options.addOption(bool, "value_tracing", value_tracing);340 test_cases_options.addOption(bool, "value_tracing", value_tracing);
349 test_cases_options.addOption(?[]const u8, "glibc_runtimes_dir", b.glibc_runtimes_dir);341 test_cases_options.addOption(?[]const u8, "glibc_runtimes_dir", b.glibc_runtimes_dir);
350 test_cases_options.addOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));342 test_cases_options.addOption([:0]const u8, "version", version);
351 test_cases_options.addOption(std.SemanticVersion, "semver", semver);343 test_cases_options.addOption(std.SemanticVersion, "semver", semver);
352 test_cases_options.addOption(?[]const u8, "test_filter", test_filter);344 test_cases_options.addOption(?[]const u8, "test_filter", test_filter);
353345
...@@ -465,6 +457,61 @@ pub fn build(b: *Builder) !void {...@@ -465,6 +457,61 @@ pub fn build(b: *Builder) !void {
465 skip_stage1,457 skip_stage1,
466 true, // TODO get these all passing458 true, // TODO get these all passing
467 ));459 ));
460
461 try addWasiUpdateStep(b, version);
462}
463
464fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void {
465 const semver = try std.SemanticVersion.parse(version);
466
467 var target: std.zig.CrossTarget = .{
468 .cpu_arch = .wasm32,
469 .os_tag = .wasi,
470 };
471 target.cpu_features_add.addFeature(@enumToInt(std.Target.wasm.Feature.bulk_memory));
472
473 const exe = addCompilerStep(b);
474 exe.setBuildMode(.ReleaseSmall);
475 exe.setTarget(target);
476
477 const exe_options = b.addOptions();
478 exe.addOptions("build_options", exe_options);
479
480 exe_options.addOption(u32, "mem_leak_frames", 0);
481 exe_options.addOption(bool, "have_llvm", false);
482 exe_options.addOption(bool, "force_gpa", false);
483 exe_options.addOption(bool, "only_c", true);
484 exe_options.addOption([:0]const u8, "version", version);
485 exe_options.addOption(std.SemanticVersion, "semver", semver);
486 exe_options.addOption(bool, "enable_logging", false);
487 exe_options.addOption(bool, "enable_link_snapshots", false);
488 exe_options.addOption(bool, "enable_tracy", false);
489 exe_options.addOption(bool, "enable_tracy_callstack", false);
490 exe_options.addOption(bool, "enable_tracy_allocation", false);
491 exe_options.addOption(bool, "value_tracing", false);
492
493 const run_opt = b.addSystemCommand(&.{ "wasm-opt", "-Oz", "--enable-bulk-memory" });
494 run_opt.addArtifactArg(exe);
495 run_opt.addArg("-o");
496 run_opt.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });
497
498 const run_zstd = b.addSystemCommand(&.{ "zstd", "-19", "-f" });
499 run_zstd.step.dependOn(&run_opt.step);
500 run_zstd.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });
501 run_zstd.addArg("-o");
502 run_zstd.addFileSourceArg(.{ .path = "stage1/zig1.wasm.zst" });
503
504 const cleanup = b.addRemoveDirTree("stage1/zig1.wasm");
505 cleanup.step.dependOn(&run_zstd.step);
506
507 const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm.zst");
508 update_zig1_step.dependOn(&cleanup.step);
509}
510
511fn addCompilerStep(b: *Builder) *std.build.LibExeObjStep {
512 const exe = b.addExecutable("zig", "src/main.zig");
513 exe.stack_size = stack_size;
514 return exe;
468}515}
469516
470const exe_cflags = [_][]const u8{517const exe_cflags = [_][]const u8{