Skip to content

Commit ef59023

Browse files
authored
Disallow external bindgen when AWS_LC_SYS_EXTERNAL_BINDGEN=0 (#808)
* Disallow external bindgen when AWS_LC_SYS_EXTERNAL_BINDGEN=0 * Fix s390x-unknown-linux-gnu CI test
1 parent 2833d9b commit ef59023

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

.github/workflows/cross.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ jobs:
2323
if: github.repository_owner == 'aws'
2424
name: cross tests ${{ matrix.target[0] }}
2525
runs-on: ubuntu-22.04
26+
env:
27+
# The flag below is set to avoid the following error with GCC 11.4.0 on the riscv64 platform:
28+
# /home/runner/work/aws-lc-rs/aws-lc-rs/aws-lc-sys/aws-lc/crypto/pem/pem_lib.c:707:11: error: 'strncmp' of strings of length 1 and 9 and bound of 9 evaluates to nonzero [-Werror=string-compare]
29+
# 707 | if (strncmp(buf, "-----END ", 9) == 0) {
30+
# | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
31+
AWS_LC_SYS_CFLAGS_riscv64gc_unknown_linux_gnu: '-Wno-string-compare'
2632
strategy:
2733
fail-fast: false
2834
matrix:
@@ -42,7 +48,7 @@ jobs:
4248
- [ powerpc64-unknown-linux-gnu, 1, 0 ]
4349
- [ powerpc64le-unknown-linux-gnu, 1, 0 ]
4450
- [ riscv64gc-unknown-linux-gnu, 0, 1 ]
45-
- [ s390x-unknown-linux-gnu, 0, 1 ]
51+
- [ s390x-unknown-linux-gnu, 0, 0 ]
4652
- [ x86_64-pc-windows-gnu, 0, 1 ] # Requires release build. See: https://github.com/rust-lang/rust/issues/139380
4753
- [ x86_64-unknown-linux-musl, 0, 1 ]
4854
- [ x86_64-unknown-illumos, 0, 0 ]
@@ -62,13 +68,6 @@ jobs:
6268
target: ${{ matrix.target[0] }}
6369
- name: Set Rust toolchain override
6470
run: rustup override set ${{ steps.toolchain.outputs.name }}
65-
# The flag below is set to avoid the following error with GCC 11.4.0 on the riscv64 platform:
66-
# /home/runner/work/aws-lc-rs/aws-lc-rs/aws-lc-sys/aws-lc/crypto/pem/pem_lib.c:707:11: error: 'strncmp' of strings of length 1 and 9 and bound of 9 evaluates to nonzero [-Werror=string-compare]
67-
# 707 | if (strncmp(buf, "-----END ", 9) == 0) {
68-
# | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
69-
- if: ${{ matrix.target[0] == 'riscv64gc-unknown-linux-gnu' }}
70-
run: |
71-
echo 'AWS_LC_SYS_CFLAGS=-Wno-string-compare' >> "$GITHUB_ENV"
7271
- if: ${{ !startsWith(matrix.target[0], 'x86_64') }}
7372
run: |
7473
echo 'AWS_LC_RS_DISABLE_SLOW_TESTS=1' >> "$GITHUB_ENV"

aws-lc-sys/builder/main.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ impl CStdRequested {
496496
static mut PREGENERATED: bool = false;
497497
static mut AWS_LC_SYS_NO_PREFIX: bool = false;
498498
static mut AWS_LC_SYS_PREGENERATING_BINDINGS: bool = false;
499-
static mut AWS_LC_SYS_EXTERNAL_BINDGEN: bool = false;
499+
static mut AWS_LC_SYS_EXTERNAL_BINDGEN: Option<bool> = None;
500500
static mut AWS_LC_SYS_NO_ASM: bool = false;
501501
static mut AWS_LC_SYS_CFLAGS: String = String::new();
502502
static mut AWS_LC_SYS_PREBUILT_NASM: Option<bool> = None;
@@ -511,7 +511,7 @@ fn initialize() {
511511
AWS_LC_SYS_NO_PREFIX = env_crate_var_to_bool("NO_PREFIX").unwrap_or(false);
512512
AWS_LC_SYS_PREGENERATING_BINDINGS =
513513
env_crate_var_to_bool("PREGENERATING_BINDINGS").unwrap_or(false);
514-
AWS_LC_SYS_EXTERNAL_BINDGEN = env_crate_var_to_bool("EXTERNAL_BINDGEN").unwrap_or(false);
514+
AWS_LC_SYS_EXTERNAL_BINDGEN = env_crate_var_to_bool("EXTERNAL_BINDGEN");
515515
AWS_LC_SYS_NO_ASM = env_crate_var_to_bool("NO_ASM").unwrap_or(false);
516516
AWS_LC_SYS_CFLAGS = optional_env_optional_crate_target("CFLAGS").unwrap_or_default();
517517
AWS_LC_SYS_PREBUILT_NASM = env_crate_var_to_bool("PREBUILT_NASM");
@@ -523,7 +523,9 @@ fn initialize() {
523523
optional_env_crate_target("EFFECTIVE_TARGET").unwrap_or_default();
524524
}
525525

526-
if !is_external_bindgen() && (is_pregenerating_bindings() || !has_bindgen_feature()) {
526+
if !is_external_bindgen_requested().unwrap_or(false)
527+
&& (is_pregenerating_bindings() || !has_bindgen_feature())
528+
{
527529
let target = effective_target();
528530
let supported_platform = match target.as_str() {
529531
"aarch64-apple-darwin"
@@ -553,7 +555,7 @@ fn initialize() {
553555
fn is_bindgen_required() -> bool {
554556
is_no_prefix()
555557
|| is_pregenerating_bindings()
556-
|| is_external_bindgen()
558+
|| is_external_bindgen_requested().unwrap_or(false)
557559
|| has_bindgen_feature()
558560
|| !has_pregenerated()
559561
}
@@ -574,7 +576,7 @@ fn is_pregenerating_bindings() -> bool {
574576
unsafe { AWS_LC_SYS_PREGENERATING_BINDINGS }
575577
}
576578

577-
fn is_external_bindgen() -> bool {
579+
fn is_external_bindgen_requested() -> Option<bool> {
578580
unsafe { AWS_LC_SYS_EXTERNAL_BINDGEN }
579581
}
580582

@@ -655,7 +657,7 @@ fn is_crt_static() -> bool {
655657

656658
bindgen_available!(
657659
fn handle_bindgen(manifest_dir: &Path, prefix: &Option<String>) -> bool {
658-
if internal_bindgen_supported() && !is_external_bindgen() {
660+
if internal_bindgen_supported() && !is_external_bindgen_requested().unwrap_or(false) {
659661
emit_warning(&format!(
660662
"Generating bindings - internal bindgen. Platform: {}",
661663
effective_target()
@@ -704,7 +706,7 @@ fn main() {
704706
let src_bindings_path = Path::new(&manifest_dir)
705707
.join("src")
706708
.join(format!("{}.rs", target_platform_prefix("crypto")));
707-
if is_external_bindgen() {
709+
if is_external_bindgen_requested().unwrap_or(false) {
708710
invoke_external_bindgen(&manifest_dir, &prefix, &src_bindings_path).unwrap();
709711
} else {
710712
generate_src_bindings(&manifest_dir, &prefix, &src_bindings_path);
@@ -827,6 +829,12 @@ impl Debug for BindingOptions {
827829
}
828830

829831
fn verify_bindgen() -> Result<(), String> {
832+
if !is_external_bindgen_requested().unwrap_or(true) {
833+
return Err(
834+
"external bindgen usage prevented by AWS_LC_SYS_EXTERNAL_BINDGEN=0".to_string(),
835+
);
836+
}
837+
830838
let result = execute_command("bindgen".as_ref(), &["--version".as_ref()]);
831839
if !result.status {
832840
if result.executed {

0 commit comments

Comments
 (0)