aboutsummaryrefslogtreecommitdiff
path: root/src/target.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-08-15 20:49:34 +0100
committerAndrew Kelley <andrew@ziglang.org>2025-08-18 13:07:40 -0700
commitc1483eb05c221b4f0c0c357bf75b828f722fa44d (patch)
tree81956e1fdf1b4effd44386f02759a042e274e0ab /src/target.zig
parent2f422372b588789a5ce208bb85c9bfeee84dd980 (diff)
downloadzig-c1483eb05c221b4f0c0c357bf75b828f722fa44d.tar.gz
zig-c1483eb05c221b4f0c0c357bf75b828f722fa44d.zip
Compilation: fix compiler_rt and ubsan_rt strategy logic
It doesn't really make sense for `target_util.canBuildLibCompilerRt` (and its ubsan-rt friend) to take in `use_llvm`, because the caller doesn't control that: they're just going to queue a sub-compilation for the runtime. The only exception to that is the ZCU strategy, where we effectively embed `_ = @import("compiler_rt")` into the Zig compilation: there, the question does matter. Rather than trying to do multiple weird calls to model this, just have `canBuildLibCompilerRt` return not just a boolean, but also differentiate the self-hosted backend being capable of building the library vs only LLVM being capable. Logic in `Compilation` uses that difference to decide whether to use the ZCU strategy, and also to disable the library if the compiler does not support LLVM and it is required. Also, remove a redundant check later on, when actually queuing jobs. We've already checked that we can build `compiler_rt`, and `compiler_rt_strat` is set accordingly. I'm guessing this was there to work around a bug I saw in the old strategy assignment, where support was ignored in some cases. Resolves: #24623
Diffstat (limited to 'src/target.zig')
-rw-r--r--src/target.zig36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/target.zig b/src/target.zig
index b0fc3dd070..ee9d39fbf3 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -351,43 +351,41 @@ pub fn defaultCompilerRtOptimizeMode(target: *const std.Target) std.builtin.Opti
}
}
-pub fn canBuildLibCompilerRt(target: *const std.Target, use_llvm: bool, have_llvm: bool) bool {
+pub fn canBuildLibCompilerRt(target: *const std.Target) enum { no, yes, llvm_only } {
switch (target.os.tag) {
- .plan9 => return false,
+ .plan9 => return .no,
else => {},
}
switch (target.cpu.arch) {
- .spirv32, .spirv64 => return false,
+ .spirv32, .spirv64 => return .no,
// Remove this once https://github.com/ziglang/zig/issues/23714 is fixed
- .amdgcn => return false,
+ .amdgcn => return .no,
else => {},
}
- return switch (zigBackend(target, use_llvm)) {
- .stage2_aarch64 => true,
- .stage2_llvm => true,
+ return switch (zigBackend(target, false)) {
+ .stage2_aarch64 => .yes,
.stage2_x86_64 => switch (target.ofmt) {
- .elf, .macho => true,
- else => have_llvm,
+ .elf, .macho => .yes,
+ else => .llvm_only,
},
- else => have_llvm,
+ else => .llvm_only,
};
}
-pub fn canBuildLibUbsanRt(target: *const std.Target, use_llvm: bool, have_llvm: bool) bool {
+pub fn canBuildLibUbsanRt(target: *const std.Target) enum { no, yes, llvm_only, llvm_lld_only } {
switch (target.cpu.arch) {
- .spirv32, .spirv64 => return false,
+ .spirv32, .spirv64 => return .no,
// Remove this once https://github.com/ziglang/zig/issues/23715 is fixed
- .nvptx, .nvptx64 => return false,
+ .nvptx, .nvptx64 => return .no,
else => {},
}
- return switch (zigBackend(target, use_llvm)) {
- .stage2_llvm => true,
- .stage2_wasm => false,
+ return switch (zigBackend(target, false)) {
+ .stage2_wasm => .llvm_lld_only,
.stage2_x86_64 => switch (target.ofmt) {
- .elf, .macho => true,
- else => have_llvm,
+ .elf, .macho => .yes,
+ else => .llvm_only,
},
- else => have_llvm,
+ else => .llvm_only,
};
}