| ... | @@ -56,69 +56,6 @@ pub fn build(b: *Builder) !void { | ... | @@ -56,69 +56,6 @@ pub fn build(b: *Builder) !void { |
| 56 | const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse false; | 56 | const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse false; |
| 57 | const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h"); | 57 | const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h"); |
| 58 | | 58 | |
| 59 | if (!only_install_lib_files) { | | |
| 60 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); | | |
| 61 | exe.install(); | | |
| 62 | exe.setBuildMode(mode); | | |
| 63 | exe.setTarget(target); | | |
| 64 | test_step.dependOn(&exe.step); | | |
| 65 | b.default_step.dependOn(&exe.step); | | |
| 66 | | | |
| 67 | exe.addBuildOption(bool, "have_llvm", enable_llvm); | | |
| 68 | if (enable_llvm) { | | |
| 69 | const config_h_text = if (config_h_path_option) |config_h_path| | | |
| 70 | try std.fs.cwd().readFileAlloc(b.allocator, toNativePathSep(b, config_h_path), max_config_h_bytes) | | |
| 71 | else | | |
| 72 | try findAndReadConfigH(b); | | |
| 73 | | | |
| 74 | var ctx = parseConfigH(b, config_h_text); | | |
| 75 | ctx.llvm = try findLLVM(b, ctx.llvm_config_exe); | | |
| 76 | | | |
| 77 | try configureStage2(b, exe, ctx); | | |
| 78 | } | | |
| 79 | const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source"); | | |
| 80 | const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm; | | |
| 81 | if (link_libc) { | | |
| 82 | exe.linkLibC(); | | |
| 83 | test_stage2.linkLibC(); | | |
| 84 | } | | |
| 85 | | | |
| 86 | const log_scopes = b.option([]const []const u8, "log", "Which log scopes to enable") orelse &[0][]const u8{}; | | |
| 87 | const zir_dumps = b.option([]const []const u8, "dump-zir", "Which functions to dump ZIR for before codegen") orelse &[0][]const u8{}; | | |
| 88 | | | |
| 89 | const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git."); | | |
| 90 | const version = if (opt_version_string) |version| version else v: { | | |
| 91 | var code: u8 = undefined; | | |
| 92 | const version_untrimmed = b.execAllowFail(&[_][]const u8{ | | |
| 93 | "git", "-C", b.build_root, "name-rev", "HEAD", | | |
| 94 | "--tags", "--name-only", "--no-undefined", "--always", | | |
| 95 | }, &code, .Ignore) catch |err| { | | |
| 96 | std.debug.print( | | |
| 97 | \\Unable to determine zig version string: {} | | |
| 98 | \\Provide the zig version string explicitly using the `version-string` build option. | | |
| 99 | , .{err}); | | |
| 100 | std.process.exit(1); | | |
| 101 | }; | | |
| 102 | const trimmed = mem.trim(u8, version_untrimmed, " \n\r"); | | |
| 103 | break :v b.fmt("{}.{}.{}+{}", .{ zig_version.major, zig_version.minor, zig_version.patch, trimmed }); | | |
| 104 | }; | | |
| 105 | exe.addBuildOption([]const u8, "version", version); | | |
| 106 | | | |
| 107 | exe.addBuildOption([]const []const u8, "log_scopes", log_scopes); | | |
| 108 | exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps); | | |
| 109 | exe.addBuildOption(bool, "enable_tracy", tracy != null); | | |
| 110 | if (tracy) |tracy_path| { | | |
| 111 | const client_cpp = fs.path.join( | | |
| 112 | b.allocator, | | |
| 113 | &[_][]const u8{ tracy_path, "TracyClient.cpp" }, | | |
| 114 | ) catch unreachable; | | |
| 115 | exe.addIncludeDir(tracy_path); | | |
| 116 | exe.addCSourceFile(client_cpp, &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }); | | |
| 117 | exe.linkSystemLibraryName("c++"); | | |
| 118 | exe.linkLibC(); | | |
| 119 | } | | |
| 120 | } | | |
| 121 | | | |
| 122 | b.installDirectory(InstallDirectoryOptions{ | 59 | b.installDirectory(InstallDirectoryOptions{ |
| 123 | .source_dir = "lib", | 60 | .source_dir = "lib", |
| 124 | .install_dir = .Lib, | 61 | .install_dir = .Lib, |
| ... | @@ -132,6 +69,91 @@ pub fn build(b: *Builder) !void { | ... | @@ -132,6 +69,91 @@ pub fn build(b: *Builder) !void { |
| 132 | }, | 69 | }, |
| 133 | }); | 70 | }); |
| 134 | | 71 | |
| | 72 | if (only_install_lib_files) |
| | 73 | return; |
| | 74 | |
| | 75 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); |
| | 76 | exe.install(); |
| | 77 | exe.setBuildMode(mode); |
| | 78 | exe.setTarget(target); |
| | 79 | test_step.dependOn(&exe.step); |
| | 80 | b.default_step.dependOn(&exe.step); |
| | 81 | |
| | 82 | exe.addBuildOption(bool, "have_llvm", enable_llvm); |
| | 83 | if (enable_llvm) { |
| | 84 | const config_h_text = if (config_h_path_option) |config_h_path| |
| | 85 | try std.fs.cwd().readFileAlloc(b.allocator, toNativePathSep(b, config_h_path), max_config_h_bytes) |
| | 86 | else |
| | 87 | try findAndReadConfigH(b); |
| | 88 | |
| | 89 | var ctx = parseConfigH(b, config_h_text); |
| | 90 | ctx.llvm = try findLLVM(b, ctx.llvm_config_exe); |
| | 91 | |
| | 92 | try configureStage2(b, exe, ctx); |
| | 93 | } |
| | 94 | const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source"); |
| | 95 | const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm; |
| | 96 | if (link_libc) { |
| | 97 | exe.linkLibC(); |
| | 98 | test_stage2.linkLibC(); |
| | 99 | } |
| | 100 | |
| | 101 | const log_scopes = b.option([]const []const u8, "log", "Which log scopes to enable") orelse &[0][]const u8{}; |
| | 102 | const zir_dumps = b.option([]const []const u8, "dump-zir", "Which functions to dump ZIR for before codegen") orelse &[0][]const u8{}; |
| | 103 | |
| | 104 | const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git."); |
| | 105 | const version = if (opt_version_string) |version| version else v: { |
| | 106 | const version_string = b.fmt("{}.{}.{}", .{ zig_version.major, zig_version.minor, zig_version.patch }); |
| | 107 | |
| | 108 | var code: u8 = undefined; |
| | 109 | const git_sha_untrimmed = b.execAllowFail(&[_][]const u8{ |
| | 110 | "git", "-C", b.build_root, "name-rev", "HEAD", |
| | 111 | "--tags", "--name-only", "--no-undefined", "--always", |
| | 112 | }, &code, .Ignore) catch { |
| | 113 | break :v version_string; |
| | 114 | }; |
| | 115 | const git_sha_trimmed = mem.trim(u8, git_sha_untrimmed, " \n\r"); |
| | 116 | // Detect dirty changes. |
| | 117 | const diff_untrimmed = b.execAllowFail(&[_][]const u8{ |
| | 118 | "git", "-C", b.build_root, "diff", "HEAD", |
| | 119 | }, &code, .Ignore) catch |err| { |
| | 120 | std.debug.print("Error executing git diff: {}", .{err}); |
| | 121 | std.process.exit(1); |
| | 122 | }; |
| | 123 | const trimmed_diff = mem.trim(u8, diff_untrimmed, " \n\r"); |
| | 124 | const dirty_suffix = if (trimmed_diff.len == 0) "" else s: { |
| | 125 | const dirty_hash = std.hash.Wyhash.hash(0, trimmed_diff); |
| | 126 | break :s b.fmt("dirty{x}", .{@truncate(u32, dirty_hash)}); |
| | 127 | }; |
| | 128 | |
| | 129 | // This will look like e.g. "0.6.0^0" for a tag commit. |
| | 130 | if (mem.endsWith(u8, git_sha_trimmed, "^0")) { |
| | 131 | const git_ver_string = git_sha_trimmed[0 .. git_sha_trimmed.len - 2]; |
| | 132 | if (!mem.eql(u8, git_ver_string, version_string)) { |
| | 133 | std.debug.print("Expected git tag '{}', found '{}'", .{ version_string, git_ver_string }); |
| | 134 | std.process.exit(1); |
| | 135 | } |
| | 136 | break :v b.fmt("{}{}", .{ version_string, dirty_suffix }); |
| | 137 | } else { |
| | 138 | break :v b.fmt("{}+{}{}", .{ version_string, git_sha_trimmed, dirty_suffix }); |
| | 139 | } |
| | 140 | }; |
| | 141 | exe.addBuildOption([]const u8, "version", version); |
| | 142 | |
| | 143 | exe.addBuildOption([]const []const u8, "log_scopes", log_scopes); |
| | 144 | exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps); |
| | 145 | exe.addBuildOption(bool, "enable_tracy", tracy != null); |
| | 146 | if (tracy) |tracy_path| { |
| | 147 | const client_cpp = fs.path.join( |
| | 148 | b.allocator, |
| | 149 | &[_][]const u8{ tracy_path, "TracyClient.cpp" }, |
| | 150 | ) catch unreachable; |
| | 151 | exe.addIncludeDir(tracy_path); |
| | 152 | exe.addCSourceFile(client_cpp, &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }); |
| | 153 | exe.linkSystemLibraryName("c++"); |
| | 154 | exe.linkLibC(); |
| | 155 | } |
| | 156 | |
| 135 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); | 157 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); |
| 136 | | 158 | |
| 137 | const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false; | 159 | const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false; |
| ... | @@ -144,6 +166,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -144,6 +166,7 @@ pub fn build(b: *Builder) !void { |
| 144 | test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled); | 166 | test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled); |
| 145 | test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled); | 167 | test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled); |
| 146 | test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir); | 168 | test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir); |
| | 169 | test_stage2.addBuildOption([]const u8, "version", version); |
| 147 | | 170 | |
| 148 | const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests"); | 171 | const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests"); |
| 149 | test_stage2_step.dependOn(&test_stage2.step); | 172 | test_stage2_step.dependOn(&test_stage2.step); |