Skip to content

Commit 442b92b

Browse files
committed
set macos link args automatically
1 parent feb64c1 commit 442b92b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

sys/build.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
fn main() {
22
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
3-
if target_os == "windows" {
4-
windows_link_node_import_library();
5-
}
3+
match target_os.as_str() {
4+
"macos" => {
5+
macos_setup();
6+
}
7+
"windows" => {
8+
windows_setup();
9+
}
10+
_ => {}
11+
};
612
}
713

8-
fn windows_link_node_import_library() {
9-
let version = "v15.9.0";
14+
fn macos_setup() {
15+
println!("cargo:rustc-cdylib-link-arg=-Wl");
16+
println!("cargo:rustc-cdylib-link-arg=-undefined");
17+
println!("cargo:rustc-cdylib-link-arg=dynamic_lookup");
18+
}
19+
20+
fn windows_setup() {
21+
let version = "v16.4.0";
1022
let arch = "x64";
1123
let url = format!(
1224
"https://nodejs.org/dist/{version}/win-{arch}/node.lib",
@@ -17,7 +29,6 @@ fn windows_link_node_import_library() {
1729
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
1830
let node_lib_path = out_dir.join("node.lib");
1931
std::fs::write(node_lib_path, node_lib_bytes).unwrap();
20-
println!("cargo:rerun-if-changed=build.rs");
2132
println!("cargo:rustc-link-search={}", out_dir.to_str().unwrap());
2233
println!("cargo:rustc-link-lib=node");
2334
}

0 commit comments

Comments
 (0)