Skip to content

Commit 7733b5d

Browse files
Merge pull request #23501 from imreallybadatnames/master
Step.Compile: use LtoMode enum for lto option
1 parent 227788e commit 7733b5d

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

lib/std/Build/Step/Compile.zig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ discard_local_symbols: bool = false,
167167
/// Position Independent Executable
168168
pie: ?bool = null,
169169

170+
/// Link Time Optimization mode
171+
lto: ?std.zig.LtoMode = null,
172+
170173
dll_export_fns: ?bool = null,
171174

172175
subsystem: ?std.Target.SubSystem = null,
@@ -185,7 +188,9 @@ force_undefined_symbols: std.StringHashMap(void),
185188
/// Overrides the default stack size
186189
stack_size: ?u64 = null,
187190

191+
/// Deprecated; prefer using `lto`.
188192
want_lto: ?bool = null,
193+
189194
use_llvm: ?bool,
190195
use_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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ pub const BuildId = union(enum) {
313313
}
314314
};
315315

316+
pub 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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use_lib_llvm: bool,
4848
/// and updates the final binary.
4949
use_lld: bool,
5050
c_frontend: CFrontend,
51-
lto: LtoMode,
51+
lto: std.zig.LtoMode,
5252
/// WASI-only. Type of WASI execution model ("command" or "reactor").
5353
/// Always set to `command` for non-WASI targets.
5454
wasi_exec_model: std.builtin.WasiExecModel,
@@ -66,8 +66,6 @@ san_cov_trace_pc_guard: bool,
6666

6767
pub const CFrontend = enum { clang, aro };
6868

69-
pub const LtoMode = enum { none, full, thin };
70-
7169
pub 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)