8f71dcfafe
Having our binary depend on the shared library, which in turn depends on the binary (at runtime) is messy. Instead, statically compile the shlib code into our binary. This duplicates the text a bit, but it's not a lot of code. The goal is to more easily in the future to e.g. move the shared library out into a separate git repository entirely that runs on a separate lifecycle - that would still build using Automake for example while the main git repository switches to purely cargo. Another motivation is avoiding linker issues I had with other patches due to this semi-cyclical dependency.
38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
use anyhow::Result;
|
|
|
|
fn detect_fedora_feature() -> Result<()> {
|
|
if !std::path::Path::new("/usr/lib/os-release").exists() {
|
|
return Ok(());
|
|
}
|
|
let p = std::process::Command::new("sh")
|
|
.args(&["-c", ". /usr/lib/os-release && echo ${ID}"])
|
|
.stdout(std::process::Stdio::piped())
|
|
.output()?;
|
|
let out = std::str::from_utf8(&p.stdout).ok().map(|s| s.trim());
|
|
if out == Some("fedora") {
|
|
println!(r#"cargo:rustc-cfg=feature="fedora-integration""#)
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
fn main() -> Result<()> {
|
|
let cwd = std::env::current_dir()?;
|
|
let cwd = cwd.to_str().expect("utf8 pwd");
|
|
println!("cargo:rustc-link-search={}/.libs", cwd);
|
|
println!("cargo:rustc-link-lib=static=rpmostreeinternals");
|
|
println!(
|
|
"cargo:rerun-if-changed={}/.libs/librpmostreeinternals.a",
|
|
cwd
|
|
);
|
|
println!("cargo:rustc-link-lib=cap");
|
|
println!("cargo:rustc-link-lib=rt");
|
|
println!("cargo:rustc-link-lib=stdc++");
|
|
// https://github.com/ostreedev/ostree/commit/1f832597fc83fda6cb8daf48c4495a9e1590774c
|
|
// https://github.com/rust-lang/rust/issues/47714
|
|
println!("cargo:rustc-link-lib=dl");
|
|
println!("cargo:rustc-link-lib=m");
|
|
system_deps::Config::new().probe()?;
|
|
detect_fedora_feature()?;
|
|
Ok(())
|
|
}
|