Skip to content

Commit

Permalink
No CMake required for non-FIPS
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jan 24, 2024
1 parent 9b66263 commit 5abfe93
Show file tree
Hide file tree
Showing 5 changed files with 538 additions and 52 deletions.
73 changes: 45 additions & 28 deletions aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,32 @@ enum OutputLibType {
Dynamic,
}

fn env_var_to_bool(name: &str) -> Option<bool> {
let build_type_result = env::var(name);
if let Ok(env_var_value) = build_type_result {
eprintln!("{name}={env_var_value}");
// If the environment variable is set, we ignore every other factor.
let env_var_value = env_var_value.to_lowercase();
if env_var_value.starts_with('0')
|| env_var_value.starts_with('n')
|| env_var_value.starts_with("off")
{
return Some(false);
}
// Otherwise, if the variable is set, assume true
return Some(true);
}
return None;
}

impl Default for OutputLibType {
fn default() -> Self {
let build_type_result = env::var("AWS_LC_FIPS_SYS_STATIC");
if let Ok(build_type) = build_type_result {
eprintln!("AWS_LC_FIPS_SYS_STATIC={build_type}");
// If the environment variable is set, we ignore every other factor.
let build_type = build_type.to_lowercase();
if build_type.starts_with('0')
|| build_type.starts_with('n')
|| build_type.starts_with("off")
{
// Only dynamic if the value is set and is a "negative" value
return OutputLibType::Dynamic;
}

return OutputLibType::Static;
if let Some(val) = env_var_to_bool("AWS_LC_FIPS_SYS_STATIC") {
return if val {
OutputLibType::Static
} else {
OutputLibType::Dynamic
};
}

if target_os() == "linux" && (target_arch() == "x86_64" || target_arch() == "aarch64") {
Expand Down Expand Up @@ -185,7 +195,6 @@ fn target_env() -> String {
env::var("CARGO_CFG_TARGET_ENV").unwrap()
}

#[allow(unused)]
fn target_vendor() -> String {
env::var("CARGO_CFG_TARGET_VENDOR").unwrap()
}
Expand All @@ -195,6 +204,25 @@ fn target() -> String {
env::var("TARGET").unwrap()
}

fn get_builder(
prefix: Option<String>,
manifest_dir: &PathBuf,
out_dir: &PathBuf,
) -> Box<dyn Builder> {
let cmake_builder_builder = || {
Box::new(CmakeBuilder::new(
manifest_dir.clone(),
out_dir.clone(),
prefix.clone(),
OutputLibType::default(),
))
};

let cmake_builder = cmake_builder_builder();
cmake_builder.check_dependencies().unwrap();
cmake_builder
}

macro_rules! cfg_bindgen_platform {
($binding:ident, $os:literal, $arch:literal, $env:literal, $additional:expr) => {
let $binding = {
Expand All @@ -214,8 +242,6 @@ trait Builder {
}

fn main() {
let output_lib_type = OutputLibType::default();

let mut is_bindgen_required = cfg!(feature = "bindgen");

let is_internal_generate = env::var("AWS_LC_RUST_INTERNAL_BINDGEN")
Expand All @@ -237,15 +263,7 @@ fn main() {
let prefix = prefix_string();
let out_dir_str = env::var("OUT_DIR").unwrap();
let out_dir = Path::new(out_dir_str.as_str()).to_path_buf();

let builder = CmakeBuilder::new(
manifest_dir.clone(),
out_dir.clone(),
Some(prefix.clone()),
output_lib_type,
);

builder.check_dependencies().unwrap();
let builder = get_builder(Some(prefix.clone()), &manifest_dir, &out_dir);

#[allow(unused_assignments)]
let mut bindings_available = false;
Expand Down Expand Up @@ -275,9 +293,8 @@ fn main() {

assert!(
bindings_available,
"aws-lc-fip-sys build failed. Please enable the 'bindgen' feature on aws-lc-rs or aws-lc-fips-sys"
"aws-lc-fips-sys build failed. Please enable the 'bindgen' feature on aws-lc-rs or aws-lc-fips-sys"
);

builder.build().unwrap();

println!(
Expand Down
4 changes: 3 additions & 1 deletion aws-lc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ bindgen = ["dep:bindgen"] # Generate the bindings on the targetted platform as a
cmake = "0.1.48"
dunce = "1.0"
fs_extra = "1.3"
serde = { version = "1.0.195", features = ["derive"] }
toml = "0.6.0"
cc = { version = "1.0.83", features = ["parallel"] }

[target.'cfg(any(all(target_os = "macos", target_arch = "x86_64"), all(target_os = "linux", target_arch = "x86", target_env="gnu"), all(target_os = "linux", target_arch = "x86_64", target_env="gnu"), all(target_os = "linux", target_arch = "aarch64", target_env="gnu")))'.build-dependencies]
bindgen = { version = "0.69.1", optional = true }
Expand All @@ -64,6 +67,5 @@ bindgen = { version = "0.69.2" }
[dependencies]
libc = "0.2"
paste = "1.0.11"

[package.metadata.aws-lc-sys]
commit-hash = "c2b14dfb82e1a4d0f2260e05cf07c3a864e52d99"
Loading

0 comments on commit 5abfe93

Please sign in to comment.