Skip to content

Commit

Permalink
fix: Handle -Wl,-exported_symbols_list <path> (#273)
Browse files Browse the repository at this point in the history
When building a targeting a macos target you may get an error such as:

error: unsupported linker arg: -exported_symbols_list

A previous fix addressed the first variant of this flag where it is one argument.
This fix addresses the second form of this flag where the symbols list is passed
as a file path via a follow up argument.

Repros by building a cdylib targetting aarch64-apple-darwin.

Fixes #164
  • Loading branch information
rfairfax authored Sep 18, 2024
1 parent d420792 commit d821c50
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ impl Zig {
let rustc_ver = rustc_version::version()?;
let zig_version = Zig::zig_version()?;

let filter_linker_arg = |arg: &str| {
let mut skip_next_arg = false;
let mut filter_linker_arg = |arg: &str| {
if skip_next_arg {
skip_next_arg = false;
return None;
}

if arg == "-lgcc_s" {
// Replace libgcc_s with libunwind
return Some("-lunwind".to_string());
Expand Down Expand Up @@ -184,6 +190,10 @@ impl Zig {
// zig doesn't support -exported_symbols_list arg
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-exported_symbols_list
return None;
} else if arg.starts_with("-Wl,-exported_symbols_list") {
// This variant passes the list file as the next argument, skip it
skip_next_arg = true;
return None;
}
if arg == "-Wl,-dylib" {
// zig doesn't support -dylib
Expand Down Expand Up @@ -240,8 +250,10 @@ impl Zig {
)
})?
};
let mut link_args: Vec<_> =
content.split('\n').filter_map(filter_linker_arg).collect();
let mut link_args: Vec<_> = content
.split('\n')
.filter_map(&mut filter_linker_arg)
.collect();
if has_undefined_dynamic_lookup(&link_args) {
link_args.push("-Wl,-undefined=dynamic_lookup".to_string());
}
Expand Down

0 comments on commit d821c50

Please sign in to comment.