authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-06 01:52:47+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-06 01:52:47+02:00
log35f30558ad2836b83859d8ba64a593a0603d4e0e
treedf204d0928ab8378e295a46acf5de3a1fb51c2e9
parenta14352b0b24b295e1857f306de5877680dd80d2b
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Build: Rename --glibc-runtimes to --libc-runtimes and enable it for musl.


4 files changed, 45 insertions(+), 30 deletions(-)

lib/compiler/build_runner.zig+7-5
...@@ -241,8 +241,9 @@ pub fn main() !void {...@@ -241,8 +241,9 @@ pub fn main() !void {
241 // but it is handled by the parent process. The build runner241 // but it is handled by the parent process. The build runner
242 // only sees this flag.242 // only sees this flag.
243 graph.system_package_mode = true;243 graph.system_package_mode = true;
244 } else if (mem.eql(u8, arg, "--glibc-runtimes")) {244 } else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {
245 builder.glibc_runtimes_dir = nextArgOrFatal(args, &arg_idx);245 // --glibc-runtimes was the old name of the flag; kept for compatibility for now.
246 builder.libc_runtimes_dir = nextArgOrFatal(args, &arg_idx);
246 } else if (mem.eql(u8, arg, "--verbose-link")) {247 } else if (mem.eql(u8, arg, "--verbose-link")) {
247 builder.verbose_link = true;248 builder.verbose_link = true;
248 } else if (mem.eql(u8, arg, "--verbose-air")) {249 } else if (mem.eql(u8, arg, "--verbose-air")) {
...@@ -1279,9 +1280,10 @@ fn usage(b: *std.Build, out_stream: anytype) !void {...@@ -1279,9 +1280,10 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
1279 \\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute1280 \\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute
1280 \\ foreign-architecture programs on Linux hosts1281 \\ foreign-architecture programs on Linux hosts
1281 \\ (default: no)1282 \\ (default: no)
1282 \\ --glibc-runtimes [path] Enhances QEMU integration by providing glibc built1283 \\ --libc-runtimes [path] Enhances QEMU integration by providing dynamic libc
1283 \\ for multiple foreign architectures, allowing1284 \\ (e.g. glibc or musl) built for multiple foreign
1284 \\ execution of non-native programs that link with glibc.1285 \\ architectures, allowing execution of non-native
1286 \\ programs that link with libc.
1285 \\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on1287 \\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on
1286 \\ ARM64 macOS hosts. (default: no)1288 \\ ARM64 macOS hosts. (default: no)
1287 \\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to1289 \\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to
lib/std/Build.zig+3-2
...@@ -79,7 +79,8 @@ enable_wine: bool = false,...@@ -79,7 +79,8 @@ enable_wine: bool = false,
79/// this will be the directory $glibc-build-dir/install/glibcs79/// this will be the directory $glibc-build-dir/install/glibcs
80/// Given the example of the aarch64 target, this is the directory80/// Given the example of the aarch64 target, this is the directory
81/// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.81/// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
82glibc_runtimes_dir: ?[]const u8 = null,82/// Also works for dynamic musl.
83libc_runtimes_dir: ?[]const u8 = null,
8384
84dep_prefix: []const u8 = "",85dep_prefix: []const u8 = "",
8586
...@@ -390,7 +391,7 @@ fn createChildOnly(...@@ -390,7 +391,7 @@ fn createChildOnly(
390 .enable_rosetta = parent.enable_rosetta,391 .enable_rosetta = parent.enable_rosetta,
391 .enable_wasmtime = parent.enable_wasmtime,392 .enable_wasmtime = parent.enable_wasmtime,
392 .enable_wine = parent.enable_wine,393 .enable_wine = parent.enable_wine,
393 .glibc_runtimes_dir = parent.glibc_runtimes_dir,394 .libc_runtimes_dir = parent.libc_runtimes_dir,
394 .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),395 .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),
395 .modules = .init(allocator),396 .modules = .init(allocator),
396 .named_writefiles = .init(allocator),397 .named_writefiles = .init(allocator),
lib/std/Build/Step/Run.zig+21-23
...@@ -1026,11 +1026,11 @@ fn runCommand(...@@ -1026,11 +1026,11 @@ fn runCommand(
1026 }1026 }
10271027
1028 const root_target = exe.rootModuleTarget();1028 const root_target = exe.rootModuleTarget();
1029 const need_cross_glibc = root_target.isGnuLibC() and1029 const need_cross_libc = exe.is_linking_libc and
1030 exe.is_linking_libc;1030 (root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
1031 const other_target = exe.root_module.resolved_target.?.result;1031 const other_target = exe.root_module.resolved_target.?.result;
1032 switch (std.zig.system.getExternalExecutor(b.graph.host.result, &other_target, .{1032 switch (std.zig.system.getExternalExecutor(b.graph.host.result, &other_target, .{
1033 .qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null,1033 .qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
1034 .link_libc = exe.is_linking_libc,1034 .link_libc = exe.is_linking_libc,
1035 })) {1035 })) {
1036 .native, .rosetta => {1036 .native, .rosetta => {
...@@ -1047,31 +1047,29 @@ fn runCommand(...@@ -1047,31 +1047,29 @@ fn runCommand(
1047 },1047 },
1048 .qemu => |bin_name| {1048 .qemu => |bin_name| {
1049 if (b.enable_qemu) {1049 if (b.enable_qemu) {
1050 const glibc_dir_arg = if (need_cross_glibc)
1051 b.glibc_runtimes_dir orelse
1052 return failForeign(run, "--glibc-runtimes", argv[0], exe)
1053 else
1054 null;
1055
1056 try interp_argv.append(bin_name);1050 try interp_argv.append(bin_name);
10571051
1058 if (glibc_dir_arg) |dir| {1052 if (need_cross_libc) {
1059 try interp_argv.append("-L");1053 if (b.libc_runtimes_dir) |dir| {
1060 try interp_argv.append(b.pathJoin(&.{1054 try interp_argv.append("-L");
1061 dir,1055 try interp_argv.append(b.pathJoin(&.{
1062 try std.zig.target.glibcRuntimeTriple(1056 dir,
1063 b.allocator,1057 try if (root_target.isGnuLibC()) std.zig.target.glibcRuntimeTriple(
1064 root_target.cpu.arch,1058 b.allocator,
1065 root_target.os.tag,1059 root_target.cpu.arch,
1066 root_target.abi,1060 root_target.os.tag,
1067 ),1061 root_target.abi,
1068 }));1062 ) else if (root_target.isMuslLibC()) std.zig.target.muslRuntimeTriple(
1063 b.allocator,
1064 root_target.cpu.arch,
1065 root_target.abi,
1066 ) else unreachable,
1067 }));
1068 } else return failForeign(run, "--libc-runtimes", argv[0], exe);
1069 }1069 }
10701070
1071 try interp_argv.appendSlice(argv);1071 try interp_argv.appendSlice(argv);
1072 } else {1072 } else return failForeign(run, "-fqemu", argv[0], exe);
1073 return failForeign(run, "-fqemu", argv[0], exe);
1074 }
1075 },1073 },
1076 .darling => |bin_name| {1074 .darling => |bin_name| {
1077 if (b.enable_darling) {1075 if (b.enable_darling) {
lib/std/zig/target.zig+14
...@@ -131,6 +131,20 @@ pub fn glibcRuntimeTriple(...@@ -131,6 +131,20 @@ pub fn glibcRuntimeTriple(
131 };131 };
132}132}
133133
134/// Returns the subdirectory triple to be used to find the correct musl for the given `arch` and
135/// `abi` in an installation directory.
136///
137/// `abi` must be a musl ABI, i.e. `.isMusl()`.
138pub fn muslRuntimeTriple(
139 allocator: Allocator,
140 arch: std.Target.Cpu.Arch,
141 abi: std.Target.Abi,
142) Allocator.Error![]const u8 {
143 assert(abi.isMusl());
144
145 return std.Target.linuxTripleSimple(allocator, arch, .linux, abi);
146}
147
134pub fn osArchName(target: std.Target) [:0]const u8 {148pub fn osArchName(target: std.Target) [:0]const u8 {
135 return switch (target.os.tag) {149 return switch (target.os.tag) {
136 .linux => switch (target.cpu.arch) {150 .linux => switch (target.cpu.arch) {