Files
SFG545 5c33a36100 Refactor build flags handling and add tool alias management
- Introduced a new method `apply_default_string` to streamline the application of default values for string fields in build flags.
- Enhanced `apply_flags_table` to utilize the new method for setting various build flags, improving code readability and maintainability.
- Added support for additional build flags: `fuse_ld`, `ranlib`, `strip`, `nm`, `objcopy`, `objdump`, and `readelf`.
- Implemented a new command `set` to manage tool aliases for compilers, linkers, and shells, allowing users to set preferred tools in the build environment.
- Improved error handling and validation for tool alias configuration, ensuring that existing non-symlink files are not replaced.
- Added tests to verify the correct behavior of tool alias management and build flag application.
2026-05-27 14:39:01 -05:00

52 lines
1.7 KiB
Rust

const BUILD_OPTION_KEYS: &[&str] = &[
"BUILD_DEPOT_STATIC",
"DEPOT_AUTOTOOLS_PACKAGE",
"DEPOT_CMAKE_PACKAGE",
"DEPOT_MESON_PACKAGE",
"DEPOT_PERL_PACKAGE",
"DEPOT_CUSTOM_PACKAGE",
"DEPOT_PYTHON_PACKAGE",
"DEPOT_RUST_PACKAGE",
"DEPOT_MAKEFILE_PACKAGE",
];
fn main() {
println!("cargo:rerun-if-env-changed=CC");
for key in BUILD_OPTION_KEYS {
println!("cargo:rerun-if-env-changed={key}");
if let Ok(value) = std::env::var(key) {
println!("cargo:rustc-env={key}={value}");
}
}
if std::env::var_os("CARGO_FEATURE_STATIC_EXCEPT_LIBC").is_some()
&& std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("linux")
{
let libgcc_eh = gcc_runtime_archive("libgcc_eh.a").unwrap_or_else(|| {
panic!("static-except-libc requires libgcc_eh.a for static libgcc linkage")
});
println!("cargo:rustc-link-arg-bin=depot=-Wl,--whole-archive");
println!("cargo:rustc-link-arg-bin=depot={libgcc_eh}");
println!("cargo:rustc-link-arg-bin=depot=-Wl,--no-whole-archive");
println!("cargo:rustc-link-arg-bin=depot=-static-libgcc");
}
}
fn gcc_runtime_archive(name: &str) -> Option<String> {
let compiler = std::env::var_os("CC").unwrap_or_else(|| "cc".into());
let output = std::process::Command::new(compiler)
.arg(format!("-print-file-name={name}"))
.output()
.ok()?;
if !output.status.success() {
return None;
}
let path = String::from_utf8(output.stdout).ok()?;
let path = path.trim();
if path.is_empty() || path == name || !std::path::Path::new(path).exists() {
None
} else {
Some(path.to_string())
}
}