Skip to content

Commit

Permalink
Merge pull request #10 from messense/dynamic-lookup
Browse files Browse the repository at this point in the history
Add `-undefined dynamic_lookup` support for macOS
  • Loading branch information
messense authored Feb 23, 2022
2 parents 2b13ac4 + 15cb185 commit 094caf7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,30 @@ impl Zig {
}
Some(arg.to_string())
};
let has_undefined_dynamic_lookup = |args: &[String]| {
let undefined = args
.iter()
.position(|x| x == "-undefined")
.and_then(|i| args.get(i + 1));
match undefined {
Some(x) if x == "dynamic_lookup" => true,
_ => false,
}
};

let mut new_cmd_args = Vec::with_capacity(cmd_args.len());
for arg in cmd_args {
let arg = if arg.starts_with('@') && arg.ends_with("linker-arguments") {
// rustc passes arguments to linker via an @-file when arguments are too long
// See https://github.com/rust-lang/rust/issues/41190
let content = fs::read(arg.trim_start_matches('@'))?;
let link_args: Vec<_> = str::from_utf8(&content)?
let mut link_args: Vec<_> = str::from_utf8(&content)?
.split('\n')
.filter_map(filter_link_arg)
.collect();
if has_undefined_dynamic_lookup(&link_args) {
link_args.push("-Wl,-undefined=dynamic_lookup".to_string());
}
fs::write(arg.trim_start_matches('@'), link_args.join("\n").as_bytes())?;
Some(arg.to_string())
} else {
Expand All @@ -96,6 +109,9 @@ impl Zig {
new_cmd_args.push(arg);
}
}
if has_undefined_dynamic_lookup(&cmd_args) {
new_cmd_args.push("-Wl,-undefined=dynamic_lookup".to_string());
}
let (zig, zig_args) = Self::find_zig()?;
let mut child = Command::new(zig)
.args(zig_args)
Expand Down

0 comments on commit 094caf7

Please sign in to comment.