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"); }