Pass allocator to zig.system.resolveTargetQuery

For now the allocator is only used in `detectAndroidApiLevel`, but there
are probably other places in the detection logic that could benefit from
this too.
This commit is contained in:
Luna Schwalbe 2025-09-05 16:36:14 +02:00
parent c2cd8df622
commit b7264937d4
No known key found for this signature in database
GPG key ID: 7E20C1B6E0766C1D
19 changed files with 59 additions and 50 deletions

View file

@ -1017,7 +1017,7 @@ fn parseTarget(d: *Driver, arch_os_abi: []const u8, opt_cpu_features: ?[]const u
} }
} }
const zig_target = std.zig.system.resolveTargetQuery(d.comp.io, query) catch |e| const zig_target = std.zig.system.resolveTargetQuery(d.comp.io, d.comp.gpa, query) catch |e|
return d.fatal("unable to resolve target: {s}", .{errorDescription(e)}); return d.fatal("unable to resolve target: {s}", .{errorDescription(e)});
if (query.isNative()) { if (query.isNative()) {

View file

@ -83,7 +83,7 @@ test "minUnsignedBits" {
var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, std.fs.cwd()); var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, std.fs.cwd());
defer comp.deinit(); defer comp.deinit();
const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" }); const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query)); comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, comp.gpa, target_query));
try Test.checkIntBits(&comp, 0, 0); try Test.checkIntBits(&comp, 0, 0);
try Test.checkIntBits(&comp, 1, 1); try Test.checkIntBits(&comp, 1, 1);
@ -122,7 +122,7 @@ test "minSignedBits" {
var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, std.fs.cwd()); var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, std.fs.cwd());
defer comp.deinit(); defer comp.deinit();
const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" }); const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query)); comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, comp.gpa, target_query));
try Test.checkIntBits(&comp, -1, 1); try Test.checkIntBits(&comp, -1, 1);
try Test.checkIntBits(&comp, -2, 2); try Test.checkIntBits(&comp, -2, 2);

View file

@ -87,7 +87,7 @@ pub fn main() !void {
.zig_lib_directory = zig_lib_directory, .zig_lib_directory = zig_lib_directory,
.host = .{ .host = .{
.query = .{}, .query = .{},
.result = try std.zig.system.resolveTargetQuery(io, .{}), .result = try std.zig.system.resolveTargetQuery(io, arena, .{}),
}, },
.time_report = false, .time_report = false,
}; };

View file

