zig

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

commit 090ae3042e8e2fec2c2f8797bf78c8f6e6335a30 (tree)
parent b15aa0540d03c92c7b822fbebc373bf4e76e3425
Author: rpkak <rpkak@noreply.codeberg.org>
Date:   Fri, 13 Mar 2026 12:52:37 +0100

Set link_libunwind to true for zig build-exe -lunwind

Diffstat:
Msrc/main.zig | 59++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 34 insertions(+), 25 deletions(-)

diff --git a/src/main.zig b/src/main.zig @@ -2001,32 +2001,32 @@ fn buildOutputType( try create_module.cli_link_inputs.append(arena, .{ .dso_exact = .{ .name = it.only_arg, } }); - } else switch (target_util.classifyCompilerRtLibName(it.only_arg)) { - .none => try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ - .name = it.only_arg, - .query = .{ - .must_link = must_link, - .needed = needed, - .weak = false, - .preferred_mode = lib_preferred_mode, - .search_strategy = lib_search_strategy, - .allow_so_scripts = allow_so_scripts, + } else { + const compiler_rt_classification = target_util.classifyCompilerRtLibName(it.only_arg); + switch (compiler_rt_classification) { + .only_compiler_rt, .both => { + // We need this variable separately from `want_compiler_rt` because of + // invocations such as `zig cc -lcompiler_rt -nostdlib`. If we just set + // `want_compiler_rt = true` here, processing of the later `-nostdlib` + // would undo that. + zig_cc_explicitly_link_compiler_rt = true; }, - } }), - .only_compiler_rt => { - // We need this variable separately from `want_compiler_rt` because of - // invocations such as `zig cc -lcompiler_rt -nostdlib`. If we just set - // `want_compiler_rt = true` here, processing of the later `-nostdlib` - // would undo that. - zig_cc_explicitly_link_compiler_rt = true; - }, - .only_libunwind => { - create_module.opts.link_libunwind = true; - }, - .both => { - zig_cc_explicitly_link_compiler_rt = true; - create_module.opts.link_libunwind = true; - }, + .none, .only_libunwind => {}, + } + if (compiler_rt_classification != .only_compiler_rt) { + // The case in which this arg wants to link libunwind is handled in createModule. + try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ + .name = it.only_arg, + .query = .{ + .must_link = must_link, + .needed = needed, + .weak = false, + .preferred_mode = lib_preferred_mode, + .search_strategy = lib_search_strategy, + .allow_so_scripts = allow_so_scripts, + }, + } }); + } } }, .ignore => {}, @@ -3994,6 +3994,15 @@ fn createModule( continue; } + switch (target_util.classifyCompilerRtLibName(lib_name)) { + .none => {}, + .only_libunwind, .both => { + create_module.opts.link_libunwind = true; + continue; + }, + .only_compiler_rt => continue, + } + if (target.isMinGW()) { const exists = mingw.libExists(arena, io, target, create_module.dirs.zig_lib, lib_name) catch |err| fatal("failed to check zig installation for DLL import libs: {t}", .{err});