musl: deal with zig rename of i386 to x86

musl uses "i386" for this while Zig has switched to "x86".
This commit is contained in:
Andrew Kelley 2023-06-19 14:12:30 -07:00 committed by Jacob Young
parent 928c4c9bd3
commit cdcfd15d3c
4 changed files with 14 additions and 5 deletions

View File

@ -4918,7 +4918,7 @@ fn detectLibCFromBuilding(
const generic_name = target_util.libCGenericName(target);
// Some architectures are handled by the same set of headers.
const arch_name = if (target.abi.isMusl())
musl.archName(target.cpu.arch)
musl.archNameHeaders(target.cpu.arch)
else if (target.cpu.arch.isThumb())
// ARM headers are valid for Thumb too.
switch (target.cpu.arch) {

View File

@ -258,7 +258,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
}
}
pub fn archName(arch: std.Target.Cpu.Arch) [:0]const u8 {
fn archName(arch: std.Target.Cpu.Arch) [:0]const u8 {
switch (arch) {
.aarch64, .aarch64_be => return "aarch64",
.arm, .armeb, .thumb, .thumbeb => return "arm",
@ -275,6 +275,13 @@ pub fn archName(arch: std.Target.Cpu.Arch) [:0]const u8 {
}
}
pub fn archNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 {
return switch (arch) {
.x86 => return "x86",
else => archName(arch),
};
}
// Return true if musl has arch-specific crti/crtn sources.
// See lib/libc/musl/crt/ARCH/crt?.s .
pub fn needsCrtiCrtn(target: std.Target) bool {
@ -361,7 +368,9 @@ fn addCcArgs(
const target = comp.getTarget();
const arch_name = archName(target.cpu.arch);
const os_name = @tagName(target.os.tag);
const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name });
const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{
archNameHeaders(target.cpu.arch), os_name,
});
const o_arg = if (want_O3) "-O3" else "-Os";
try args.appendSlice(&[_][]const u8{

View File

@ -256,7 +256,7 @@ fn addCCArgs(
want_O3: bool,
) error{OutOfMemory}!void {
const target = comp.getTarget();
const arch_name = musl.archName(target.cpu.arch);
const arch_name = musl.archNameHeaders(target.cpu.arch);
const os_name = @tagName(target.os.tag);
const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name });
const o_arg = if (want_O3) "-O3" else "-Os";

View File

@ -208,7 +208,7 @@ const musl_targets = [_]LibCTarget{
.abi = MultiAbi.musl,
},
LibCTarget{
.name = "x86",
.name = "i386",
.arch = MultiArch{ .specific = .x86 },
.abi = MultiAbi.musl,
},