| ... | ... | @@ -14,17 +14,11 @@ const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 }; |
| 14 | 14 | const stack_size = 32 * 1024 * 1024; |
| 15 | 15 | |
| 16 | 16 | pub 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; |
| 20 | 19 | const target = t: { |
| 21 | 20 | 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) { |
| 28 | 22 | default_target.ofmt = .c; |
| 29 | 23 | } |
| 30 | 24 | break :t b.standardTargetOptions(.{ .default_target = default_target }); |
| ... | ... | @@ -81,7 +75,7 @@ pub fn build(b: *Builder) !void { |
| 81 | 75 | if (deprecated_skip_install_lib_files) { |
| 82 | 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; |
| 85 | 79 | |
| 86 | 80 | const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false; |
| 87 | 81 | |
| ... | ... | @@ -145,7 +139,7 @@ pub fn build(b: *Builder) !void { |
| 145 | 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 | 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 | 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 | 143 | const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false; |
| 150 | 144 | const strip = b.option(bool, "strip", "Omit debug information"); |
| 151 | 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 | 150 | break :blk 4; |
| 157 | 151 | }; |
| 158 | 152 | |
| 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); |
| 167 | 154 | exe.strip = strip; |
| 168 | 155 | exe.sanitize_thread = sanitize_thread; |
| 169 | 156 | exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false; |
| 170 | 157 | exe.install(); |
| 171 | 158 | exe.setBuildMode(mode); |
| 172 | 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 | 164 | if (!skip_stage2_tests) { |
| 174 | 165 | test_step.dependOn(&exe.step); |
| 175 | 166 | } |
| ... | ... | @@ -205,7 +196,7 @@ pub fn build(b: *Builder) !void { |
| 205 | 196 | const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false; |
| 206 | 197 | |
| 207 | 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 | 200 | if (!std.process.can_spawn) { |
| 210 | 201 | std.debug.print("error: version info cannot be retrieved from git. Zig version must be provided using -Dversion-string\n", .{}); |
| 211 | 202 | std.process.exit(1); |
| ... | ... | @@ -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); |
| 261 | 253 | |
| 262 | 254 | if (enable_llvm) { |
| 263 | 255 | const cmake_cfg = if (static_llvm) null else blk: { |
| ... | ... | @@ -347,7 +339,7 @@ pub fn build(b: *Builder) !void { |
| 347 | 339 | test_cases_options.addOption(u32, "mem_leak_frames", mem_leak_frames * 2); |
| 348 | 340 | test_cases_options.addOption(bool, "value_tracing", value_tracing); |
| 349 | 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 | 343 | test_cases_options.addOption(std.SemanticVersion, "semver", semver); |
| 352 | 344 | test_cases_options.addOption(?[]const u8, "test_filter", test_filter); |
| 353 | 345 | |
| ... | ... | @@ -465,6 +457,61 @@ pub fn build(b: *Builder) !void { |
| 465 | 457 | skip_stage1, |
| 466 | 458 | true, // TODO get these all passing |
| 467 | 459 | )); |
| 460 | |
| 461 | try addWasiUpdateStep(b, version); |
| 462 | } |
| 463 | |
| 464 | fn 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 | |
| 511 | fn 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 | } |
| 469 | 516 | |
| 470 | 517 | const exe_cflags = [_][]const u8{ |