aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-06-13 04:46:30 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2025-06-19 11:45:06 -0400
commit917640810e7f3e18daff9e75b5ecefe761a1896c (patch)
tree579e627d695f898d411a3cb1fbc0578d1a763cc2 /lib/std/Build
parent16d78bc0c024da307c7ab5f6b94622e6b4b37397 (diff)
downloadzig-917640810e7f3e18daff9e75b5ecefe761a1896c.tar.gz
zig-917640810e7f3e18daff9e75b5ecefe761a1896c.zip
Target: pass and use locals by pointer instead of by value
This struct is larger than 256 bytes and code that copies it consistently shows up in profiles of the compiler.
Diffstat (limited to 'lib/std/Build')
-rw-r--r--lib/std/Build/Fuzz/WebServer.zig4
-rw-r--r--lib/std/Build/Module.zig8
-rw-r--r--lib/std/Build/Step/Compile.zig4
-rw-r--r--lib/std/Build/Step/Run.zig2
4 files changed, 9 insertions, 9 deletions
diff --git a/lib/std/Build/Fuzz/WebServer.zig b/lib/std/Build/Fuzz/WebServer.zig
index 87cd7a1a1d..ab44d4e7af 100644
--- a/lib/std/Build/Fuzz/WebServer.zig
+++ b/lib/std/Build/Fuzz/WebServer.zig
@@ -198,10 +198,10 @@ fn serveWasm(
const wasm_base_path = try buildWasmBinary(ws, arena, optimize_mode);
const bin_name = try std.zig.binNameAlloc(arena, .{
.root_name = fuzzer_bin_name,
- .target = std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{
+ .target = &(std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{
.arch_os_abi = fuzzer_arch_os_abi,
.cpu_features = fuzzer_cpu_features,
- }) catch unreachable) catch unreachable,
+ }) catch unreachable) catch unreachable),
.output_mode = .Exe,
});
// std.http.Server does not have a sendfile API yet.
diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig
index 12b55a8c29..d9c098113f 100644
--- a/lib/std/Build/Module.zig
+++ b/lib/std/Build/Module.zig
@@ -655,10 +655,10 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void {
m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM");
}
-fn requireKnownTarget(m: *Module) std.Target {
- const resolved_target = m.resolved_target orelse
- @panic("this API requires the Module to be created with a known 'target' field");
- return resolved_target.result;
+fn requireKnownTarget(m: *Module) *const std.Target {
+ const resolved_target = &(m.resolved_target orelse
+ @panic("this API requires the Module to be created with a known 'target' field"));
+ return &resolved_target.result;
}
/// Elements of `modules` and `names` are matched one-to-one.
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
index e10840db75..9352280d96 100644
--- a/lib/std/Build/Step/Compile.zig
+++ b/lib/std/Build/Step/Compile.zig
@@ -377,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
const resolved_target = options.root_module.resolved_target orelse
@panic("the root Module of a Compile step must be created with a known 'target' field");
- const target = resolved_target.result;
+ const target = &resolved_target.result;
const step_name = owner.fmt("compile {s} {s} {s}", .{
// Avoid the common case of the step name looking like "compile test test".
@@ -1866,7 +1866,7 @@ fn outputPath(c: *Compile, out_dir: std.Build.Cache.Path, ea: std.zig.EmitArtifa
const arena = c.step.owner.graph.arena;
const name = ea.cacheName(arena, .{
.root_name = c.name,
- .target = c.root_module.resolved_target.?.result,
+ .target = &c.root_module.resolved_target.?.result,
.output_mode = switch (c.kind) {
.lib => .Lib,
.obj, .test_obj => .Obj,
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index af7f0ee1a9..aa3931ac8c 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1108,7 +1108,7 @@ fn runCommand(
const need_cross_libc = exe.is_linking_libc and
(root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
const other_target = exe.root_module.resolved_target.?.result;
- switch (std.zig.system.getExternalExecutor(b.graph.host.result, &other_target, .{
+ switch (std.zig.system.getExternalExecutor(&b.graph.host.result, &other_target, .{
.qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
.link_libc = exe.is_linking_libc,
})) {