4ce5f42d12
This allows us to fully use cxx-rs with `extern "C++"`. Now we do call back into the C/C++ today, but it only works outside of cargo/Rust's knowledge. Most notably, it means we can't use our C code in `cargo test`. And that's a problem for moving some C/C++ code to Rust, because we want to port the unit tests too. For now, re-declare our dependencies and part of the build system inside the Cargo build. However, this is also an important step towards using Cargo as our *sole* build system. We don't add build dependencies too often, so the short term duplication should be OK. However, a major unfortunate side effect of this is that we now need to serialize the build process; almost all the C/C++ comes first (`librpmostreeinternals.la`) and then the Rust build, then we finally generate the executable with both. The only way out of this really is to move more of the C/C++ build into Cargo, and we probably want to refactor into internal crates.
31 lines
1.0 KiB
Rust
31 lines
1.0 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:rustc-link-lib=cap");
|
|
println!("cargo:rustc-link-search={}/libdnf-build/libdnf", cwd);
|
|
println!("cargo:rustc-link-lib=dnf");
|
|
println!("cargo:rustc-link-lib=rpmostree-1");
|
|
system_deps::Config::new().probe()?;
|
|
detect_fedora_feature()?;
|
|
Ok(())
|
|
}
|