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 };
1414const stack_size = 32 * 1024 * 1024;
1515
1616pub fn build(b: *Builder) !void {
17 const wasi_bootstrap = b.option(bool, "wasi-bootstrap", "Produce a WASI build for bootstrapping the compiler") orelse false;
18 const release = b.option(bool, "release", "Build in release mode") orelse wasi_bootstrap;
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;
17 const release = b.option(bool, "release", "Build in release mode") orelse false;
18 const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
2019 const target = t: {
2120 var default_target: std.zig.CrossTarget = .{};
22 if (wasi_bootstrap) {
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) {
21 if (only_c) {
2822 default_target.ofmt = .c;
2923 }
3024 break :t b.standardTargetOptions(.{ .default_target = default_target });
......@@ -81,7 +75,7 @@ pub fn build(b: *Builder) !void {
8175 if (deprecated_skip_install_lib_files) {
8276 std.log.warn("-Dskip-install-lib-files is deprecated in favor of -Dno-lib", .{});
8377 }
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
8680 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 {
145139 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
146140 const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
147141 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);
149143 const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false;
150144 const strip = b.option(bool, "strip", "Omit debug information");
151145 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 {
156150 break :blk 4;
157151 };
158152
159 const main_file: ?[]const u8 = "src/main.zig";
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;
153 const exe = addCompilerStep(b);
167154 exe.strip = strip;
168155 exe.sanitize_thread = sanitize_thread;
169156 exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false;
170157 exe.install();
171158 exe.setBuildMode(mode);
172159 exe.setTarget(target);
160
161 const compile_step = b.step("compile", "Build the self-hosted compiler");
162 compile_step.dependOn(&exe.step);
163
173164 if (!skip_stage2_tests) {
174165 test_step.dependOn(&exe.step);
175166 }
......@@ -205,7 +196,7 @@ pub fn build(b: *Builder) !void {
205196 const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false;
206197
207198 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: {
209200 if (!std.process.can_spawn) {
210201 std.debug.print("error: version info cannot be retrieved from git. Zig version must be provided using -Dversion-string\n", .{});
211202 std.process.exit(1);
......@@ -257,7 +248,8 @@ pub fn build(b: *Builder) !void {
257248 },
258249 }
259250 };
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
262254 if (enable_llvm) {
263255 const cmake_cfg = if (static_llvm) null else blk: {
......@@ -347,7 +339,7 @@ pub fn build(b: *Builder) !void {
347339 test_cases_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2);
348340 test_cases_options.addOption(bool, "value_tracing", value_tracing);
349341 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);
351343 test_cases_options.addOption(std.SemanticVersion, "semver", semver);
352344 test_cases_options.addOption(?[]const u8, "test_filter", test_filter);
353345
......@@ -465,6 +457,61 @@ pub fn build(b: *Builder) !void {
465457 skip_stage1,
466458 true, // TODO get these all passing
467459 ));
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;
468515}
469516
470517const exe_cflags = [_][]const u8{