Skip to content

Commit c2f3298

Browse files
justsmthaws-lc-fips-sys-bindings-generator
and
aws-lc-fips-sys-bindings-generator
authored
Prepare aws-lc-fips-sys v0.13.1 (#651)
* Prepare aws-lc-sys v0.13.1 * Symbols from macos-14-xlarge * Symbols from ubuntu-latest * Symbols from macos-13 * Symbols for aarch64-unknown-linux-gnu * Symbols for aarch64-unknown-linux-musl * Symbols for x86_64-unknown-linux-musl * Generated headers * Generated bindings from macos-14-xlarge * Generated bindings from ubuntu-latest * Generated bindings from macos-13 * Generated bindings for aarch64-unknown-linux-gnu * Generated bindings for x86_64-unknown-linux-musl * Generated bindings for aarch64-unknown-linux-musl --------- Co-authored-by: aws-lc-fips-sys-bindings-generator <[email protected]>
1 parent c5e6879 commit c2f3298

12 files changed

+15833
-15637
lines changed

aws-lc-fips-sys/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "aws-lc-fips-sys"
33
description = "AWS-LC is a general-purpose cryptographic library maintained by the AWS Cryptography team for AWS and their customers. This is the FIPS validated version of AWS-LC."
4-
version = "0.13.0"
5-
links = "aws_lc_fips_0_13_0"
4+
version = "0.13.1"
5+
links = "aws_lc_fips_0_13_1"
66
authors = ["AWS-LC"]
77
edition = "2021"
88
repository = "https://github.com/aws/aws-lc-rs"

aws-lc-fips-sys/builder/main.rs

+100-25
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,28 @@ fn generate_src_bindings(manifest_dir: &Path, prefix: &Option<String>, src_bindi
271271
&BindingOptions {
272272
build_prefix: prefix.clone(),
273273
include_ssl: false,
274-
..Default::default()
274+
disable_prelude: false,
275275
},
276276
)
277-
.write_to_file(src_bindings_path.join(format!("{}.rs", target_platform_prefix("crypto"))))
277+
.write_to_file(src_bindings_path)
278+
.expect("write bindings");
279+
}
280+
281+
#[allow(unused)]
282+
fn external_generate_src_bindings(
283+
manifest_dir: &Path,
284+
prefix: &Option<String>,
285+
src_bindings_path: &Path,
286+
) {
287+
invoke_external_bindgen(
288+
manifest_dir,
289+
&BindingOptions {
290+
build_prefix: prefix.clone(),
291+
include_ssl: false,
292+
disable_prelude: false,
293+
},
294+
src_bindings_path,
295+
)
278296
.expect("write bindings");
279297
}
280298

@@ -356,7 +374,15 @@ fn initialize() {
356374
AWS_LC_FIPS_SYS_NO_ASM = env_var_to_bool("AWS_LC_FIPS_SYS_NO_ASM").unwrap_or(false);
357375
}
358376

