| ... | @@ -14,13 +14,30 @@ const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 }; | ... | @@ -14,13 +14,30 @@ const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 }; |
| 14 | const stack_size = 32 * 1024 * 1024; | 14 | const stack_size = 32 * 1024 * 1024; |
| 15 | | 15 | |
| 16 | pub fn build(b: *Builder) !void { | 16 | pub fn build(b: *Builder) !void { |
| 17 | b.setPreferredReleaseMode(.ReleaseFast); | 17 | const wasi_bootstrap = b.option(bool, "wasi-bootstrap", "Produce a WASI build for bootstrapping the compiler") orelse false; |
| 18 | const test_step = b.step("test", "Run all the tests"); | 18 | const release = b.option(bool, "release", "Build in release mode") orelse wasi_bootstrap; |
| 19 | const mode = b.standardReleaseOptions(); | 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 | var target = b.standardTargetOptions(.{}); | 20 | const target = t: { |
| | 21 | var default_target: std.zig.CrossTarget = .{}; |
| | 22 | if (wasi_bootstrap) { |
| | 23 | default_target.cpu_arch = .wasm32; |
| | 24 | default_target.os_tag = .wasi; |
| | 25 | break :t default_target; |
| | 26 | } else if (only_c) { |
| | 27 | default_target.ofmt = .c; |
| | 28 | } |
| | 29 | break :t b.standardTargetOptions(.{ .default_target = default_target }); |
| | 30 | }; |
| | 31 | const mode: std.builtin.Mode = if (release) switch (target.getCpuArch()) { |
| | 32 | .wasm32 => .ReleaseSmall, |
| | 33 | else => .ReleaseFast, |
| | 34 | } else .Debug; |
| | 35 | |
| 21 | const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode"); | 36 | const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode"); |
| 22 | const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false; | 37 | const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false; |
| 23 | | 38 | |
| | 39 | const test_step = b.step("test", "Run all the tests"); |
| | 40 | |
| 24 | const docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); | 41 | const docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); |
| 25 | docgen_exe.single_threaded = single_threaded; | 42 | docgen_exe.single_threaded = single_threaded; |
| 26 | | 43 | |
| ... | @@ -48,8 +65,6 @@ pub fn build(b: *Builder) !void { | ... | @@ -48,8 +65,6 @@ pub fn build(b: *Builder) !void { |
| 48 | | 65 | |
| 49 | const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"}); | 66 | const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"}); |
| 50 | | 67 | |
| 51 | const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false; | | |
| 52 | | | |
| 53 | const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; | 68 | const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; |
| 54 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; | 69 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; |
| 55 | const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; | 70 | const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; |
| ... | @@ -65,7 +80,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -65,7 +80,7 @@ pub fn build(b: *Builder) !void { |
| 65 | if (deprecated_skip_install_lib_files) { | 80 | if (deprecated_skip_install_lib_files) { |
| 66 | std.log.warn("-Dskip-install-lib-files is deprecated in favor of -Dno-lib", .{}); | 81 | std.log.warn("-Dskip-install-lib-files is deprecated in favor of -Dno-lib", .{}); |
| 67 | } | 82 | } |
| 68 | 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; | 83 | 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); |
| 69 | | 84 | |
| 70 | const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false; | 85 | const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false; |
| 71 | | 86 | |
| ... | @@ -129,21 +144,17 @@ pub fn build(b: *Builder) !void { | ... | @@ -129,21 +144,17 @@ pub fn build(b: *Builder) !void { |
| 129 | const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null); | 144 | const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null); |
| 130 | const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null); | 145 | const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null); |
| 131 | const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false; | 146 | const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false; |
| 132 | const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or only_c); | 147 | 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)); |
| 133 | const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false; | 148 | const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false; |
| 134 | const strip = b.option(bool, "strip", "Omit debug information") orelse false; | 149 | const strip = b.option(bool, "strip", "Omit debug information"); |
| 135 | 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; | 150 | 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; |
| 136 | | 151 | |
| 137 | const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { | 152 | const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { |
| 138 | if (strip) break :blk @as(u32, 0); | 153 | if (strip == true) break :blk @as(u32, 0); |
| 139 | if (mode != .Debug) break :blk 0; | 154 | if (mode != .Debug) break :blk 0; |
| 140 | break :blk 4; | 155 | break :blk 4; |
| 141 | }; | 156 | }; |
| 142 | | 157 | |
| 143 | if (only_c) { | | |
| 144 | target.ofmt = .c; | | |
| 145 | } | | |
| 146 | | | |
| 147 | const main_file: ?[]const u8 = "src/main.zig"; | 158 | const main_file: ?[]const u8 = "src/main.zig"; |
| 148 | | 159 | |
| 149 | const exe = b.addExecutable("zig", main_file); | 160 | const exe = b.addExecutable("zig", main_file); |