zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7733b5dbe603033a1ed9e8d0146ef7432d5ffd5b (tree)
parent 227788e6d5025933d6d70086fb939dcf487fee0a
Author: imreallybadatnames™️ <68000899+imreallybadatnames@users.noreply.github.com>
Date:   Wed,  9 Apr 2025 16:16:36 +1100

Merge pull request #23501 from imreallybadatnames/master

Step.Compile: use LtoMode enum for lto option
Diffstat:
Mlib/std/Build/Step/Compile.zig | 15++++++++++++++-
Mlib/std/zig.zig | 2++
Msrc/Compilation.zig | 1-
Msrc/Compilation/Config.zig | 8+++-----
Msrc/codegen/llvm.zig | 2+-
Mtest/standalone/c_compiler/build.zig | 6+++---
Mtest/tests.zig | 2+-
7 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig @@ -167,6 +167,9 @@ discard_local_symbols: bool = false, /// Position Independent Executable pie: ?bool = null, +/// Link Time Optimization mode +lto: ?std.zig.LtoMode = null, + dll_export_fns: ?bool = null, subsystem: ?std.Target.SubSystem = null, @@ -185,7 +188,9 @@ force_undefined_symbols: std.StringHashMap(void), /// Overrides the default stack size stack_size: ?u64 = null, +/// Deprecated; prefer using `lto`. want_lto: ?bool = null, + use_llvm: ?bool, use_lld: ?bool, @@ -1711,7 +1716,15 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { } try addFlag(&zig_args, "PIE", compile.pie); - try addFlag(&zig_args, "lto", compile.want_lto); + + if (compile.lto) |lto| { + try zig_args.append(switch (lto) { + .full => "-flto=full", + .thin => "-flto=thin", + .none => "-fno-lto", + }); + } else try addFlag(&zig_args, "lto", compile.want_lto); + try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard); if (compile.subsystem) |subsystem| { diff --git a/lib/std/zig.zig b/lib/std/zig.zig @@ -313,6 +313,8 @@ pub const BuildId = union(enum) { } }; +pub const LtoMode = enum { none, full, thin }; + /// Renders a `std.Target.Cpu` value into a textual representation that can be parsed /// via the `-mcpu` flag passed to the Zig compiler. /// Appends the result to `buffer`. diff --git a/src/Compilation.zig b/src/Compilation.zig @@ -1074,7 +1074,6 @@ pub const CreateOptions = struct { /// executable this field is ignored. want_compiler_rt: ?bool = null, want_ubsan_rt: ?bool = null, - want_lto: ?bool = null, function_sections: bool = false, data_sections: bool = false, time_report: bool = false, diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig @@ -48,7 +48,7 @@ use_lib_llvm: bool, /// and updates the final binary. use_lld: bool, c_frontend: CFrontend, -lto: LtoMode, +lto: std.zig.LtoMode, /// WASI-only. Type of WASI execution model ("command" or "reactor"). /// Always set to `command` for non-WASI targets. wasi_exec_model: std.builtin.WasiExecModel, @@ -66,8 +66,6 @@ san_cov_trace_pc_guard: bool, pub const CFrontend = enum { clang, aro }; -pub const LtoMode = enum { none, full, thin }; - pub const DebugFormat = union(enum) { strip, dwarf: std.dwarf.Format, @@ -105,7 +103,7 @@ pub const Options = struct { use_lib_llvm: ?bool = null, use_lld: ?bool = null, use_clang: ?bool = null, - lto: ?LtoMode = null, + lto: ?std.zig.LtoMode = null, /// WASI-only. Type of WASI execution model ("command" or "reactor"). wasi_exec_model: ?std.builtin.WasiExecModel = null, import_memory: ?bool = null, @@ -288,7 +286,7 @@ pub fn resolve(options: Options) ResolveError!Config { break :b .clang; }; - const lto: LtoMode = b: { + const lto: std.zig.LtoMode = b: { if (!use_lld) { // zig ld LTO support is tracked by // https://github.com/ziglang/zig/issues/8680 diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig @@ -771,7 +771,7 @@ pub const Object = struct { time_report: bool, sanitize_thread: bool, fuzz: bool, - lto: Compilation.Config.LtoMode, + lto: std.zig.LtoMode, }; pub fn emit(o: *Object, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void { diff --git a/test/standalone/c_compiler/build.zig b/test/standalone/c_compiler/build.zig @@ -43,12 +43,12 @@ fn add( switch (target.result.os.tag) { .windows => { // https://github.com/ziglang/zig/issues/8531 - exe_cpp.want_lto = false; + exe_cpp.lto = .none; }, .macos => { // https://github.com/ziglang/zig/issues/8680 - exe_cpp.want_lto = false; - exe_c.want_lto = false; + exe_cpp.lto = .none; + exe_c.lto = .none; }, else => {}, } diff --git a/test/tests.zig b/test/tests.zig @@ -1681,7 +1681,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { // This test is intentionally trying to check if the external ABI is // done properly. LTO would be a hindrance to this. - test_step.want_lto = false; + test_step.lto = .none; const run = b.addRunArtifact(test_step); run.skip_foreign_checks = true;