359-
if !is_external_bindgen() && (is_pregenerating_bindings() || !has_bindgen_feature()) {
377+
// The conditions below should prevent use of pregenerated bindings in all cases where the
378+
// consumer either requires or is requesting bindings generation.
379+
if (!is_no_prefix()
380+
&& !has_bindgen_feature()
381+
&& !is_external_bindgen()
382+
&& cfg!(not(feature = "ssl")))
383+
|| is_pregenerating_bindings()
384+
{
385+
// We only set the PREGENERATED flag when we know pregenerated bindings are available.
360386
let target = target();
361387
let supported_platform = match target.as_str() {
362388
"x86_64-unknown-linux-gnu"
@@ -479,12 +505,18 @@ fn main() {
479505
if is_pregenerating_bindings() {
480506
#[cfg(feature = "bindgen")]
481507
{
508+
let src_bindings_path = Path::new(&manifest_dir)
509+
.join("src")
510+
.join(format!("{}.rs", target_platform_prefix("crypto")));
482511
emit_warning(&format!(
483-
"Generating src bindings. Platform: '{}' Prefix: '{prefix:?}'",
484-
target()
512+
"Generating src bindings: {}",
513+
&src_bindings_path.display()
485514
));
486-
let src_bindings_path = Path::new(&manifest_dir).join("src");
487-
generate_src_bindings(&manifest_dir, &prefix, &src_bindings_path);
515+
if is_external_bindgen() {
516+
external_generate_src_bindings(&manifest_dir, &prefix, &src_bindings_path);
517+
} else {
518+
generate_src_bindings(&manifest_dir, &prefix, &src_bindings_path);
519+
}
488520
bindings_available = true;
489521
}
490522
} else if is_bindgen_required() {
@@ -493,13 +525,14 @@ fn main() {
493525
bindings_available = true;
494526
}
495527

496-
if !bindings_available && !cfg!(feature = "ssl") {
497-
emit_warning(&format!(
498-
"Generating bindings - external bindgen. Platform: {}",
499-
target()
500-
));
528+
if !bindings_available {
529+
let options = BindingOptions {
530+
build_prefix: prefix,
531+
include_ssl: cfg!(feature = "ssl"),
532+
disable_prelude: true,
533+
};
501534
let gen_bindings_path = out_dir().join("bindings.rs");
502-
let result = invoke_external_bindgen(&manifest_dir, &prefix, &gen_bindings_path);
535+
let result = invoke_external_bindgen(&manifest_dir, &options, &gen_bindings_path);
503536
match result {
504537
Ok(()) => {
505538
emit_rustc_cfg("use_bindgen_generated");
@@ -628,30 +661,69 @@ fn verify_bindgen() -> Result<(), String> {
628661
Ok(())
629662
}
630663

664+
const PRELUDE: &str = r"
665+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
666+
// SPDX-License-Identifier: Apache-2.0 OR ISC
667+
668+
#![allow(
669+
clippy::cast_lossless,
670+
clippy::cast_possible_truncation,
671+
clippy::default_trait_access,
672+
clippy::must_use_candidate,
673+
clippy::not_unsafe_ptr_arg_deref,
674+
clippy::ptr_as_ptr,
675+
clippy::pub_underscore_fields,
676+
clippy::semicolon_if_nothing_returned,
677+
clippy::too_many_lines,
678+
clippy::unreadable_literal,
679+
clippy::used_underscore_binding,
680+
clippy::useless_transmute,
681+
dead_code,
682+
improper_ctypes,
683+
non_camel_case_types,
684+
non_snake_case,
685+
non_upper_case_globals,
686+
unused_imports,
687+
)]
688+
";
689+
631690
fn invoke_external_bindgen(
632691
manifest_dir: &Path,
633-
prefix: &Option<String>,
692+
options: &BindingOptions,
634693
gen_bindings_path: &Path,
635694
) -> Result<(), String> {
636695
verify_bindgen()?;
696+
emit_warning(&format!(
697+
"Generating bindings - external bindgen. Platform: '{}' Prefix: '{:?}'",
698+
target(),
699+
&options.build_prefix
700+
));
637701

638-
let options = BindingOptions {
639-
// We collect the symbols w/o the prefix added
640-
build_prefix: None,
641-
include_ssl: false,
642-
disable_prelude: true,
643-
};
644-
645-
let clang_args = prepare_clang_args(manifest_dir, &options);
702+
let mut clang_args = prepare_clang_args(
703+
manifest_dir,
704+
&BindingOptions {
705+
// For external bindgen, we don't want the prefix headers to be included.
706+
// The bindgen-cli will add prefixes to the symbols to form the correct link name.
707+
build_prefix: None,
708+
include_ssl: options.include_ssl,
709+
disable_prelude: options.disable_prelude,
710+
},
711+
);
646712
let header = get_rust_include_path(manifest_dir)
647713
.join("rust_wrapper.h")
648714
.display()
649715
.to_string();
650716

717+
if options.include_ssl {
718+
clang_args.extend([String::from("-DAWS_LC_RUST_INCLUDE_SSL")]);
719+
}
720+
651721
let sym_prefix: String;
652722
let mut bindgen_params = vec![];
653-
if let Some(prefix_str) = prefix {
654-
sym_prefix = if target_os().to_lowercase() == "macos" || target_os().to_lowercase() == "ios"
723+
if let Some(prefix_str) = &options.build_prefix {
724+
sym_prefix = if target_os().to_lowercase() == "macos"
725+
|| target_os().to_lowercase() == "ios"
726+
|| (target_os().to_lowercase() == "windows" && target_arch() == "x86")
655727
{
656728
format!("_{prefix_str}_")
657729
} else {
@@ -687,8 +759,11 @@ fn invoke_external_bindgen(
687759
gen_bindings_path.to_str().unwrap(),
688760
"--formatter",
689761
r"rustfmt",
690-
"--",
691762
]);
763+
if !options.disable_prelude {
764+
bindgen_params.extend(["--raw-line", PRELUDE]);
765+
}
766+
bindgen_params.push("--");
692767
clang_args
693768
.iter()
694769
.for_each(|x| bindgen_params.push(x.as_str()));

aws-lc-fips-sys/builder/sys_bindgen.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR ISC
33

4-
use crate::{get_rust_include_path, BindingOptions, COPYRIGHT};
4+
use crate::{get_rust_include_path, BindingOptions, COPYRIGHT, PRELUDE};
55
use bindgen::callbacks::{ItemInfo, ParseCallbacks};
66
use std::fmt::Debug;
77
use std::path::Path;
@@ -31,29 +31,6 @@ impl ParseCallbacks for StripPrefixCallback {
3131
}
3232
}
3333

34-
const PRELUDE: &str = r"
35-
#![allow(
36-
clippy::cast_lossless,
37-
clippy::cast_possible_truncation,
38-
clippy::default_trait_access,
39-
clippy::must_use_candidate,
40-
clippy::not_unsafe_ptr_arg_deref,
41-
clippy::ptr_as_ptr,
42-
clippy::pub_underscore_fields,
43-
clippy::semicolon_if_nothing_returned,
44-
clippy::too_many_lines,
45-
clippy::unreadable_literal,
46-
clippy::used_underscore_binding,
47-
clippy::useless_transmute,
48-
dead_code,
49-
improper_ctypes,
50-
non_camel_case_types,
51-
non_snake_case,
52-
non_upper_case_globals,
53-
unused_imports,
54-
)]
55-
";
56-
5734
fn prepare_bindings_builder(manifest_dir: &Path, options: &BindingOptions) -> bindgen::Builder {
5835
let clang_args = crate::prepare_clang_args(manifest_dir, options);
5936

@@ -62,7 +39,7 @@ fn prepare_bindings_builder(manifest_dir: &Path, options: &BindingOptions) -> bi
6239
.derive_debug(true)
6340
.derive_default(true)
6441
.derive_eq(true)
65-
.allowlist_file(r".*(/|\\)openssl(/|\\)[^/\\]+\.h")
42+
.allowlist_file(r".*(/|\\)openssl((/|\\)[^/\\]+)+\.h")
6643
.allowlist_file(r".*(/|\\)rust_wrapper\.h")
6744
.rustified_enum(r"point_conversion_form_t")
6845
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)

aws-lc-fips-sys/generated-include/openssl/boringssl_prefix_symbols.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define BORINGSSL_PREFIX_SYMBOLS_H
1818

1919
#ifndef BORINGSSL_PREFIX
20-
#define BORINGSSL_PREFIX aws_lc_fips_0_13_0
20+
#define BORINGSSL_PREFIX aws_lc_fips_0_13_1
2121
#endif // BORINGSSL_PREFIX
2222

2323

aws-lc-fips-sys/generated-include/openssl/boringssl_prefix_symbols_asm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define BORINGSSL_PREFIX_SYMBOLS_ASM_H
2121

2222
#ifndef BORINGSSL_PREFIX
23-
#define BORINGSSL_PREFIX aws_lc_fips_0_13_0
23+
#define BORINGSSL_PREFIX aws_lc_fips_0_13_1
2424
#endif // BORINGSSL_PREFIX
2525

2626
// On iOS and macOS, we need to treat assembly symbols differently from other

aws-lc-fips-sys/generated-include/openssl/boringssl_prefix_symbols_nasm.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
%define BORINGSSL_PREFIX_SYMBOLS_NASM_INC
1818

1919
%ifndef BORINGSSL_PREFIX
20-
%define BORINGSSL_PREFIX aws_lc_fips_0_13_0
20+
%define BORINGSSL_PREFIX aws_lc_fips_0_13_1
2121
%endif ; BORINGSSL_PREFIX
2222

2323
; 32-bit Windows adds underscores to C functions, while 64-bit Windows does not.

0 commit comments

Comments
 (0)