Skip to content

Commit

Permalink
Use C11; Align with AWS-LC v1.34.2
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Aug 28, 2024
1 parent f4e09c2 commit 3e327c1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sys-bindings-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
- name: No-prefix build for ${{ matrix.os }}
env:
AWS_LC_SYS_NO_PREFIX: "1"
# Ensure that we collect symbols unique to C99 builds
AWS_LC_SYS_C_STD: "99"
run: |
cargo test -p aws-lc-sys --features bindgen
- name: Collect symbols
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-sys/aws-lc
Submodule aws-lc updated 123 files
13 changes: 10 additions & 3 deletions aws-lc-sys/builder/cc_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ mod x86_64_unknown_linux_gnu;
mod x86_64_unknown_linux_musl;

use crate::{
cargo_env, env_var_to_bool, execute_command, out_dir, target, target_arch, target_os,
target_vendor, OutputLibType,
cargo_env, env_var_to_bool, execute_command, out_dir, requested_c_std, target, target_arch,
target_os, target_vendor, CStdRequested, OutputLibType,
};
use std::path::PathBuf;

Expand Down Expand Up @@ -96,15 +96,22 @@ impl CcBuilder {
}
}

fn apply_c_std(cc_build: &mut cc::Build) {
match requested_c_std() {
CStdRequested::C99 => cc_build.std("c99"),
_ => cc_build.std("c11"),
};
}

fn create_builder(&self) -> cc::Build {
let mut cc_build = cc::Build::default();
cc_build
.out_dir(&self.out_dir)
.flag("-std=c99")
.flag("-Wno-unused-parameter")
.cpp(false)
.shared_flag(false)
.static_flag(true);
CcBuilder::apply_c_std(&mut cc_build);
if target_os() == "linux" {
cc_build.define("_XOPEN_SOURCE", "700").flag("-lpthread");
}
Expand Down
13 changes: 11 additions & 2 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use crate::OutputLib::{Crypto, RustWrapper, Ssl};
use crate::{
allow_prebuilt_nasm, cargo_env, emit_warning, execute_command, is_crt_static, is_no_asm,
option_env, target, target_arch, target_env, target_family, target_os, target_underscored,
target_vendor, test_nasm_command, OutputLibType,
option_env, requested_c_std, target, target_arch, target_env, target_family, target_os,
target_underscored, target_vendor, test_nasm_command, CStdRequested, OutputLibType,
};
use std::env;
use std::ffi::OsString;
Expand Down Expand Up @@ -135,6 +135,15 @@ impl CmakeBuilder {

cmake_cfg.define("ASAN", "1");
}
match requested_c_std() {
CStdRequested::C99 => {
cmake_cfg.define("CMAKE_C_STANDARD", "99");
}
CStdRequested::C11 => {
cmake_cfg.define("CMAKE_C_STANDARD", "11");
}
CStdRequested::None => {}
}

// Allow environment to specify CMake toolchain.
if let Some(toolchain) = option_env("CMAKE_TOOLCHAIN_FILE").or(option_env(format!(
Expand Down
31 changes: 31 additions & 0 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,39 @@ trait Builder {
fn build(&self) -> Result<(), String>;
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum CStdRequested {
C99,
C11,
None,
}

impl CStdRequested {
fn from_env() -> Self {
if let Some(val) = option_env("AWS_LC_SYS_C_STD") {
let cstd = match val.as_str() {
"99" => CStdRequested::C99,
"11" => CStdRequested::C11,
_ => CStdRequested::None,
};
emit_warning(&format!(
"AWS_LC_SYS_C_STD environment variable set: {cstd:?}"
));
return cstd;
}
CStdRequested::None
}
}

static mut PREGENERATED: bool = false;
static mut AWS_LC_SYS_NO_PREFIX: bool = false;
static mut AWS_LC_SYS_INTERNAL_BINDGEN: bool = false;
static mut AWS_LC_SYS_EXTERNAL_BINDGEN: bool = false;
static mut AWS_LC_SYS_NO_ASM: bool = false;
static mut AWS_LC_SYS_PREBUILT_NASM: Option<bool> = None;

static mut AWS_LC_SYS_C_STD: CStdRequested = CStdRequested::None;

fn initialize() {
unsafe {
AWS_LC_SYS_NO_PREFIX = env_var_to_bool("AWS_LC_SYS_NO_PREFIX").unwrap_or(false);
Expand All @@ -330,6 +356,7 @@ fn initialize() {
env_var_to_bool("AWS_LC_SYS_EXTERNAL_BINDGEN").unwrap_or(false);
AWS_LC_SYS_NO_ASM = env_var_to_bool("AWS_LC_SYS_NO_ASM").unwrap_or(false);
AWS_LC_SYS_PREBUILT_NASM = env_var_to_bool("AWS_LC_SYS_PREBUILT_NASM");
AWS_LC_SYS_C_STD = CStdRequested::from_env();
}

if !is_external_bindgen() && (is_internal_bindgen() || !has_bindgen_feature()) {
Expand Down Expand Up @@ -392,6 +419,10 @@ fn allow_prebuilt_nasm() -> Option<bool> {
unsafe { AWS_LC_SYS_PREBUILT_NASM }
}

fn requested_c_std() -> CStdRequested {
unsafe { AWS_LC_SYS_C_STD }
}

fn has_bindgen_feature() -> bool {
cfg!(feature = "bindgen")
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/collect_nasm_obj.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ for nasm_file in `find aws-lc-sys/aws-lc/generated-src/win-x86_64/ -name "*.asm"
cp "${NASM_OBJ}" "${PREBUILT_NASM_DIR}"
# We remove the '.debug$S' value, which indicates the size of the debug section. This value can change across builds
# because it typically contains full source file paths that vary by build environment
"${DUMPBIN}" //DISASM "${PREBUILT_NASM_DIR}"/"${OBJNAME/.asm/.obj}" | grep -v '.debug$S' | sed -e "s/^Dump of file.*/Dump of file ${OBJNAME/.asm/.obj}/" > "${PREBUILT_NASM_DIR}"/"${OBJNAME/.asm/}"-disasm.txt
"${DUMPBIN}" //DISASM "${PREBUILT_NASM_DIR}"/"${OBJNAME/.asm/.obj}" | grep -v '.debug$S' | grep -v 'Dumper Version' | sed -e "s/^Dump of file.*/Dump of file ${OBJNAME/.asm/.obj}/" > "${PREBUILT_NASM_DIR}"/"${OBJNAME/.asm/}"-disasm.txt
done

0 comments on commit 3e327c1

Please sign in to comment.