fn main() {
let has_mutually_exclusive_features = cfg!(feature = "non-fips") && cfg!(feature = "fips");
assert!(
!has_mutually_exclusive_features,
"`fips` and `non-fips` are mutually exclusive crate features."
);
let sys_crate = if cfg!(feature = "fips") {
"aws-lc-fips-sys"
} else if cfg!(feature = "aws-lc-sys") {
"aws-lc-sys"
} else {
panic!(
"one of the following features must be specified: `aws-lc-sys`, `non-fips`, or `fips`."
);
};
export_sys_vars(sys_crate);
}
fn export_sys_vars(sys_crate: &str) {
let prefix = if sys_crate == "aws-lc-fips-sys" {
"DEP_AWS_LC_FIPS_"
} else {
"DEP_AWS_LC_"
};
let mut selected = String::default();
let mut candidates = vec![];
for (name, value) in std::env::vars() {
if !selected.is_empty() {
try_export_var(&selected, &name, &value);
continue;
}
if let Some(version) = name.strip_prefix(prefix) {
if let Some(version) = version.strip_suffix("_INCLUDE") {
selected = format!("{prefix}{version}_");
try_export_var(&selected, &name, &value);
} else {
candidates.push((name, value));
}
}
}
assert!(!selected.is_empty(), "missing {prefix} include");
for (name, value) in candidates {
try_export_var(&selected, &name, &value);
}
}
fn try_export_var(selected: &str, name: &str, value: &str) {
assert!(!selected.is_empty(), "missing selected prefix");
if let Some(var) = name.strip_prefix(selected) {
eprintln!("cargo:rerun-if-env-changed={name}");
let var = var.to_lowercase();
println!("cargo:{var}={value}");
}
}