Skip to content

Commit

Permalink
* Realign aws-lc-sys build with aws-lc-fips-sys
Browse files Browse the repository at this point in the history
* cleanup
  • Loading branch information
justinwsmith committed Jan 18, 2024
1 parent bf861e4 commit 55d78de
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
8 changes: 5 additions & 3 deletions aws-lc-fips-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,20 @@ impl CmakeBuilder {
// The Windows/FIPS build rejects "debug" profile
// https://github.com/aws/aws-lc/blob/main/CMakeLists.txt#L656
cmake_cfg.define("CMAKE_BUILD_TYPE", "relwithdebinfo");
} else {
cmake_cfg.define("CMAKE_BUILD_TYPE", "debug");
}

if target_os() == "windows" {
cmake_cfg.generator("Ninja");
let env_map = self
.collect_vcvarsall_bat()
.map_err(|x| panic!("{}", x))
.unwrap();
println!("Setting environment!");
for (key, value) in env_map {
println!("ENV-{}={}", key.as_str(), value.as_str());
cmake_cfg.env(key, value);
}
} else {
cmake_cfg.define("CMAKE_BUILD_TYPE", "debug");
}

if let Some(prefix) = &self.build_prefix {
Expand Down
7 changes: 2 additions & 5 deletions aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ enum OutputLibType {

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 {
if let Ok(build_type) = env::var("AWS_LC_FIPS_SYS_STATIC") {
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();
Expand Down Expand Up @@ -228,9 +227,8 @@ trait Builder {
}

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

let mut is_bindgen_required = cfg!(feature = "bindgen");
let output_lib_type = OutputLibType::default();

let is_internal_generate = env::var("AWS_LC_RUST_INTERNAL_BINDGEN")
.unwrap_or_else(|_| String::from("0"))
Expand Down Expand Up @@ -291,7 +289,6 @@ fn main() {
bindings_available,
"aws-lc-fip-sys build failed. Please enable the 'bindgen' feature on aws-lc-rs or aws-lc-fips-sys"
);

builder.build().unwrap();

println!(
Expand Down
1 change: 1 addition & 0 deletions aws-lc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bindgen = ["dep:bindgen"] # Generate the bindings on the targetted platform as a
cmake = "0.1.48"
dunce = "1.0"
fs_extra = "1.3"
which = "5.0"

[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 Down
17 changes: 8 additions & 9 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0 OR ISC

use crate::OutputLib::{Crypto, RustWrapper, Ssl};
use crate::{target, target_arch, target_os, target_vendor, test_command, OutputLibType};
use crate::{target, target_arch, target_os, target_vendor, OutputLibType};
use std::env;
use std::ffi::OsStr;
use std::path::PathBuf;
use which::which;

pub(crate) struct CmakeBuilder {
manifest_dir: PathBuf,
Expand All @@ -14,14 +14,11 @@ pub(crate) struct CmakeBuilder {
output_lib_type: OutputLibType,
}

fn find_cmake_command() -> Option<&'static OsStr> {
if test_command("cmake3".as_ref(), &["--version".as_ref()]) {
Some("cmake3".as_ref())
} else if test_command("cmake".as_ref(), &["--version".as_ref()]) {
Some("cmake".as_ref())
} else {
None
fn find_cmake_command() -> Option<PathBuf> {
if let Ok(path) = which("cmake").or_else(|_| which("cmake3")) {
return Some(path);
}
None
}

fn get_platform_output_path() -> PathBuf {
Expand Down Expand Up @@ -120,13 +117,15 @@ impl CmakeBuilder {

cmake_cfg.define("ASAN", "1");
}
cmake_cfg.define("CMAKE_INSTALL_PREFIX", self.artifact_output_dir());

cmake_cfg
}

fn build_rust_wrapper(&self) -> PathBuf {
self.prepare_cmake_build()
.configure_arg("--no-warn-unused-cli")
.build_target("install")
.build()
}
}
Expand Down
12 changes: 1 addition & 11 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
// SPDX-License-Identifier: Apache-2.0 OR ISC

use std::env;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::process::Command;

use cmake_builder::CmakeBuilder;

Expand Down Expand Up @@ -57,8 +55,7 @@ enum OutputLibType {

impl Default for OutputLibType {
fn default() -> Self {
let build_type_result = env::var("AWS_LC_SYS_STATIC");
if let Ok(build_type) = build_type_result {
if let Ok(build_type) = env::var("AWS_LC_SYS_STATIC") {
eprintln!("AWS_LC_SYS_STATIC={build_type}");
// If the environment variable is set, we ignore every other factor.
let build_type = build_type.to_lowercase();
Expand Down Expand Up @@ -109,13 +106,6 @@ fn target_platform_prefix(name: &str) -> String {
format!("{}_{}_{}", env::consts::OS, env::consts::ARCH, name)
}

fn test_command(executable: &OsStr, args: &[&OsStr]) -> bool {
if let Ok(output) = Command::new(executable).args(args).output() {
return output.status.success();
}
false
}

#[cfg(any(
feature = "bindgen",
not(any(
Expand Down
9 changes: 6 additions & 3 deletions aws-lc-sys/include/rust_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#ifdef _WIN32
#define BORINGSSL_SHARED_LIBRARY
#define AWS_LC_FIPS_SYS_EXPORT __declspec(dllexport)
#else
#define AWS_LC_FIPS_SYS_EXPORT __attribute__((visibility("default")))
#endif

#include <openssl/err.h>
Expand All @@ -20,9 +23,9 @@ extern "C" {
// The following functions are wrappers over inline functions and macros in
// BoringSSL, which bindgen cannot currently correctly bind. These wrappers
// ensure changes to the functions remain in lockstep with the Rust versions.
int ERR_GET_LIB_RUST(uint32_t packed_error);
int ERR_GET_REASON_RUST(uint32_t packed_error);
int ERR_GET_FUNC_RUST(uint32_t packed_error);
AWS_LC_FIPS_SYS_EXPORT int ERR_GET_LIB_RUST(uint32_t packed_error);
AWS_LC_FIPS_SYS_EXPORT int ERR_GET_REASON_RUST(uint32_t packed_error);
AWS_LC_FIPS_SYS_EXPORT int ERR_GET_FUNC_RUST(uint32_t packed_error);


#if defined(__cplusplus)
Expand Down

0 comments on commit 55d78de

Please sign in to comment.