Skip to content
Closed
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
5 changes: 4 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ else
echo " 2. Set LLVM_SYS_XXX_PREFIX environment variable"
echo ""
echo "Installation examples:"
echo " macOS: brew install llvm"
echo " macOS (Homebrew): brew install llvm"
echo " macOS (MacPorts): sudo port install llvm-21 clang-21"
echo " sudo port select --set llvm mp-llvm-21"
echo " sudo port select --set clang mp-clang-21"
echo " Ubuntu: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 21"
echo " Manual: export LLVM_SYS_211_PREFIX=/path/to/llvm"
exit 1
Expand Down
30 changes: 4 additions & 26 deletions openvaf/linker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,6 @@ fn linker_with_args<'a>(
// this environment variable too in recent versions.
cmd.cmd().env("ZERO_AR_DATE", "1");

// On macOS, we always need to add the SDK sysroot for linking against system libraries
if flavor == LinkerFlavor::Ld64 && target.options.is_like_osx {
// Detect SDK path using xcrun
if let Ok(output) = std::process::Command::new("xcrun").args(["--show-sdk-path"]).output() {
if output.status.success() {
if let Ok(sdk_path) = String::from_utf8(output.stdout) {
let sdk_path = sdk_path.trim();
if !sdk_path.is_empty() {
cmd.args(["-syslibroot", sdk_path]);
}
}
}
}
}

cmd.add_pre_link_args(target, flavor);

add_objects(&mut *cmd);
Expand Down Expand Up @@ -170,17 +155,9 @@ fn get_linker<'a>(
let path = path.unwrap_or_else(|| {
if is_msys2_environment() {
"gcc".into()
} else if flavor == LinkerFlavor::Ld64 {
// For macOS, prefer LLVM's ld64.lld if available
if let Some(llvm_prefix) = get_llvm_prefix() {
let llvm_lld = PathBuf::from(llvm_prefix).join("bin/ld64.lld");
if llvm_lld.exists() {
return llvm_lld;
}
}
"ld".into()
} else if cfg!(target_os = "macos") {
"clang".into()
} else {
// On macOS and Linux, use system ld
"ld".into()
}
});
Expand Down Expand Up @@ -286,7 +263,8 @@ impl<'a> LdLinker<'a> {
fn build_dylib(&mut self) {
// On mac we need to tell the linker to let this library be rpathed
if self.target.options.is_like_osx {
self.linker_arg("-dylib");
self.linker_arg("-dynamiclib");
// clang automatically handles -lSystem
} else {
self.linker_arg("-shared");
}
Expand Down
17 changes: 17 additions & 0 deletions openvaf/openvaf-driver/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// build.rs for openvaf-driver

fn main() {
// Add rpath for LLVM on macOS
#[cfg(target_os = "macos")]
{
if let Ok(output) = std::process::Command::new("llvm-config")
.arg("--libdir")
.output()
{
if output.status.success() {
let libdir = String::from_utf8_lossy(&output.stdout).trim().to_string();
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", libdir);
}
}
}
}
15 changes: 1 addition & 14 deletions openvaf/target/src/spec/aarch64_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,10 @@ pub fn target() -> Target {
base.pre_link_args.insert(
LinkerFlavor::Ld64,
vec![
"-arch".to_string(),
"arm64".to_string(),
"-platform_version".to_string(),
"macos".to_string(),
"11.0".to_string(),
"11.0".to_string(),
"-undefined".to_string(),
"dynamic_lookup".to_string(),
"-Wl,-undefined,dynamic_lookup".to_string(),
],
);

// Link against libSystem which provides dyld_stub_binder
base.post_link_args.insert(
LinkerFlavor::Ld64,
vec!["-lSystem".to_string()],
);

Target {
llvm_target: "arm64-apple-macosx11.0.0".to_owned(),
pointer_width: 64,
Expand Down
9 changes: 1 addition & 8 deletions openvaf/target/src/spec/x86_64_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ pub fn target() -> Target {
base.pre_link_args.insert(
LinkerFlavor::Ld64,
vec![
"-arch".to_string(),
"x86_64".to_string(),
"-platform_version".to_string(),
"macos".to_string(),
"10.15".to_string(),
"10.15".to_string(),
"-undefined".to_string(),
"dynamic_lookup".to_string(),
"-Wl,-undefined,dynamic_lookup".to_string(),
],
);

Expand Down
Loading