Skip to content

zig cc: Respect Clang's -static and -dynamic flags #23572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/clang_options_data.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,14 @@ flagpd1("dwarf-ext-refs"),
},
sepd1("dylib_file"),
flagpd1("dylinker"),
flagpd1("dynamic"),
.{
.name = "dynamic",
.syntax = .flag,
.zig_equivalent = .dynamic,
.pd1 = true,
.pd2 = false,
.psl = false,
},
.{
.name = "dynamiclib",
.syntax = .flag,
Expand Down Expand Up @@ -5698,7 +5705,7 @@ flagpd1("startfiles"),
.{
.name = "static",
.syntax = .flag,
.zig_equivalent = .other,
.zig_equivalent = .static,
.pd1 = true,
.pd2 = true,
.psl = false,
Expand Down
13 changes: 12 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,16 @@ fn buildOutputType(
fatal("unsupported -rtlib option '{s}'", .{it.only_arg});
}
},
.static => {
create_module.opts.link_mode = .static;
lib_preferred_mode = .static;
lib_search_strategy = .no_fallback;
},
.dynamic => {
create_module.opts.link_mode = .dynamic;
lib_preferred_mode = .dynamic;
lib_search_strategy = .mode_first;
},
}
}
// Parse linker args.
Expand Down Expand Up @@ -4088,7 +4098,6 @@ fn createModule(
color,
) catch |err| fatal("failed to resolve link inputs: {s}", .{@errorName(err)});

if (create_module.windows_libs.count() != 0) create_module.opts.any_dyn_libs = true;
if (!create_module.opts.any_dyn_libs) for (create_module.link_inputs.items) |item| switch (item) {
.dso, .dso_exact => {
create_module.opts.any_dyn_libs = true;
Expand Down Expand Up @@ -5955,6 +5964,8 @@ pub const ClangArgIterator = struct {
san_cov,
no_san_cov,
rtlib,
static,
dynamic,
};

const Args = struct {
Expand Down
8 changes: 8 additions & 0 deletions tools/update_clang_options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,14 @@ const known_options = [_]KnownOpt{
.name = "rtlib=",
.ident = "rtlib",
},
.{
.name = "static",
.ident = "static",
},
.{
.name = "dynamic",
.ident = "dynamic",
},
};

const blacklisted_options = [_][]const u8{};
Expand Down