| author | |
| committer | |
| log | 8045268698bb46e954c886b913fe216c59f5824e |
| tree | 257035a6382ec86acba573125d9e00b0cfdf485a |
| parent | 533d8ea771a307a33d1e6f93d819d808f9c27597 |
| signature |
This is needed for muslx32 and muslabin32 support.3 files changed, 44 insertions(+), 38 deletions(-)
lib/std/zig/LibCDirs.zig+5-10| ... | @@ -167,21 +167,16 @@ pub fn detectFromBuilding( | ... | @@ -167,21 +167,16 @@ pub fn detectFromBuilding( |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | const generic_name = libCGenericName(target); | 169 | const generic_name = libCGenericName(target); |
| 170 | // Some architectures are handled by the same set of headers. | 170 | // Some architecture families are handled by the same set of headers. |
| 171 | const arch_name = if (target.abi.isMusl()) | 171 | const arch_name = if (target.abi.isMusl()) |
| 172 | std.zig.target.muslArchNameHeaders(target.cpu.arch) | 172 | std.zig.target.muslArchNameHeaders(target.cpu.arch) |
| 173 | else if (target.cpu.arch.isThumb()) | ||
| 174 | // ARM headers are valid for Thumb too. | ||
| 175 | switch (target.cpu.arch) { | ||
| 176 | .thumb => "arm", | ||
| 177 | .thumbeb => "armeb", | ||
| 178 | else => unreachable, | ||
| 179 | } | ||
| 180 | else | 173 | else |
| 181 | @tagName(target.cpu.arch); | 174 | @tagName(target.cpu.arch); |
| 182 | const os_name = @tagName(target.os.tag); | 175 | const os_name = @tagName(target.os.tag); |
| 183 | // Musl's headers are ABI-agnostic and so they all have the "musl" ABI name. | 176 | const abi_name = if (target.abi.isMusl()) |
| 184 | const abi_name = if (target.abi.isMusl()) "musl" else @tagName(target.abi); | 177 | std.zig.target.muslAbiNameHeaders(target.abi) |
| 178 | else | ||
| 179 | @tagName(target.abi); | ||
| 185 | const arch_include_dir = try std.fmt.allocPrint( | 180 | const arch_include_dir = try std.fmt.allocPrint( |
| 186 | arena, | 181 | arena, |
| 187 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", | 182 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", |
lib/std/zig/target.zig+30-20| ... | @@ -97,31 +97,41 @@ pub fn canBuildLibC(target: std.Target) bool { | ... | @@ -97,31 +97,41 @@ pub fn canBuildLibC(target: std.Target) bool { |
| 97 | return false; | 97 | return false; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | pub fn muslArchName(arch: std.Target.Cpu.Arch, abi: std.Target.Abi) [:0]const u8 { | ||
| 101 | return switch (abi) { | ||
| 102 | .muslx32 => "x32", | ||
| 103 | else => switch (arch) { | ||
| 104 | .arm, .armeb, .thumb, .thumbeb => "arm", | ||
| 105 | .aarch64, .aarch64_be => "aarch64", | ||
| 106 | .loongarch64 => "loongarch64", | ||
| 107 | .m68k => "m68k", | ||
| 108 | .mips, .mipsel => "mips", | ||
| 109 | .mips64el, .mips64 => "mips64", | ||
| 110 | .powerpc => "powerpc", | ||
| 111 | .powerpc64, .powerpc64le => "powerpc64", | ||
| 112 | .riscv32 => "riscv32", | ||
| 113 | .riscv64 => "riscv64", | ||
| 114 | .s390x => "s390x", | ||
| 115 | .wasm32, .wasm64 => "wasm", | ||
| 116 | .x86 => "i386", | ||
| 117 | .x86_64 => "x86_64", | ||
| 118 | else => unreachable, | ||
| 119 | }, | ||
| 120 | }; | ||
| 121 | } | ||
| 122 | |||
| 100 | pub fn muslArchNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 { | 123 | pub fn muslArchNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 { |
| 101 | return switch (arch) { | 124 | return switch (arch) { |
| 102 | .x86 => return "x86", | 125 | .x86 => "x86", |
| 103 | else => muslArchName(arch), | 126 | else => muslArchName(arch, .musl), |
| 104 | }; | 127 | }; |
| 105 | } | 128 | } |
| 106 | 129 | ||
| 107 | pub fn muslArchName(arch: std.Target.Cpu.Arch) [:0]const u8 { | 130 | pub fn muslAbiNameHeaders(abi: std.Target.Abi) [:0]const u8 { |
| 108 | switch (arch) { | 131 | return switch (abi) { |
| 109 | .aarch64, .aarch64_be => return "aarch64", | 132 | .muslx32 => "muslx32", |
| 110 | .arm, .armeb, .thumb, .thumbeb => return "arm", | 133 | else => "musl", |
| 111 | .x86 => return "i386", | 134 | }; |
| 112 | .loongarch64 => return "loongarch64", | ||
| 113 | .m68k => return "m68k", | ||
| 114 | .mips, .mipsel => return "mips", | ||
| 115 | .mips64el, .mips64 => return "mips64", | ||
| 116 | .powerpc => return "powerpc", | ||
| 117 | .powerpc64, .powerpc64le => return "powerpc64", | ||
| 118 | .riscv32 => return "riscv32", | ||
| 119 | .riscv64 => return "riscv64", | ||
| 120 | .s390x => return "s390x", | ||
| 121 | .wasm32, .wasm64 => return "wasm", | ||
| 122 | .x86_64 => return "x86_64", | ||
| 123 | else => unreachable, | ||
| 124 | } | ||
| 125 | } | 135 | } |
| 126 | 136 | ||
| 127 | pub fn isLibCLibName(target: std.Target, name: []const u8) bool { | 137 | pub fn isLibCLibName(target: std.Target, name: []const u8) bool { |
src/musl.zig+9-8| ... | @@ -4,7 +4,6 @@ const mem = std.mem; | ... | @@ -4,7 +4,6 @@ const mem = std.mem; |
| 4 | const path = std.fs.path; | 4 | const path = std.fs.path; |
| 5 | const assert = std.debug.assert; | 5 | const assert = std.debug.assert; |
| 6 | const Module = @import("Package/Module.zig"); | 6 | const Module = @import("Package/Module.zig"); |
| 7 | const archName = std.zig.target.muslArchName; | ||
| 8 | 7 | ||
| 9 | const Compilation = @import("Compilation.zig"); | 8 | const Compilation = @import("Compilation.zig"); |
| 10 | const build_options = @import("build_options"); | 9 | const build_options = @import("build_options"); |
| ... | @@ -113,7 +112,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro | ... | @@ -113,7 +112,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro |
| 113 | // When there is a src/<arch>/foo.* then it should substitute for src/foo.* | 112 | // When there is a src/<arch>/foo.* then it should substitute for src/foo.* |
| 114 | // Even a .s file can substitute for a .c file. | 113 | // Even a .s file can substitute for a .c file. |
| 115 | const target = comp.getTarget(); | 114 | const target = comp.getTarget(); |
| 116 | const arch_name = archName(target.cpu.arch); | 115 | const arch_name = std.zig.target.muslArchName(target.cpu.arch, target.abi); |
| 117 | var source_table = std.StringArrayHashMap(Ext).init(comp.gpa); | 116 | var source_table = std.StringArrayHashMap(Ext).init(comp.gpa); |
| 118 | defer source_table.deinit(); | 117 | defer source_table.deinit(); |
| 119 | 118 | ||
| ... | @@ -162,7 +161,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro | ... | @@ -162,7 +161,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro |
| 162 | 161 | ||
| 163 | var is_arch_specific = false; | 162 | var is_arch_specific = false; |
| 164 | // Architecture-specific implementations are under a <arch>/ folder. | 163 | // Architecture-specific implementations are under a <arch>/ folder. |
| 165 | if (isMuslArchName(dirbasename)) { | 164 | if (isArchName(dirbasename)) { |
| 166 | if (!mem.eql(u8, dirbasename, arch_name)) | 165 | if (!mem.eql(u8, dirbasename, arch_name)) |
| 167 | continue; // Not the architecture we're compiling for. | 166 | continue; // Not the architecture we're compiling for. |
| 168 | is_arch_specific = true; | 167 | is_arch_specific = true; |
| ... | @@ -327,7 +326,7 @@ pub fn needsCrt0(output_mode: std.builtin.OutputMode, link_mode: std.builtin.Lin | ... | @@ -327,7 +326,7 @@ pub fn needsCrt0(output_mode: std.builtin.OutputMode, link_mode: std.builtin.Lin |
| 327 | }; | 326 | }; |
| 328 | } | 327 | } |
| 329 | 328 | ||
| 330 | fn isMuslArchName(name: []const u8) bool { | 329 | fn isArchName(name: []const u8) bool { |
| 331 | const musl_arch_names = [_][]const u8{ | 330 | const musl_arch_names = [_][]const u8{ |
| 332 | "aarch64", | 331 | "aarch64", |
| 333 | "arm", | 332 | "arm", |
| ... | @@ -401,10 +400,12 @@ fn addCcArgs( | ... | @@ -401,10 +400,12 @@ fn addCcArgs( |
| 401 | want_O3: bool, | 400 | want_O3: bool, |
| 402 | ) error{OutOfMemory}!void { | 401 | ) error{OutOfMemory}!void { |
| 403 | const target = comp.getTarget(); | 402 | const target = comp.getTarget(); |
| 404 | const arch_name = archName(target.cpu.arch); | 403 | const arch_name = std.zig.target.muslArchName(target.cpu.arch, target.abi); |
| 405 | const os_name = @tagName(target.os.tag); | 404 | const os_name = @tagName(target.os.tag); |
| 406 | const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ | 405 | const triple = try std.fmt.allocPrint(arena, "{s}-{s}-{s}", .{ |
| 407 | std.zig.target.muslArchNameHeaders(target.cpu.arch), os_name, | 406 | std.zig.target.muslArchNameHeaders(target.cpu.arch), |
| 407 | os_name, | ||
| 408 | std.zig.target.muslAbiNameHeaders(target.abi), | ||
| 408 | }); | 409 | }); |
| 409 | const o_arg = if (want_O3) "-O3" else "-Os"; | 410 | const o_arg = if (want_O3) "-O3" else "-Os"; |
| 410 | 411 | ||
| ... | @@ -460,7 +461,7 @@ fn addCcArgs( | ... | @@ -460,7 +461,7 @@ fn addCcArgs( |
| 460 | fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { | 461 | fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { |
| 461 | const target = comp.getTarget(); | 462 | const target = comp.getTarget(); |
| 462 | return comp.zig_lib_directory.join(arena, &[_][]const u8{ | 463 | return comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 463 | "libc", "musl", "crt", archName(target.cpu.arch), basename, | 464 | "libc", "musl", "crt", std.zig.target.muslArchName(target.cpu.arch, target.abi), basename, |
| 464 | }); | 465 | }); |
| 465 | } | 466 | } |
| 466 | 467 |