@ -70,7 +70,7 @@ pub fn main() !void {
const target_query = std.zig.parseTargetQueryOrReportFatalError(gpa, .{ const target_query = std.zig.parseTargetQueryOrReportFatalError(gpa, .{
.arch_os_abi = target_arch_os_abi, .arch_os_abi = target_arch_os_abi,
}); });
const target = std.zig.resolveTargetQueryOrFatal(io, target_query); const target = std.zig.resolveTargetQueryOrFatal(io, gpa, target_query);
if (print_includes) { if (print_includes) {
const libc_installation: ?*LibCInstallation = libc: { const libc_installation: ?*LibCInstallation = libc: {

View file

@ -616,7 +616,7 @@ fn getIncludePaths(
.cpu_arch = includes_arch, .cpu_arch = includes_arch,
.abi = .msvc, .abi = .msvc,
}; };
const target = std.zig.resolveTargetQueryOrFatal(io, target_query); const target = std.zig.resolveTargetQueryOrFatal(io, arena, target_query);
const is_native_abi = target_query.isNativeAbi(); const is_native_abi = target_query.isNativeAbi();
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch { const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch {
if (includes == .any) { if (includes == .any) {
@ -642,7 +642,7 @@ fn getIncludePaths(
.cpu_arch = includes_arch, .cpu_arch = includes_arch,
.abi = .gnu, .abi = .gnu,
}; };
const target = std.zig.resolveTargetQueryOrFatal(io, target_query); const target = std.zig.resolveTargetQueryOrFatal(io, arena, target_query);
const is_native_abi = target_query.isNativeAbi(); const is_native_abi = target_query.isNativeAbi();
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) { const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) {
error.OutOfMemory => |e| return e, error.OutOfMemory => |e| return e,

View file

@ -255,10 +255,13 @@ fn serveWasm(
const wasm_base_path = try buildWasmBinary(arena, context, optimize_mode); const wasm_base_path = try buildWasmBinary(arena, context, optimize_mode);
const bin_name = try std.zig.binNameAlloc(arena, .{ const bin_name = try std.zig.binNameAlloc(arena, .{
.root_name = autodoc_root_name, .root_name = autodoc_root_name,
.target = &(std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{ .target = &(std.zig.system.resolveTargetQuery(gpa, std.Build.parseTargetQuery(.{
.arch_os_abi = autodoc_arch_os_abi, .arch_os_abi = autodoc_arch_os_abi,
.cpu_features = autodoc_cpu_features, .cpu_features = autodoc_cpu_features,
}) catch unreachable) catch unreachable), }) catch unreachable) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => unreachable,
}),
.output_mode = .Exe, .output_mode = .Exe,
}); });
// std.http.Server does not have a sendfile API yet. // std.http.Server does not have a sendfile API yet.

View file

@ -2664,7 +2664,7 @@ pub fn resolveTargetQuery(b: *Build, query: Target.Query) ResolvedTarget {
const io = b.graph.io; const io = b.graph.io;
return .{ return .{
.query = query, .query = query,
.result = std.zig.system.resolveTargetQuery(io, query) catch .result = std.zig.system.resolveTargetQuery(io, b.allocator, query) catch
@panic("unable to resolve target query"), @panic("unable to resolve target query"),
}; };
} }

View file

@ -551,7 +551,7 @@ test Options {
.global_cache_root = .{ .path = "test", .handle = std.fs.cwd() }, .global_cache_root = .{ .path = "test", .handle = std.fs.cwd() },
.host = .{ .host = .{
.query = .{}, .query = .{},
.result = try std.zig.system.resolveTargetQuery(io, .{}), .result = try std.zig.system.resolveTargetQuery(io, arena.allocator(), .{}),
}, },
.zig_lib_directory = std.Build.Cache.Directory.cwd(), .zig_lib_directory = std.Build.Cache.Directory.cwd(),
.time_report = false, .time_report = false,

View file

@ -673,10 +673,13 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
}; };
const bin_name = try std.zig.binNameAlloc(arena, .{ const bin_name = try std.zig.binNameAlloc(arena, .{
.root_name = root_name, .root_name = root_name,
.target = &(std.zig.system.resolveTargetQuery(io, std.Build.parseTargetQuery(.{ .target = &(std.zig.system.resolveTargetQuery(io, ws.gpa, std.Build.parseTargetQuery(.{
.arch_os_abi = arch_os_abi, .arch_os_abi = arch_os_abi,
.cpu_features = cpu_features, .cpu_features = cpu_features,
}) catch unreachable) catch unreachable), }) catch unreachable) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => unreachable,
}),
.output_mode = .Exe, .output_mode = .Exe,
}); });
return base_path.join(arena, bin_name); return base_path.join(arena, bin_name);

View file

@ -663,7 +663,7 @@ test parse {
.arch_os_abi = "x86_64-linux-gnu", .arch_os_abi = "x86_64-linux-gnu",
.cpu_features = "x86_64-sse-sse2-avx-cx8", .cpu_features = "x86_64-sse-sse2-avx-cx8",
}); });
const target = try std.zig.system.resolveTargetQuery(io, query); const target = try std.zig.system.resolveTargetQuery(io, std.testing.allocator, query);
try std.testing.expect(target.os.tag == .linux); try std.testing.expect(target.os.tag == .linux);
try std.testing.expect(target.abi == .gnu); try std.testing.expect(target.abi == .gnu);
@ -688,7 +688,7 @@ test parse {
.arch_os_abi = "arm-linux-musleabihf", .arch_os_abi = "arm-linux-musleabihf",
.cpu_features = "generic+v8a", .cpu_features = "generic+v8a",
}); });
const target = try std.zig.system.resolveTargetQuery(io, query); const target = try std.zig.system.resolveTargetQuery(io, std.testing.allocator, query);
try std.testing.expect(target.os.tag == .linux); try std.testing.expect(target.os.tag == .linux);
try std.testing.expect(target.abi == .musleabihf); try std.testing.expect(target.abi == .musleabihf);
@ -705,7 +705,7 @@ test parse {
.arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27", .arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27",
.cpu_features = "generic+v8a", .cpu_features = "generic+v8a",
}); });
const target = try std.zig.system.resolveTargetQuery(io, query); const target = try std.zig.system.resolveTargetQuery(io, std.testing.allocator, query);
try std.testing.expect(target.cpu.arch == .aarch64); try std.testing.expect(target.cpu.arch == .aarch64);
try std.testing.expect(target.os.tag == .linux); try std.testing.expect(target.os.tag == .linux);
@ -728,7 +728,7 @@ test parse {
const query = try Query.parse(.{ const query = try Query.parse(.{
.arch_os_abi = "aarch64-linux.3.10...4.4.1-android.30", .arch_os_abi = "aarch64-linux.3.10...4.4.1-android.30",
}); });
const target = try std.zig.system.resolveTargetQuery(io, query); const target = try std.zig.system.resolveTargetQuery(io, std.testing.allocator, query);
try std.testing.expect(target.cpu.arch == .aarch64); try std.testing.expect(target.cpu.arch == .aarch64);
try std.testing.expect(target.os.tag == .linux); try std.testing.expect(target.os.tag == .linux);
@ -749,7 +749,7 @@ test parse {
const query = try Query.parse(.{ const query = try Query.parse(.{
.arch_os_abi = "x86-windows.xp...win8-msvc", .arch_os_abi = "x86-windows.xp...win8-msvc",
}); });
const target = try std.zig.system.resolveTargetQuery(io, query); const target = try std.zig.system.resolveTargetQuery(io, std.testing.allocator, query);
try std.testing.expect(target.cpu.arch == .x86); try std.testing.expect(target.cpu.arch == .x86);
try std.testing.expect(target.os.tag == .windows); try std.testing.expect(target.os.tag == .windows);

View file

@ -663,8 +663,8 @@ pub fn putAstErrorsIntoBundle(
try wip_errors.addZirErrorMessages(zir, tree, tree.source, path); try wip_errors.addZirErrorMessages(zir, tree, tree.source, path);
} }
pub fn resolveTargetQueryOrFatal(io: Io, target_query: std.Target.Query) std.Target { pub fn resolveTargetQueryOrFatal(io: Io, gpa: Allocator, target_query: std.Target.Query) std.Target {
return std.zig.system.resolveTargetQuery(io, target_query) catch |err| return std.zig.system.resolveTargetQuery(io, gpa, target_query) catch |err|
std.process.fatal("unable to resolve target: {s}", .{@errorName(err)}); std.process.fatal("unable to resolve target: {s}", .{@errorName(err)});
} }

View file

@ -8,6 +8,7 @@ const Target = std.Target;
const native_endian = builtin.cpu.arch.endian(); const native_endian = builtin.cpu.arch.endian();
const posix = std.posix; const posix = std.posix;
const Io = std.Io; const Io = std.Io;
const Allocator = mem.Allocator;
pub const NativePaths = @import("system/NativePaths.zig"); pub const NativePaths = @import("system/NativePaths.zig");
@ -201,6 +202,7 @@ pub fn getExternalExecutor(
} }
pub const DetectError = error{ pub const DetectError = error{
OutOfMemory,
FileSystem, FileSystem,
SystemResources, SystemResources,
SymLinkLoop, SymLinkLoop,
@ -219,7 +221,7 @@ pub const DetectError = error{
/// and which are provided explicitly, this function resolves the native /// and which are provided explicitly, this function resolves the native
/// components by detecting the native system, and then resolves /// components by detecting the native system, and then resolves
/// standard/default parts relative to that. /// standard/default parts relative to that.
pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target { pub fn resolveTargetQuery(io: Io, gpa: Allocator, query: Target.Query) DetectError!Target {
// Until https://github.com/ziglang/zig/issues/4592 is implemented (support detecting the // Until https://github.com/ziglang/zig/issues/4592 is implemented (support detecting the
// native CPU architecture as being different than the current target), we use this: // native CPU architecture as being different than the current target), we use this:
const query_cpu_arch = query.cpu_arch orelse builtin.cpu.arch; const query_cpu_arch = query.cpu_arch orelse builtin.cpu.arch;
@ -503,7 +505,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
} }
if (builtin.os.tag == .linux and result.isBionicLibC() and query.os_tag == null and query.android_api_level == null) { if (builtin.os.tag == .linux and result.isBionicLibC() and query.os_tag == null and query.android_api_level == null) {
result.os.version_range.linux.android = detectAndroidApiLevel(io) catch |err| return switch (err) { result.os.version_range.linux.android = detectAndroidApiLevel(io, gpa) catch |err| return switch (err) {
error.InvalidWtf8, error.InvalidWtf8,
error.CurrentWorkingDirectoryUnlinked, error.CurrentWorkingDirectoryUnlinked,
error.InvalidBatchScriptArg, error.InvalidBatchScriptArg,
@ -513,6 +515,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
else => blk: { else => blk: {
std.log.err("spawning or reading from getprop failed ({s})", .{@errorName(err)}); std.log.err("spawning or reading from getprop failed ({s})", .{@errorName(err)});
switch (err) { switch (err) {
error.OutOfMemory,
error.SystemResources, error.SystemResources,
error.FileSystem, error.FileSystem,
error.ProcessFdQuotaExceeded, error.ProcessFdQuotaExceeded,
@ -1158,14 +1161,10 @@ const LdInfo = struct {
abi: Target.Abi, abi: Target.Abi,
}; };
fn detectAndroidApiLevel(io: Io) !u32 { fn detectAndroidApiLevel(io: Io, gpa: Allocator) !u32 {
comptime if (builtin.os.tag != .linux) unreachable; comptime if (builtin.os.tag != .linux) unreachable;
// `child.spawn()` uses an arena and the exact memory requirement isn't easily determined, var child = std.process.Child.init(&.{ "/system/bin/getprop", "ro.build.version.sdk" }, gpa);
// so we give it 128 * 3 bytes, which was shown in testing to be enough.
var alloc_buf: [128 * 3]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&alloc_buf);
var child = std.process.Child.init(&.{ "/system/bin/getprop", "ro.build.version.sdk" }, fba.allocator());
// pass empty EnvMap, no allocator and deinit() required // pass empty EnvMap, no allocator and deinit() required
child.env_map = &std.process.EnvMap.init(undefined); child.env_map = &std.process.EnvMap.init(undefined);
child.stdin_behavior = .Ignore; child.stdin_behavior = .Ignore;

View file

@ -5348,7 +5348,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
const optimize_mode = std.builtin.OptimizeMode.ReleaseSmall; const optimize_mode = std.builtin.OptimizeMode.ReleaseSmall;
const output_mode = std.builtin.OutputMode.Exe; const output_mode = std.builtin.OutputMode.Exe;
const resolved_target: Package.Module.ResolvedTarget = .{ const resolved_target: Package.Module.ResolvedTarget = .{
.result = std.zig.system.resolveTargetQuery(io, .{ .result = std.zig.system.resolveTargetQuery(io, gpa, .{
.cpu_arch = .wasm32, .cpu_arch = .wasm32,
.os_tag = .freestanding, .os_tag = .freestanding,
.cpu_features_add = std.Target.wasm.featureSet(&.{ .cpu_features_add = std.Target.wasm.featureSet(&.{
@ -5361,7 +5361,10 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
//.simd128, //.simd128,
// .tail_call, not supported by Safari // .tail_call, not supported by Safari
}), }),
}) catch unreachable, }) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => unreachable,
},
.is_native_os = false, .is_native_os = false,
.is_native_abi = false, .is_native_abi = false,

View file

@ -335,7 +335,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
return cmdInit(gpa, arena, cmd_args); return cmdInit(gpa, arena, cmd_args);
} else if (mem.eql(u8, cmd, "targets")) { } else if (mem.eql(u8, cmd, "targets")) {
dev.check(.targets_command); dev.check(.targets_command);
const host = std.zig.resolveTargetQueryOrFatal(io, .{}); const host = std.zig.resolveTargetQueryOrFatal(io, gpa, .{});
var stdout_writer = fs.File.stdout().writer(&stdout_buffer); var stdout_writer = fs.File.stdout().writer(&stdout_buffer);
try @import("print_targets.zig").cmdTargets(arena, cmd_args, &stdout_writer.interface, &host); try @import("print_targets.zig").cmdTargets(arena, cmd_args, &stdout_writer.interface, &host);
return stdout_writer.interface.flush(); return stdout_writer.interface.flush();
@ -345,7 +345,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
return; return;
} else if (mem.eql(u8, cmd, "env")) { } else if (mem.eql(u8, cmd, "env")) {
dev.check(.env_command); dev.check(.env_command);
const host = std.zig.resolveTargetQueryOrFatal(io, .{}); const host = std.zig.resolveTargetQueryOrFatal(io, gpa, .{});
var stdout_writer = fs.File.stdout().writer(&stdout_buffer); var stdout_writer = fs.File.stdout().writer(&stdout_buffer);
try @import("print_env.zig").cmdEnv( try @import("print_env.zig").cmdEnv(
arena, arena,
@ -369,7 +369,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
} else if (mem.eql(u8, cmd, "ast-check")) { } else if (mem.eql(u8, cmd, "ast-check")) {
return cmdAstCheck(arena, io, cmd_args); return cmdAstCheck(arena, io, cmd_args);
} else if (mem.eql(u8, cmd, "detect-cpu")) { } else if (mem.eql(u8, cmd, "detect-cpu")) {
return cmdDetectCpu(io, cmd_args); return cmdDetectCpu(io, gpa, cmd_args);
} else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "changelist")) { } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "changelist")) {
return cmdChangelist(arena, io, cmd_args); return cmdChangelist(arena, io, cmd_args);
} else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) { } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) {
@ -3802,7 +3802,7 @@ fn createModule(
} }
const target_query = std.zig.parseTargetQueryOrReportFatalError(arena, target_parse_options); const target_query = std.zig.parseTargetQueryOrReportFatalError(arena, target_parse_options);
const target = std.zig.resolveTargetQueryOrFatal(io, target_query); const target = std.zig.resolveTargetQueryOrFatal(io, gpa, target_query);
break :t .{ break :t .{
.result = target, .result = target,
.is_native_os = target_query.isNativeOs(), .is_native_os = target_query.isNativeOs(),
@ -4364,7 +4364,7 @@ fn runOrTest(
std.debug.lockStdErr(); std.debug.lockStdErr();
const err = process.execve(gpa, argv.items, &env_map); const err = process.execve(gpa, argv.items, &env_map);
std.debug.unlockStdErr(); std.debug.unlockStdErr();
try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc); try warnAboutForeignBinaries(io, gpa, arena, arg_mode, target, link_libc);
const cmd = try std.mem.join(arena, " ", argv.items); const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd }); fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
} else if (process.can_spawn) { } else if (process.can_spawn) {
@ -4385,7 +4385,7 @@ fn runOrTest(
break :t child.spawnAndWait(); break :t child.spawnAndWait();
}; };
const term = term_result catch |err| { const term = term_result catch |err| {
try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc); try warnAboutForeignBinaries(io, gpa, arena, arg_mode, target, link_libc);
const cmd = try std.mem.join(arena, " ", argv.items); const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd }); fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });
}; };
@ -5016,7 +5016,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
.arch_os_abi = triple, .arch_os_abi = triple,
}); });
break :t .{ break :t .{
.result = std.zig.resolveTargetQueryOrFatal(io, target_query), .result = std.zig.resolveTargetQueryOrFatal(io, gpa, target_query),
.is_native_os = false, .is_native_os = false,
.is_native_abi = false, .is_native_abi = false,
.is_explicit_dynamic_linker = false, .is_explicit_dynamic_linker = false,
@ -5024,7 +5024,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
} }
} }
break :t .{ break :t .{
.result = std.zig.resolveTargetQueryOrFatal(io, .{}), .result = std.zig.resolveTargetQueryOrFatal(io, gpa, .{}),
.is_native_os = true, .is_native_os = true,
.is_native_abi = true, .is_native_abi = true,
.is_explicit_dynamic_linker = false, .is_explicit_dynamic_linker = false,
@ -5445,7 +5445,7 @@ fn jitCmd(
const target_query: std.Target.Query = .{}; const target_query: std.Target.Query = .{};
const resolved_target: Package.Module.ResolvedTarget = .{ const resolved_target: Package.Module.ResolvedTarget = .{
.result = std.zig.resolveTargetQueryOrFatal(io, target_query), .result = std.zig.resolveTargetQueryOrFatal(io, gpa, target_query),
.is_native_os = true, .is_native_os = true,
.is_native_abi = true, .is_native_abi = true,
.is_explicit_dynamic_linker = false, .is_explicit_dynamic_linker = false,
@ -6239,7 +6239,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
} }
} }
fn cmdDetectCpu(io: Io, args: []const []const u8) !void { fn cmdDetectCpu(io: Io, gpa: Allocator, args: []const []const u8) !void {
dev.check(.detect_cpu_command); dev.check(.detect_cpu_command);
const detect_cpu_usage = const detect_cpu_usage =
@ -6284,7 +6284,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
const cpu = try detectNativeCpuWithLLVM(builtin.cpu.arch, name, features); const cpu = try detectNativeCpuWithLLVM(builtin.cpu.arch, name, features);
try printCpu(cpu); try printCpu(cpu);
} else { } else {
const host_target = std.zig.resolveTargetQueryOrFatal(io, .{}); const host_target = std.zig.resolveTargetQueryOrFatal(io, gpa, .{});
try printCpu(host_target.cpu); try printCpu(host_target.cpu);
} }
} }
@ -6546,13 +6546,14 @@ fn prefixedIntArg(arg: []const u8, prefix: []const u8) ?u64 {
fn warnAboutForeignBinaries( fn warnAboutForeignBinaries(
io: Io, io: Io,
gpa: Allocator,
arena: Allocator, arena: Allocator,
arg_mode: ArgMode, arg_mode: ArgMode,
target: *const std.Target, target: *const std.Target,
link_libc: bool, link_libc: bool,
) !void { ) !void {
const host_query: std.Target.Query = .{}; const host_query: std.Target.Query = .{};
const host_target = std.zig.resolveTargetQueryOrFatal(io, host_query); const host_target = std.zig.resolveTargetQueryOrFatal(io, gpa, host_query);
switch (std.zig.system.getExternalExecutor(&host_target, target, .{ .link_libc = link_libc })) { switch (std.zig.system.getExternalExecutor(&host_target, target, .{ .link_libc = link_libc })) {
.native => return, .native => return,

View file

@ -133,7 +133,7 @@ fn printOutput(
var env_map = try process.getEnvMap(arena); var env_map = try process.getEnvMap(arena);
try env_map.put("CLICOLOR_FORCE", "1"); try env_map.put("CLICOLOR_FORCE", "1");
const host = try std.zig.system.resolveTargetQuery(io, .{}); const host = try std.zig.system.resolveTargetQuery(io, arena, .{});
const obj_ext = builtin.object_format.fileExt(builtin.cpu.arch); const obj_ext = builtin.object_format.fileExt(builtin.cpu.arch);
const print = std.debug.print; const print = std.debug.print;
@ -248,7 +248,7 @@ fn printOutput(
const target_query = try std.Target.Query.parse(.{ const target_query = try std.Target.Query.parse(.{
.arch_os_abi = code.target_str orelse "native", .arch_os_abi = code.target_str orelse "native",
}); });
const target = try std.zig.system.resolveTargetQuery(io, target_query); const target = try std.zig.system.resolveTargetQuery(io, arena, target_query);
const path_to_exe = try std.fmt.allocPrint(arena, "./{s}{s}", .{ const path_to_exe = try std.fmt.allocPrint(arena, "./{s}{s}", .{
code_name, target.exeFileExt(), code_name, target.exeFileExt(),
@ -326,7 +326,7 @@ fn printOutput(
const target_query = try std.Target.Query.parse(.{ const target_query = try std.Target.Query.parse(.{
.arch_os_abi = triple, .arch_os_abi = triple,
}); });
const target = try std.zig.system.resolveTargetQuery(io, target_query); const target = try std.zig.system.resolveTargetQuery(io, arena, target_query);
switch (getExternalExecutor(&host, &target, .{ switch (getExternalExecutor(&host, &target, .{
.link_libc = code.link_libc, .link_libc = code.link_libc,
})) { })) {

View file

@ -32,7 +32,7 @@ pub fn main() !void {
, .{if (args.len == 0) "dump-cov" else args[0]}), , .{if (args.len == 0) "dump-cov" else args[0]}),
}; };
const target = std.zig.resolveTargetQueryOrFatal(io, try .parse(.{ const target = std.zig.resolveTargetQueryOrFatal(io, gpa, try .parse(.{
.arch_os_abi = target_query_str, .arch_os_abi = target_query_str,
})); }));

View file

@ -91,7 +91,7 @@ pub fn main() anyerror!void {
const io = threaded.io(); const io = threaded.io();
const sysroot_path = sysroot orelse blk: { const sysroot_path = sysroot orelse blk: {
const target = try std.zig.system.resolveTargetQuery(io, .{}); const target = try std.zig.system.resolveTargetQuery(io, gpa, .{});
break :blk std.zig.system.darwin.getSdk(allocator, &target) orelse break :blk std.zig.system.darwin.getSdk(allocator, &target) orelse
fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{}); fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{});
}; };

View file

@ -44,7 +44,7 @@ pub fn main() !void {
const io = threaded.io(); const io = threaded.io();
const query = try std.Target.Query.parse(.{ .arch_os_abi = args[1] }); const query = try std.Target.Query.parse(.{ .arch_os_abi = args[1] });
const target = try std.zig.system.resolveTargetQuery(io, query); const target = try std.zig.system.resolveTargetQuery(io, gpa, query);
var buffer: [2000]u8 = undefined; var buffer: [2000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer); var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);

View file

@ -93,7 +93,7 @@ pub fn main() !void {
else else
null; null;
const host = try std.zig.system.resolveTargetQuery(io, .{}); const host = try std.zig.system.resolveTargetQuery(io, arena, .{});
const debug_log_verbose = debug_zcu or debug_dwarf or debug_link; const debug_log_verbose = debug_zcu or debug_dwarf or debug_link;
@ -697,7 +697,7 @@ const Case = struct {
}, },
}) catch fatal("line {d}: invalid target query '{s}'", .{ line_n, query }); }) catch fatal("line {d}: invalid target query '{s}'", .{ line_n, query });
const resolved = try std.zig.system.resolveTargetQuery(io, parsed_query); const resolved = try std.zig.system.resolveTargetQuery(io, arena, parsed_query);
try targets.append(arena, .{ try targets.append(arena, .{
.query = query, .query = query,