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,
167167/// Position Independent Executable
168168pie: ?bool = null,
169169
170/// Link Time Optimization mode
171lto: ?std.zig.LtoMode = null,
172
170173dll_export_fns: ?bool = null,
171174
172175subsystem: ?std.Target.SubSystem = null,
......@@ -185,7 +188,9 @@ force_undefined_symbols: std.StringHashMap(void),
185188/// Overrides the default stack size
186189stack_size: ?u64 = null,
187190
191/// Deprecated; prefer using `lto`.
188192want_lto: ?bool = null,
193
189194use_llvm: ?bool,
190195use_lld: ?bool,
191196
......@@ -1711,7 +1716,15 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
17111716 }
17121717
17131718 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
17151728 try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard);
17161729
17171730 if (compile.subsystem) |subsystem| {
lib/std/zig.zig+2
......@@ -313,6 +313,8 @@ pub const BuildId = union(enum) {
313313 }
314314};
315315
316pub const LtoMode = enum { none, full, thin };
317
316318/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed
317319/// via the `-mcpu` flag passed to the Zig compiler.
318320/// Appends the result to `buffer`.
src/Compilation.zig-1
......@@ -1074,7 +1074,6 @@ pub const CreateOptions = struct {
10741074 /// executable this field is ignored.
10751075 want_compiler_rt: ?bool = null,
10761076 want_ubsan_rt: ?bool = null,
1077 want_lto: ?bool = null,
10781077 function_sections: bool = false,
10791078 data_sections: bool = false,
10801079 time_report: bool = false,
src/Compilation/Config.zig+3-5
......@@ -48,7 +48,7 @@ use_lib_llvm: bool,
4848/// and updates the final binary.
4949use_lld: bool,
5050c_frontend: CFrontend,
51lto: LtoMode,
51lto: std.zig.LtoMode,
5252/// WASI-only. Type of WASI execution model ("command" or "reactor").
5353/// Always set to `command` for non-WASI targets.
5454wasi_exec_model: std.builtin.WasiExecModel,
......@@ -66,8 +66,6 @@ san_cov_trace_pc_guard: bool,
6666
6767pub const CFrontend = enum { clang, aro };
6868
69pub const LtoMode = enum { none, full, thin };
70
7169pub const DebugFormat = union(enum) {
7270 strip,
7371 dwarf: std.dwarf.Format,
......@@ -105,7 +103,7 @@ pub const Options = struct {
105103 use_lib_llvm: ?bool = null,
106104 use_lld: ?bool = null,
107105 use_clang: ?bool = null,
108 lto: ?LtoMode = null,
106 lto: ?std.zig.LtoMode = null,
109107 /// WASI-only. Type of WASI execution model ("command" or "reactor").
110108 wasi_exec_model: ?std.builtin.WasiExecModel = null,
111109 import_memory: ?bool = null,
......@@ -288,7 +286,7 @@ pub fn resolve(options: Options) ResolveError!Config {
288286 break :b .clang;
289287 };
290288
291 const lto: LtoMode = b: {
289 const lto: std.zig.LtoMode = b: {
292290 if (!use_lld) {
293291 // zig ld LTO support is tracked by
294292 // https://github.com/ziglang/zig/issues/8680
src/codegen/llvm.zig+1-1
......@@ -771,7 +771,7 @@ pub const Object = struct {
771771 time_report: bool,
772772 sanitize_thread: bool,
773773 fuzz: bool,
774 lto: Compilation.Config.LtoMode,
774 lto: std.zig.LtoMode,
775775 };
776776
777777 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(
4343 switch (target.result.os.tag) {
4444 .windows => {
4545 // https://github.com/ziglang/zig/issues/8531
46 exe_cpp.want_lto = false;
46 exe_cpp.lto = .none;
4747 },
4848 .macos => {
4949 // https://github.com/ziglang/zig/issues/8680
50 exe_cpp.want_lto = false;
51 exe_c.want_lto = false;
50 exe_cpp.lto = .none;
51 exe_c.lto = .none;
5252 },
5353 else => {},
5454 }
test/tests.zig+1-1
......@@ -1681,7 +1681,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
16811681
16821682 // This test is intentionally trying to check if the external ABI is
16831683 // done properly. LTO would be a hindrance to this.
1684 test_step.want_lto = false;
1684 test_step.lto = .none;
16851685
16861686 const run = b.addRunArtifact(test_step);
16871687 run.skip_foreign_checks = true;