-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
27 lines (26 loc) · 990 Bytes
/
Copy pathbuild.rs
File metadata and controls
27 lines (26 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
// Examples link against libruby too. The dynamic modules get their RUNPATH
// from their own build scripts; without this the example binaries would
// still depend on the caller exporting LD_LIBRARY_PATH.
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
if target_os != "linux" {
return;
}
println!("cargo:rerun-if-env-changed=RUBY");
if let Some(libdir) = ruby_libdir() {
println!("cargo:rustc-link-arg-examples=-Wl,-rpath,{libdir}");
}
}
fn ruby_libdir() -> Option<String> {
let ruby = std::env::var("RUBY").unwrap_or_else(|_| "ruby".to_owned());
let output = std::process::Command::new(ruby)
.args(["-e", "print RbConfig::CONFIG['libdir']"])
.output()
.ok()?;
if !output.status.success() {
return None;
}
let libdir = String::from_utf8(output.stdout).ok()?;
let libdir = libdir.trim();
(!libdir.is_empty()).then(|| libdir.to_owned())
}