From f4cb466bbb1d3005d7054fb2215c6c75016e02a7 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Tue, 12 Nov 2024 13:22:06 +0800 Subject: [PATCH] link to OUT_DIR --- build.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/build.rs b/build.rs index 22f6fc4..f11e0c3 100644 --- a/build.rs +++ b/build.rs @@ -83,31 +83,35 @@ fn main() { fail_build(); } - // install the dylib to system path - let libffi_out_path = - drift_ffi_sys_crate.join(Path::new(&format!("target/{profile}/{LIB}.{lib_ext}"))); - let output = std::process::Command::new("ln") - .args([ - "-sf", - libffi_out_path.to_str().expect("ffi build path"), - "/usr/local/lib/", - ]) - .output() - .expect("install ok"); - if !output.status.success() { eprintln!( "{LIB} could not be installed: {}", String::from_utf8_lossy(output.stderr.as_slice()) ); } + + if let Ok(out_dir) = std::env::var("OUT_DIR") { + println!("cargo:rustc-link-search=native={out_dir}"); + } else { + // install the dylib to system path + let libffi_out_path = + drift_ffi_sys_crate.join(Path::new(&format!("target/{profile}/{LIB}.{lib_ext}"))); + let _output = std::process::Command::new("ln") + .args([ + "-sf", + libffi_out_path.to_str().expect("ffi build path"), + "/usr/local/lib/", + ]) + .output() + .expect("install ok"); + println!("cargo:rustc-link-search=native=/usr/local/lib/"); + } } if let Ok(lib_path) = std::env::var("CARGO_DRIFT_FFI_PATH") { println!("{LIB}: searching for lib at: {lib_path}"); println!("cargo:rustc-link-search=native={lib_path}"); } - println!("cargo:rustc-link-search=native=/usr/local/lib"); println!("cargo:rustc-link-lib=dylib=drift_ffi_sys"); }