diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-01-21 14:27:05 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-21 14:27:05 -0500 |
| commit | b31a2c95550e0fd6ee0b1e8908fad69d364ce6ab (patch) | |
| tree | f21c96068ecc965008adf0bd58633b1c7274a02b /src/Compilation.zig | |
| parent | 0bacb79c090aabb367987ed0cff3982b84b8a4f7 (diff) | |
| parent | 874e17fe608a7b8d4324dada32664fcfe44978cd (diff) | |
| download | zig-b31a2c95550e0fd6ee0b1e8908fad69d364ce6ab.tar.gz zig-b31a2c95550e0fd6ee0b1e8908fad69d364ce6ab.zip | |
Merge pull request #22541 from ziglang/pipeline
Compilation pipeline: spawn Jobs earlier that produce linker inputs
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 440 |
1 files changed, 213 insertions, 227 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 1260bc028f..b85033264a 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -122,6 +122,10 @@ link_task_queue_postponed: std.ArrayListUnmanaged(link.Task) = .empty, /// the linker task thread. remaining_prelink_tasks: u32, +/// Set of work that can be represented by only flags to determine whether the +/// work is queued or not. +queued_jobs: QueuedJobs, + work_queues: [ len: { var len: usize = 0; @@ -193,10 +197,6 @@ stack_report: bool, debug_compiler_runtime_libs: bool, debug_compile_errors: bool, incremental: bool, -job_queued_compiler_rt_lib: bool = false, -job_queued_compiler_rt_obj: bool = false, -job_queued_fuzzer_lib: bool = false, -job_queued_update_builtin_zig: bool, alloc_failure_occurred: bool = false, last_update_was_cache_hit: bool = false, @@ -234,13 +234,13 @@ tsan_lib: ?CrtFile = null, /// and resolved before calling linker.flush(). libc_static_lib: ?CrtFile = null, /// Populated when we build the libcompiler_rt static library. A Job to build this is indicated -/// by setting `job_queued_compiler_rt_lib` and resolved before calling linker.flush(). +/// by setting `queued_jobs.compiler_rt_lib` and resolved before calling linker.flush(). compiler_rt_lib: ?CrtFile = null, /// Populated when we build the compiler_rt_obj object. A Job to build this is indicated -/// by setting `job_queued_compiler_rt_obj` and resolved before calling linker.flush(). +/// by setting `queued_jobs.compiler_rt_obj` and resolved before calling linker.flush(). compiler_rt_obj: ?CrtFile = null, /// Populated when we build the libfuzzer static library. A Job to build this -/// is indicated by setting `job_queued_fuzzer_lib` and resolved before +/// is indicated by setting `queued_jobs.fuzzer_lib` and resolved before /// calling linker.flush(). fuzzer_lib: ?CrtFile = null, @@ -284,6 +284,27 @@ file_system_inputs: ?*std.ArrayListUnmanaged(u8), /// This digest will be known after update() is called. digest: ?[Cache.bin_digest_len]u8 = null, +const QueuedJobs = struct { + compiler_rt_lib: bool = false, + compiler_rt_obj: bool = false, + fuzzer_lib: bool = false, + update_builtin_zig: bool, + musl_crt_file: [@typeInfo(musl.CrtFile).@"enum".fields.len]bool = @splat(false), + glibc_crt_file: [@typeInfo(glibc.CrtFile).@"enum".fields.len]bool = @splat(false), + /// one of WASI libc static objects + wasi_libc_crt_file: [@typeInfo(wasi_libc.CrtFile).@"enum".fields.len]bool = @splat(false), + /// one of the mingw-w64 static objects + mingw_crt_file: [@typeInfo(mingw.CrtFile).@"enum".fields.len]bool = @splat(false), + /// all of the glibc shared objects + glibc_shared_objects: bool = false, + /// libunwind.a, usually needed when linking libc + libunwind: bool = false, + libcxx: bool = false, + libcxxabi: bool = false, + libtsan: bool = false, + zig_libc: bool = false, +}; + pub const default_stack_protector_buffer_size = target_util.default_stack_protector_buffer_size; pub const SemaError = Zcu.SemaError; @@ -377,26 +398,6 @@ const Job = union(enum) { /// Fully resolve the given `struct` or `union` type. resolve_type_fully: InternPool.Index, - /// one of the glibc static objects - glibc_crt_file: glibc.CrtFile, - /// all of the glibc shared objects - glibc_shared_objects, - /// one of the musl static objects - musl_crt_file: musl.CrtFile, - /// one of the mingw-w64 static objects - mingw_crt_file: mingw.CrtFile, - - /// libunwind.a, usually needed when linking libc - libunwind: void, - libcxx: void, - libcxxabi: void, - libtsan: void, - /// needed when not linking libc and using LLVM for code generation because it generates - /// calls to, for example, memcpy and memset. - zig_libc: void, - /// one of WASI libc static objects - wasi_libc_crt_file: wasi_libc.CrtFile, - /// The value is the index into `windows_libs`. windows_import_lib: usize, @@ -800,8 +801,6 @@ pub const MiscTask = enum { docs_copy, docs_wasm, - @"musl crti.o", - @"musl crtn.o", @"musl crt1.o", @"musl rcrt1.o", @"musl Scrt1.o", @@ -816,8 +815,6 @@ pub const MiscTask = enum { @"libwasi-emulated-mman.a", @"libwasi-emulated-signal.a", - @"glibc crti.o", - @"glibc crtn.o", @"glibc Scrt1.o", @"glibc libc_nonshared.a", @"glibc shared object", @@ -1512,7 +1509,9 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil .framework_dirs = options.framework_dirs, .llvm_opt_bisect_limit = options.llvm_opt_bisect_limit, .skip_linker_dependencies = options.skip_linker_dependencies, - .job_queued_update_builtin_zig = have_zcu, + .queued_jobs = .{ + .update_builtin_zig = have_zcu, + }, .function_sections = options.function_sections, .data_sections = options.data_sections, .native_system_include_paths = options.native_system_include_paths, @@ -1804,64 +1803,44 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil } else if (target.isMusl() and !target.isWasm()) { if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; - if (musl.needsCrtiCrtn(target)) { - try comp.queueJobs(&[_]Job{ - .{ .musl_crt_file = .crti_o }, - .{ .musl_crt_file = .crtn_o }, - }); - comp.remaining_prelink_tasks += 2; - } if (musl.needsCrt0(comp.config.output_mode, comp.config.link_mode, comp.config.pie)) |f| { - try comp.queueJobs(&.{.{ .musl_crt_file = f }}); + comp.queued_jobs.musl_crt_file[@intFromEnum(f)] = true; comp.remaining_prelink_tasks += 1; } - try comp.queueJobs(&.{.{ .musl_crt_file = switch (comp.config.link_mode) { - .static => .libc_a, - .dynamic => .libc_so, - } }}); + switch (comp.config.link_mode) { + .static => comp.queued_jobs.musl_crt_file[@intFromEnum(musl.CrtFile.libc_a)] = true, + .dynamic => comp.queued_jobs.musl_crt_file[@intFromEnum(musl.CrtFile.libc_so)] = true, + } comp.remaining_prelink_tasks += 1; } else if (target.isGnuLibC()) { if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; - if (glibc.needsCrtiCrtn(target)) { - try comp.queueJobs(&[_]Job{ - .{ .glibc_crt_file = .crti_o }, - .{ .glibc_crt_file = .crtn_o }, - }); - comp.remaining_prelink_tasks += 2; - } if (glibc.needsCrt0(comp.config.output_mode)) |f| { - try comp.queueJobs(&.{.{ .glibc_crt_file = f }}); + comp.queued_jobs.glibc_crt_file[@intFromEnum(f)] = true; comp.remaining_prelink_tasks += 1; } - try comp.queueJobs(&[_]Job{ - .{ .glibc_shared_objects = {} }, - .{ .glibc_crt_file = .libc_nonshared_a }, - }); - comp.remaining_prelink_tasks += 1; + comp.queued_jobs.glibc_shared_objects = true; comp.remaining_prelink_tasks += glibc.sharedObjectsCount(&target); + + comp.queued_jobs.glibc_crt_file[@intFromEnum(glibc.CrtFile.libc_nonshared_a)] = true; + comp.remaining_prelink_tasks += 1; } else if (target.isWasm() and target.os.tag == .wasi) { if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; for (comp.wasi_emulated_libs) |crt_file| { - try comp.queueJob(.{ - .wasi_libc_crt_file = crt_file, - }); - comp.remaining_prelink_tasks += 1; + comp.queued_jobs.wasi_libc_crt_file[@intFromEnum(crt_file)] = true; } - try comp.queueJobs(&[_]Job{ - .{ .wasi_libc_crt_file = wasi_libc.execModelCrtFile(comp.config.wasi_exec_model) }, - .{ .wasi_libc_crt_file = .libc_a }, - }); + comp.remaining_prelink_tasks += @intCast(comp.wasi_emulated_libs.len); + + comp.queued_jobs.wasi_libc_crt_file[@intFromEnum(wasi_libc.execModelCrtFile(comp.config.wasi_exec_model))] = true; + comp.queued_jobs.wasi_libc_crt_file[@intFromEnum(wasi_libc.CrtFile.libc_a)] = true; comp.remaining_prelink_tasks += 2; } else if (target.isMinGW()) { if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; - const crt_job: Job = .{ .mingw_crt_file = if (is_dyn_lib) .dllcrt2_o else .crt2_o }; - try comp.queueJobs(&.{ - .{ .mingw_crt_file = .mingw32_lib }, - crt_job, - }); + const main_crt_file: mingw.CrtFile = if (is_dyn_lib) .dllcrt2_o else .crt2_o; + comp.queued_jobs.mingw_crt_file[@intFromEnum(main_crt_file)] = true; + comp.queued_jobs.mingw_crt_file[@intFromEnum(mingw.CrtFile.mingw32_lib)] = true; comp.remaining_prelink_tasks += 2; // When linking mingw-w64 there are some import libs we always need. @@ -1873,7 +1852,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil else => return error.LibCUnavailable, } } else if (target.os.tag == .freestanding and capable_of_building_zig_libc) { - try comp.queueJob(.{ .zig_libc = {} }); + comp.queued_jobs.zig_libc = true; comp.remaining_prelink_tasks += 1; } else { return error.LibCUnavailable; @@ -1886,18 +1865,22 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil for (0..count) |i| { try comp.queueJob(.{ .windows_import_lib = i }); } + // when integrating coff linker with prelink, the above + // queueJob will need to change into something else since those + // jobs are dispatched *after* the link_task_wait_group.wait() + // that happens when separateCodegenThreadOk() is false. } if (comp.wantBuildLibUnwindFromSource()) { - try comp.queueJob(.{ .libunwind = {} }); + comp.queued_jobs.libunwind = true; comp.remaining_prelink_tasks += 1; } if (build_options.have_llvm and is_exe_or_dyn_lib and comp.config.link_libcpp) { - try comp.queueJob(.libcxx); - try comp.queueJob(.libcxxabi); + comp.queued_jobs.libcxx = true; + comp.queued_jobs.libcxxabi = true; comp.remaining_prelink_tasks += 2; } if (build_options.have_llvm and is_exe_or_dyn_lib and comp.config.any_sanitize_thread) { - try comp.queueJob(.libtsan); + comp.queued_jobs.libtsan = true; comp.remaining_prelink_tasks += 1; } @@ -1916,20 +1899,20 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil if (comp.include_compiler_rt and capable_of_building_compiler_rt) { if (is_exe_or_dyn_lib) { log.debug("queuing a job to build compiler_rt_lib", .{}); - comp.job_queued_compiler_rt_lib = true; + comp.queued_jobs.compiler_rt_lib = true; comp.remaining_prelink_tasks += 1; } else if (output_mode != .Obj) { log.debug("queuing a job to build compiler_rt_obj", .{}); // In this case we are making a static library, so we ask // for a compiler-rt object to put in it. - comp.job_queued_compiler_rt_obj = true; + comp.queued_jobs.compiler_rt_obj = true; comp.remaining_prelink_tasks += 1; } } if (is_exe_or_dyn_lib and comp.config.any_fuzz and capable_of_building_compiler_rt) { log.debug("queuing a job to build libfuzzer", .{}); - comp.job_queued_fuzzer_lib = true; + comp.queued_jobs.fuzzer_lib = true; comp.remaining_prelink_tasks += 1; } } @@ -3712,21 +3695,70 @@ fn performAllTheWorkInner( work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, main_progress_node }); } - if (comp.job_queued_compiler_rt_lib) { - comp.job_queued_compiler_rt_lib = false; + if (testAndClear(&comp.queued_jobs.compiler_rt_lib)) { comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Lib, &comp.compiler_rt_lib, main_progress_node }); } - if (comp.job_queued_compiler_rt_obj) { - comp.job_queued_compiler_rt_obj = false; + if (testAndClear(&comp.queued_jobs.compiler_rt_obj)) { comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Obj, &comp.compiler_rt_obj, main_progress_node }); } - if (comp.job_queued_fuzzer_lib) { - comp.job_queued_fuzzer_lib = false; + if (testAndClear(&comp.queued_jobs.fuzzer_lib)) { comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", .libfuzzer, .Lib, &comp.fuzzer_lib, main_progress_node }); } + if (testAndClear(&comp.queued_jobs.glibc_shared_objects)) { + comp.link_task_wait_group.spawnManager(buildGlibcSharedObjects, .{ comp, main_progress_node }); + } + + if (testAndClear(&comp.queued_jobs.libunwind)) { + comp.link_task_wait_group.spawnManager(buildLibUnwind, .{ comp, main_progress_node }); + } + + if (testAndClear(&comp.queued_jobs.libcxx)) { + comp.link_task_wait_group.spawnManager(buildLibCxx, .{ comp, main_progress_node }); + } + + if (testAndClear(&comp.queued_jobs.libcxxabi)) { + comp.link_task_wait_group.spawnManager(buildLibCxxAbi, .{ comp, main_progress_node }); + } + + if (testAndClear(&comp.queued_jobs.libtsan)) { + comp.link_task_wait_group.spawnManager(buildLibTsan, .{ comp, main_progress_node }); + } + + if (testAndClear(&comp.queued_jobs.zig_libc)) { + comp.link_task_wait_group.spawnManager(buildZigLibc, .{ comp, main_progress_node }); + } + + for (0..@typeInfo(musl.CrtFile).@"enum".fields.len) |i| { + if (testAndClear(&comp.queued_jobs.musl_crt_file[i])) { + const tag: musl.CrtFile = @enumFromInt(i); + comp.link_task_wait_group.spawnManager(buildMuslCrtFile, .{ comp, tag, main_progress_node }); + } + } + + for (0..@typeInfo(glibc.CrtFile).@"enum".fields.len) |i| { + if (testAndClear(&comp.queued_jobs.glibc_crt_file[i])) { + const tag: glibc.CrtFile = @enumFromInt(i); + comp.link_task_wait_group.spawnManager(buildGlibcCrtFile, .{ comp, tag, main_progress_node }); + } + } + + for (0..@typeInfo(wasi_libc.CrtFile).@"enum".fields.len) |i| { + if (testAndClear(&comp.queued_jobs.wasi_libc_crt_file[i])) { + const tag: wasi_libc.CrtFile = @enumFromInt(i); + comp.link_task_wait_group.spawnManager(buildWasiLibcCrtFile, .{ comp, tag, main_progress_node }); + } + } + + for (0..@typeInfo(mingw.CrtFile).@"enum".fields.len) |i| { + if (testAndClear(&comp.queued_jobs.mingw_crt_file[i])) { + const tag: mingw.CrtFile = @enumFromInt(i); + comp.link_task_wait_group.spawnManager(buildMingwCrtFile, .{ comp, tag, main_progress_node }); + } + } + { const astgen_frame = tracy.namedFrame("astgen"); defer astgen_frame.end(); @@ -3741,8 +3773,8 @@ fn performAllTheWorkInner( // 1. to avoid race condition of zig processes truncating each other's builtin.zig files // 2. optimization; in the hot path it only incurs a stat() syscall, which happens // in the `astgen_wait_group`. - if (comp.job_queued_update_builtin_zig) b: { - comp.job_queued_update_builtin_zig = false; + if (comp.queued_jobs.update_builtin_zig) b: { + comp.queued_jobs.update_builtin_zig = false; if (comp.zcu == null) break :b; // TODO put all the modules in a flat array to make them easy to iterate. var seen: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .empty; @@ -3821,11 +3853,12 @@ fn performAllTheWorkInner( comp.link_task_wait_group.wait(); comp.link_task_wait_group.reset(); std.log.scoped(.link).debug("finished waiting for link_task_wait_group", .{}); + assert(comp.remaining_prelink_tasks == 0); } work: while (true) { for (&comp.work_queues) |*work_queue| if (work_queue.readItem()) |job| { - try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job, main_progress_node); + try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job); continue :work; }; if (comp.zcu) |zcu| { @@ -3860,7 +3893,7 @@ pub fn queueJobs(comp: *Compilation, jobs: []const Job) !void { for (jobs) |job| try comp.queueJob(job); } -fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progress.Node) JobError!void { +fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void { switch (job) { .codegen_nav => |nav_index| { const zcu = comp.zcu.?; @@ -3956,56 +3989,6 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre error.AnalysisFail => return, }; }, - .glibc_crt_file => |crt_file| { - const named_frame = tracy.namedFrame("glibc_crt_file"); - defer named_frame.end(); - - glibc.buildCrtFile(comp, crt_file, prog_node) catch |err| { - // TODO Surface more error details. - comp.lockAndSetMiscFailure(.glibc_crt_file, "unable to build glibc CRT file: {s}", .{ - @errorName(err), - }); - }; - }, - .glibc_shared_objects => { - const named_frame = tracy.namedFrame("glibc_shared_objects"); - defer named_frame.end(); - - glibc.buildSharedObjects(comp, prog_node) catch |err| { - // TODO Surface more error details. - comp.lockAndSetMiscFailure( - .glibc_shared_objects, - "unable to build glibc shared objects: {s}", - .{@errorName(err)}, - ); - }; - }, - .musl_crt_file => |crt_file| { - const named_frame = tracy.namedFrame("musl_crt_file"); - defer named_frame.end(); - - musl.buildCrtFile(comp, crt_file, prog_node) catch |err| { - // TODO Surface more error details. - comp.lockAndSetMiscFailure( - .musl_crt_file, - "unable to build musl CRT file: {s}", - .{@errorName(err)}, - ); - }; - }, - .mingw_crt_file => |crt_file| { - const named_frame = tracy.namedFrame("mingw_crt_file"); - defer named_frame.end(); - - mingw.buildCrtFile(comp, crt_file, prog_node) catch |err| { - // TODO Surface more error details. - comp.lockAndSetMiscFailure( - .mingw_crt_file, - "unable to build mingw-w64 CRT file {s}: {s}", - .{ @tagName(crt_file), @errorName(err) }, - ); - }; - }, .windows_import_lib => |index| { const named_frame = tracy.namedFrame("windows_import_lib"); defer named_frame.end(); @@ -4020,95 +4003,6 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre ); }; }, - .libunwind => { - const named_frame = tracy.namedFrame("libunwind"); - defer named_frame.end(); - - libunwind.buildStaticLib(comp, prog_node) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.SubCompilationFailed => return, // error reported already - else => comp.lockAndSetMiscFailure( - .libunwind, - "unable to build libunwind: {s}", - .{@errorName(err)}, - ), - }; - }, - .libcxx => { - const named_frame = tracy.namedFrame("libcxx"); - defer named_frame.end(); - - libcxx.buildLibCXX(comp, prog_node) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.SubCompilationFailed => return, // error reported already - else => comp.lockAndSetMiscFailure( - .libcxx, - "unable to build libcxx: {s}", - .{@errorName(err)}, - ), - }; - }, - .libcxxabi => { - const named_frame = tracy.namedFrame("libcxxabi"); - defer named_frame.end(); - - libcxx.buildLibCXXABI(comp, prog_node) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.SubCompilationFailed => return, // error reported already - else => comp.lockAndSetMiscFailure( - .libcxxabi, - "unable to build libcxxabi: {s}", - .{@errorName(err)}, - ), - }; - }, - .libtsan => { - const named_frame = tracy.namedFrame("libtsan"); - defer named_frame.end(); - - libtsan.buildTsan(comp, prog_node) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.SubCompilationFailed => return, // error reported already - else => comp.lockAndSetMiscFailure( - .libtsan, - "unable to build TSAN library: {s}", - .{@errorName(err)}, - ), - }; - }, - .wasi_libc_crt_file => |crt_file| { - const named_frame = tracy.namedFrame("wasi_libc_crt_file"); - defer named_frame.end(); - - wasi_libc.buildCrtFile(comp, crt_file, prog_node) catch |err| { - // TODO Surface more error details. - comp.lockAndSetMiscFailure( - .wasi_libc_crt_file, - "unable to build WASI libc CRT file: {s}", - .{@errorName(err)}, - ); - }; - }, - .zig_libc => { - const named_frame = tracy.namedFrame("zig_libc"); - defer named_frame.end(); - - comp.buildOutputFromZig( - "c.zig", - .Lib, - &comp.libc_static_lib, - .zig_libc, - prog_node, - ) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.SubCompilationFailed => return, // error reported already - else => comp.lockAndSetMiscFailure( - .zig_libc, - "unable to build zig's multitarget libc: {s}", - .{@errorName(err)}, - ), - }; - }, } } @@ -4761,6 +4655,92 @@ fn buildRt( }; } +fn buildMuslCrtFile(comp: *Compilation, crt_file: musl.CrtFile, prog_node: std.Progress.Node) void { + musl.buildCrtFile(comp, crt_file, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.musl_crt_file, "unable to build musl {s}: {s}", .{ + @tagName(crt_file), @errorName(err), + }), + }; +} + +fn buildGlibcCrtFile(comp: *Compilation, crt_file: glibc.CrtFile, prog_node: std.Progress.Node) void { + glibc.buildCrtFile(comp, crt_file, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.glibc_crt_file, "unable to build glibc {s}: {s}", .{ + @tagName(crt_file), @errorName(err), + }), + }; +} + +fn buildGlibcSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) void { + glibc.buildSharedObjects(comp, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.glibc_shared_objects, "unable to build glibc shared objects: {s}", .{ + @errorName(err), + }), + }; +} + +fn buildMingwCrtFile(comp: *Compilation, crt_file: mingw.CrtFile, prog_node: std.Progress.Node) void { + mingw.buildCrtFile(comp, crt_file, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.mingw_crt_file, "unable to build mingw-w64 {s}: {s}", .{ + @tagName(crt_file), @errorName(err), + }), + }; +} + +fn buildWasiLibcCrtFile(comp: *Compilation, crt_file: wasi_libc.CrtFile, prog_node: std.Progress.Node) void { + wasi_libc.buildCrtFile(comp, crt_file, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.wasi_libc_crt_file, "unable to build WASI libc {s}: {s}", .{ + @tagName(crt_file), @errorName(err), + }), + }; +} + +fn buildLibUnwind(comp: *Compilation, prog_node: std.Progress.Node) void { + libunwind.buildStaticLib(comp, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.libunwind, "unable to build libunwind: {s}", .{@errorName(err)}), + }; +} + +fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) void { + libcxx.buildLibCxx(comp, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.libcxx, "unable to build libcxx: {s}", .{@errorName(err)}), + }; +} + +fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) void { + libcxx.buildLibCxxAbi(comp, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.libcxxabi, "unable to build libcxxabi: {s}", .{@errorName(err)}), + }; +} + +fn buildLibTsan(comp: *Compilation, prog_node: std.Progress.Node) void { + libtsan.buildTsan(comp, prog_node) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.libtsan, "unable to build TSAN library: {s}", .{@errorName(err)}), + }; +} + +fn buildZigLibc(comp: *Compilation, prog_node: std.Progress.Node) void { + comp.buildOutputFromZig( + "c.zig", + .Lib, + &comp.libc_static_lib, + .zig_libc, + prog_node, + ) catch |err| switch (err) { + error.SubCompilationFailed => return, // error reported already + else => comp.lockAndSetMiscFailure(.zig_libc, "unable to build zig's multitarget libc: {s}", .{@errorName(err)}), + }; +} + fn reportRetryableCObjectError( comp: *Compilation, c_object: *CObject, @@ -6805,3 +6785,9 @@ pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode { pub fn compilerRtStrip(comp: Compilation) bool { return comp.root_mod.strip; } + +fn testAndClear(b: *bool) bool { + const result = b.*; + b.* = false; + return result; +} |
