authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-10-06 08:08:35-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-10-06 08:08:58-04:00
loge9b646943f609486de509375f5d3730ef4b775cd
tree5d6c80179c71769baa77014843411817b54dd9fb
parentbff490a23889750de7096d9057c0a432efc929a8

Maker: preemtively pass `QEMU_LD_PREFIX` to run steps

This has no effect unless both `-fqemu` and `--libc-runtimes` are passed, so the impact should be fairly minimal.

1 files changed, 35 insertions(+), 0 deletions(-)

lib/compiler/Maker/Step/Run.zig+35
......@@ -2221,6 +2221,41 @@ fn runCommand(
22212221 }
22222222 }
22232223
2224 if (graph.enable_qemu) runtime_dir: {
2225 const libc_runtimes_dir = graph.libc_runtimes_dir orelse break :runtime_dir;
2226 if (environ_map.contains("QEMU_LD_PREFIX")) break :runtime_dir;
2227
2228 const producer_index = arg0.producer.value orelse break :runtime_dir;
2229 const producer_step = producer_index.ptr(conf);
2230 const producer = producer_step.extended.get(conf.extra).compile;
2231 switch (producer.flags3.kind) {
2232 .exe, .@"test" => {},
2233 else => break :runtime_dir,
2234 }
2235 const root_module = producer.root_module.get(conf);
2236 const root_module_target = root_module.resolved_target.get(conf).?.result.get(conf);
2237 const root_target = root_module_target.unwrapTarget(conf);
2238 const config = maker.stepByIndex(producer_index).extended.compile.config.?;
2239
2240 const need_cross_libc = root_target.os.tag == .linux and
2241 config.flags.link_libc and config.flags.link_mode == .dynamic;
2242 if (!need_cross_libc) break :runtime_dir;
2243
2244 try environ_map.put("QEMU_LD_PREFIX", try Dir.path.join(graph.arena, &.{
2245 libc_runtimes_dir,
2246 try if (root_target.isGnuLibC()) std.zig.target.glibcRuntimeTriple(
2247 graph.arena,
2248 root_target.cpu.arch,
2249 root_target.os.tag,
2250 root_target.abi,
2251 ) else if (root_target.isMuslLibC()) std.zig.target.muslRuntimeTriple(
2252 graph.arena,
2253 root_target.cpu.arch,
2254 root_target.abi,
2255 ) else unreachable,
2256 }));
2257 }
2258
22242259 const cwd_string = switch (cwd) {
22252260 .path => |p| p,
22262261 .dir => unreachable,