| ... | @@ -34,8 +34,14 @@ pub fn build(b: *Builder) !void { | ... | @@ -34,8 +34,14 @@ pub fn build(b: *Builder) !void { |
| 34 | | 34 | |
| 35 | const test_step = b.step("test", "Run all the tests"); | 35 | const test_step = b.step("test", "Run all the tests"); |
| 36 | | 36 | |
| 37 | var ctx = try findAndParseConfigH(b); | 37 | const config_h_text = if (b.option( |
| 38 | ctx.llvm = try findLLVM(b, ctx.llvm_config_exe); | 38 | []const u8, |
| | 39 | "config_h", |
| | 40 | "Path to the generated config.h", |
| | 41 | )) |config_h_path| |
| | 42 | try std.fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) |
| | 43 | else |
| | 44 | try findAndReadConfigH(b); |
| 39 | | 45 | |
| 40 | var test_stage2 = b.addTest("src-self-hosted/test.zig"); | 46 | var test_stage2 = b.addTest("src-self-hosted/test.zig"); |
| 41 | test_stage2.setBuildMode(builtin.Mode.Debug); | 47 | test_stage2.setBuildMode(builtin.Mode.Debug); |
| ... | @@ -46,9 +52,6 @@ pub fn build(b: *Builder) !void { | ... | @@ -46,9 +52,6 @@ pub fn build(b: *Builder) !void { |
| 46 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); | 52 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); |
| 47 | exe.setBuildMode(mode); | 53 | exe.setBuildMode(mode); |
| 48 | | 54 | |
| 49 | try configureStage2(b, test_stage2, ctx); | | |
| 50 | try configureStage2(b, exe, ctx); | | |
| 51 | | | |
| 52 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; | 55 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; |
| 53 | const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; | 56 | const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; |
| 54 | const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release; | 57 | const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release; |
| ... | @@ -62,6 +65,12 @@ pub fn build(b: *Builder) !void { | ... | @@ -62,6 +65,12 @@ pub fn build(b: *Builder) !void { |
| 62 | | 65 | |
| 63 | const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false; | 66 | const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false; |
| 64 | if (!only_install_lib_files and !skip_self_hosted) { | 67 | if (!only_install_lib_files and !skip_self_hosted) { |
| | 68 | var ctx = parseConfigH(config_h_text); |
| | 69 | ctx.llvm = try findLLVM(b, ctx.llvm_config_exe); |
| | 70 | |
| | 71 | try configureStage2(b, test_stage2, ctx); |
| | 72 | try configureStage2(b, exe, ctx); |
| | 73 | |
| 65 | b.default_step.dependOn(&exe.step); | 74 | b.default_step.dependOn(&exe.step); |
| 66 | exe.install(); | 75 | exe.install(); |
| 67 | } | 76 | } |
| ... | @@ -343,14 +352,15 @@ const Context = struct { | ... | @@ -343,14 +352,15 @@ const Context = struct { |
| 343 | llvm: LibraryDep, | 352 | llvm: LibraryDep, |
| 344 | }; | 353 | }; |
| 345 | | 354 | |
| 346 | fn findAndParseConfigH(b: *Builder) !Context { | 355 | const max_config_h_bytes = 1 * 1024 * 1024; |
| | 356 | |
| | 357 | fn findAndReadConfigH(b: *Builder) ![]const u8 { |
| 347 | var check_dir = fs.path.dirname(b.zig_exe).?; | 358 | var check_dir = fs.path.dirname(b.zig_exe).?; |
| 348 | const config_h_text = while (true) { | 359 | while (true) { |
| 349 | var dir = try fs.cwd().openDir(check_dir, .{}); | 360 | var dir = try fs.cwd().openDir(check_dir, .{}); |
| 350 | defer dir.close(); | 361 | defer dir.close(); |
| 351 | | 362 | |
| 352 | const max_bytes = 1 * 1024 * 1024; | 363 | const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) { |
| 353 | const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_bytes) catch |err| switch (err) { | | |
| 354 | error.FileNotFound => { | 364 | error.FileNotFound => { |
| 355 | const new_check_dir = fs.path.dirname(check_dir); | 365 | const new_check_dir = fs.path.dirname(check_dir); |
| 356 | if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) { | 366 | if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) { |
| ... | @@ -363,9 +373,11 @@ fn findAndParseConfigH(b: *Builder) !Context { | ... | @@ -363,9 +373,11 @@ fn findAndParseConfigH(b: *Builder) !Context { |
| 363 | }, | 373 | }, |
| 364 | else => |e| return e, | 374 | else => |e| return e, |
| 365 | }; | 375 | }; |
| 366 | break config_h_text; | 376 | return config_h_text; |
| 367 | } else unreachable; // TODO should not need `else unreachable`. | 377 | } else unreachable; // TODO should not need `else unreachable`. |
| | 378 | } |
| 368 | | 379 | |
| | 380 | fn parseConfigH(config_h_text: []const u8) Context { |
| 369 | var ctx: Context = .{ | 381 | var ctx: Context = .{ |
| 370 | .cmake_binary_dir = undefined, | 382 | .cmake_binary_dir = undefined, |
| 371 | .cxx_compiler = undefined, | 383 | .cxx_compiler = undefined, |