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 authored and justsmth committed Jan 18, 2024
1 parent bf861e4 commit 72bfef3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 40 deletions.
11 changes: 4 additions & 7 deletions aws-lc-fips-sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ if (BUILD_SHARED_LIBS AND FIPS)
# as cmake crate will postfix the C/CXX flags after our disablement nullifying them.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-function-sections -fno-data-sections")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-function-sections -fno-data-sections")
endif ()
endif()

add_subdirectory(aws-lc aws-lc EXCLUDE_FROM_ALL)

if (BUILD_LIBSSL)
add_definitions(-DAWS_LC_RUST_INCLUDE_SSL)
endif()
Expand All @@ -38,6 +39,7 @@ set(FINAL_ARTIFACTS_DIRECTORY ${CMAKE_BINARY_DIR}/artifacts)
# location to find the artifacts cross-platform.
set_my_target_properties(
ARCHIVE_OUTPUT_DIRECTORY ${FINAL_ARTIFACTS_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${FINAL_ARTIFACTS_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${FINAL_ARTIFACTS_DIRECTORY})

# Based on https://stackoverflow.com/a/7750816 as some generators, like MSVC, will try to prefix the output directory
Expand All @@ -46,6 +48,7 @@ foreach (OUT_NAME ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUT_NAME} OUT_NAME)
set_my_target_properties(
ARCHIVE_OUTPUT_DIRECTORY_${OUT_NAME} ${FINAL_ARTIFACTS_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY_${OUT_NAME} ${FINAL_ARTIFACTS_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY_${OUT_NAME} ${FINAL_ARTIFACTS_DIRECTORY})
endforeach ()

Expand All @@ -58,9 +61,3 @@ if (BORINGSSL_PREFIX)
endif()
set_my_target_properties(PREFIX ${TARGET_PREFIX})
endif ()

if (BUILD_LIBSSL)
install(TARGETS rust_wrapper crypto ssl DESTINATION .)
else()
install(TARGETS rust_wrapper crypto DESTINATION .)
endif()
10 changes: 5 additions & 5 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 Expand Up @@ -145,15 +147,13 @@ 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
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
4 changes: 4 additions & 0 deletions aws-lc-sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_subdirectory(aws-lc aws-lc EXCLUDE_FROM_ALL)
if (BUILD_LIBSSL)
add_definitions(-DAWS_LC_RUST_INCLUDE_SSL)
endif()

add_library(rust_wrapper rust_wrapper.c)
target_include_directories(rust_wrapper PRIVATE include)
target_link_libraries(rust_wrapper PUBLIC crypto)
Expand All @@ -31,6 +32,7 @@ set(FINAL_ARTIFACTS_DIRECTORY ${CMAKE_BINARY_DIR}/artifacts)
# location to find the artifacts cross-platform.
set_my_target_properties(
ARCHIVE_OUTPUT_DIRECTORY ${FINAL_ARTIFACTS_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${FINAL_ARTIFACTS_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${FINAL_ARTIFACTS_DIRECTORY})

# Based on https://stackoverflow.com/a/7750816 as some generators, like MSVC, will try to prefix the output directory
Expand All @@ -39,12 +41,14 @@ foreach (OUT_NAME ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUT_NAME} OUT_NAME)
set_my_target_properties(
ARCHIVE_OUTPUT_DIRECTORY_${OUT_NAME} ${FINAL_ARTIFACTS_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY_${OUT_NAME} ${FINAL_ARTIFACTS_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY_${OUT_NAME} ${FINAL_ARTIFACTS_DIRECTORY})
endforeach ()

if (BORINGSSL_PREFIX)
if (MSVC)
set(TARGET_PREFIX "${BORINGSSL_PREFIX}")
set_my_target_properties(IMPORT_PREFIX ${TARGET_PREFIX})
else()
set(TARGET_PREFIX "lib${BORINGSSL_PREFIX}")
endif()
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
15 changes: 6 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
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 72bfef3

Please sign in to comment.