authorgravatar for 68000899+imreallybadatnames@users.noreply.github.comimreallybadatnames™️ <68000899+imreallybadatnames@users.noreply.github.com> 2025-04-09 16:16:36+11:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-09 05:16:36+00:00
log7733b5dbe603033a1ed9e8d0146ef7432d5ffd5b
treec8f2ff9bdd944039b012e05ec30ffd7126e75c88
parent227788e6d5025933d6d70086fb939dcf487fee0a
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #23501 from imreallybadatnames/master

Step.Compile: use LtoMode enum for lto option

7 files changed, 24 insertions(+), 12 deletions(-)

lib/std/Build/Step/Compile.zig+14-1
...@@ -167,6 +167,9 @@ discard_local_symbols: bool = false,...@@ -167,6 +167,9 @@ discard_local_symbols: bool = false,
167/// Position Independent Executable167/// Position Independent Executable
168pie: ?bool = null,168pie: ?bool = null,
169169
170/// Link Time Optimization mode
171lto: ?std.zig.LtoMode = null,
172
170dll_export_fns: ?bool = null,173dll_export_fns: ?bool = null,
171174
172subsystem: ?std.Target.SubSystem = null,175subsystem: ?std.Target.SubSystem = null,
...@@ -185,7 +188,9 @@ force_undefined_symbols: std.StringHashMap(void),...@@ -185,7 +188,9 @@ force_undefined_symbols: std.StringHashMap(void),
185/// Overrides the default stack size188/// Overrides the default stack size
186stack_size: ?u64 = null,189stack_size: ?u64 = null,
187190
191/// Deprecated; prefer using `lto`.
188want_lto: ?bool = null,192want_lto: ?bool = null,
193
189use_llvm: ?bool,194use_llvm: ?bool,
190use_lld: ?bool,195use_lld: ?bool,
191196
...@@ -1711,7 +1716,15 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {...@@ -1711,7 +1716,15 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
1711 }1716 }
17121717
1713 try addFlag(&zig_args, "PIE", compile.pie);1718 try addFlag(&zig_args, "PIE", compile.pie);
1714 try addFlag(&zig_args, "lto", compile.want_lto);1719
1720 if (compile.lto) |lto| {
1721 try zig_args.append(switch (lto) {
1722 .full => "-flto=full",
1723 .thin => "-flto=thin",
1724 .none => "-fno-lto",
1725 });
1726 } else try addFlag(&zig_args, "lto", compile.want_lto);
1727
1715 try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard);1728 try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard);
17161729
1717 if (compile.subsystem) |subsystem| {1730 if (compile.subsystem) |subsystem| {
lib/std/zig.zig+2
...@@ -313,6 +313,8 @@ pub const BuildId = union(enum) {...@@ -313,6 +313,8 @@ pub const BuildId = union(enum) {
313 }313 }
314};314};
315315
316pub const LtoMode = enum { none, full, thin };
317
316/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed318/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed
317/// via the `-mcpu` flag passed to the Zig compiler.319/// via the `-mcpu` flag passed to the Zig compiler.
318/// Appends the result to `buffer`.320/// Appends the result to `buffer`.
src/Compilation.zig-1
...@@ -1074,7 +1074,6 @@ pub const CreateOptions = struct {...@@ -1074,7 +1074,6 @@ pub const CreateOptions = struct {
1074 /// executable this field is ignored.1074 /// executable this field is ignored.
1075 want_compiler_rt: ?bool = null,1075 want_compiler_rt: ?bool = null,
1076 want_ubsan_rt: ?bool = null,1076 want_ubsan_rt: ?bool = null,
1077 want_lto: ?bool = null,
1078 function_sections: bool = false,1077 function_sections: bool = false,
1079 data_sections: bool = false,1078 data_sections: bool = false,
1080 time_report: bool = false,1079 time_report: bool = false,
src/Compilation/Config.zig+3-5
...@@ -48,7 +48,7 @@ use_lib_llvm: bool,...@@ -48,7 +48,7 @@ use_lib_llvm: bool,
48/// and updates the final binary.48/// and updates the final binary.
49use_lld: bool,49use_lld: bool,
50c_frontend: CFrontend,50c_frontend: CFrontend,
51lto: LtoMode,51lto: std.zig.LtoMode,
52/// WASI-only. Type of WASI execution model ("command" or "reactor").52/// WASI-only. Type of WASI execution model ("command" or "reactor").
53/// Always set to `command` for non-WASI targets.53/// Always set to `command` for non-WASI targets.
54wasi_exec_model: std.builtin.WasiExecModel,54wasi_exec_model: std.builtin.WasiExecModel,
...@@ -66,8 +66,6 @@ san_cov_trace_pc_guard: bool,...@@ -66,8 +66,6 @@ san_cov_trace_pc_guard: bool,
6666
67pub const CFrontend = enum { clang, aro };67pub const CFrontend = enum { clang, aro };
6868
69pub const LtoMode = enum { none, full, thin };
70
71pub const DebugFormat = union(enum) {69pub const DebugFormat = union(enum) {
72 strip,70 strip,
73 dwarf: std.dwarf.Format,71 dwarf: std.dwarf.Format,
...@@ -105,7 +103,7 @@ pub const Options = struct {...@@ -105,7 +103,7 @@ pub const Options = struct {
105 use_lib_llvm: ?bool = null,103 use_lib_llvm: ?bool = null,
106 use_lld: ?bool = null,104 use_lld: ?bool = null,
107 use_clang: ?bool = null,105 use_clang: ?bool = null,
108 lto: ?LtoMode = null,106 lto: ?std.zig.LtoMode = null,
109 /// WASI-only. Type of WASI execution model ("command" or "reactor").107 /// WASI-only. Type of WASI execution model ("command" or "reactor").
110 wasi_exec_model: ?std.builtin.WasiExecModel = null,108 wasi_exec_model: ?std.builtin.WasiExecModel = null,
111 import_memory: ?bool = null,109 import_memory: ?bool = null,
...@@ -288,7 +286,7 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -288,7 +286,7 @@ pub fn resolve(options: Options) ResolveError!Config {
288 break :b .clang;286 break :b .clang;
289 };287 };
290288
291 const lto: LtoMode = b: {289 const lto: std.zig.LtoMode = b: {
292 if (!use_lld) {290 if (!use_lld) {
293 // zig ld LTO support is tracked by291 // zig ld LTO support is tracked by
294 // https://github.com/ziglang/zig/issues/8680292 // https://github.com/ziglang/zig/issues/8680
src/codegen/llvm.zig+1-1
...@@ -771,7 +771,7 @@ pub const Object = struct {...@@ -771,7 +771,7 @@ pub const Object = struct {
771 time_report: bool,771 time_report: bool,
772 sanitize_thread: bool,772 sanitize_thread: bool,
773 fuzz: bool,773 fuzz: bool,
774 lto: Compilation.Config.LtoMode,774 lto: std.zig.LtoMode,
775 };775 };
776776
777 pub fn emit(o: *Object, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void {777 pub fn emit(o: *Object, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void {
test/standalone/c_compiler/build.zig+3-3
...@@ -43,12 +43,12 @@ fn add(...@@ -43,12 +43,12 @@ fn add(
43 switch (target.result.os.tag) {43 switch (target.result.os.tag) {
44 .windows => {44 .windows => {
45 // https://github.com/ziglang/zig/issues/853145 // https://github.com/ziglang/zig/issues/8531
46 exe_cpp.want_lto = false;46 exe_cpp.lto = .none;
47 },47 },
48 .macos => {48 .macos => {
49 // https://github.com/ziglang/zig/issues/868049 // https://github.com/ziglang/zig/issues/8680
50 exe_cpp.want_lto = false;50 exe_cpp.lto = .none;
51 exe_c.want_lto = false;51 exe_c.lto = .none;
52 },52 },
53 else => {},53 else => {},
54 }54 }
test/tests.zig+1-1
...@@ -1681,7 +1681,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {...@@ -1681,7 +1681,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
16811681
1682 // This test is intentionally trying to check if the external ABI is1682 // This test is intentionally trying to check if the external ABI is
1683 // done properly. LTO would be a hindrance to this.1683 // done properly. LTO would be a hindrance to this.
1684 test_step.want_lto = false;1684 test_step.lto = .none;
16851685
1686 const run = b.addRunArtifact(test_step);1686 const run = b.addRunArtifact(test_step);
1687 run.skip_foreign_checks = true;1687 run.skip_foreign_checks = true;