diff --git a/src/main.zig b/src/main.zig index 5da6751833ca157fa8fe9f9bb5a2ddae902f60e0..f1432de74a8916d74a3dfe90a76b13ea67f4def3 100644 --- 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});