Skip to content

Commit 735b333

Browse files
committed
rust_src: Fix macOS
1 parent 903a5d6 commit 735b333

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/rust_src/build.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ use std::path::PathBuf;
33

44
fn main() {
55
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
6-
let target_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
7-
.join("target")
8-
.join(env::var("PROFILE").unwrap_or("release".into()));
6+
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
7+
let profile = env::var("PROFILE").unwrap_or("release".into());
8+
let target = env::var("TARGET").unwrap_or_default();
9+
let host = env::var("HOST").unwrap_or_default();
10+
11+
// For cross-compilation, cargo puts output in target/<triple>/<profile>/
12+
let target_dir = if target != host && !target.is_empty() {
13+
manifest_dir.join("target").join(&target).join(&profile)
14+
} else {
15+
manifest_dir.join("target").join(&profile)
16+
};
917

1018
// Compile the loader .so
1119
// This tiny C library:
@@ -17,7 +25,6 @@ fn main() {
1725
std::fs::write(&loader_c, LOADER_SOURCE).unwrap();
1826

1927
// Platform-specific loader compilation
20-
let target = env::var("TARGET").unwrap_or_default();
2128
let is_windows = target.contains("windows");
2229
let is_macos = target.contains("apple") || target.contains("darwin");
2330

@@ -75,6 +82,12 @@ fn main() {
7582
}
7683

7784
println!("cargo:rerun-if-changed=build.rs");
85+
86+
// On macOS, allow undefined symbols (resolved at runtime by the loader)
87+
if is_macos {
88+
println!("cargo:rustc-cdylib-link-arg=-undefined");
89+
println!("cargo:rustc-cdylib-link-arg=dynamic_lookup");
90+
}
7891
}
7992

8093
const LOADER_SOURCE: &str = r#"

0 commit comments

Comments
 (0)