Skip to content

Commit ee3917f

Browse files
authored
aws-lc-sys: bindgen is optional (#949)
1 parent cd58abe commit ee3917f

File tree

2 files changed

+38
-77
lines changed

2 files changed

+38
-77
lines changed

aws-lc-sys/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ cmake.workspace = true
7171
dunce.workspace = true
7272
fs_extra.workspace = true
7373
cc = { workspace = true, features = ["parallel"] }
74-
75-
[target.'cfg(any(all(any(target_arch="x86_64",target_arch="aarch64"),any(target_os="linux",target_os="macos",target_os="windows"),any(target_env="gnu",target_env="musl",target_env="msvc",target_env="")),all(target_arch="x86",target_os="windows",target_env="msvc"),all(target_arch="x86",target_os="linux",target_env="gnu")))'.build-dependencies]
7674
bindgen = { workspace = true, optional = true }
7775

78-
[target.'cfg(not(any(all(any(target_arch="x86_64",target_arch="aarch64"),any(target_os="linux",target_os="macos",target_os="windows"),any(target_env="gnu",target_env="musl",target_env="msvc",target_env="")),all(target_arch="x86",target_os="windows",target_env="msvc"),all(target_arch="x86",target_os="linux",target_env="gnu"))))'.build-dependencies]
79-
bindgen.workspace = true
80-
8176
[package.metadata.aws-lc-sys]
8277
commit-hash = "7b627926398b6bb786296132b22dbb37bab7649f"

aws-lc-sys/builder/main.rs

Lines changed: 38 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,10 @@ const OSSL_CONF_DEFINES: &[&str] = &[
7171
"OPENSSL_NO_WHIRLPOOL",
7272
];
7373

74-
macro_rules! bindgen_available {
75-
($top:ident, $item:item) => {
76-
#[allow(clippy::non_minimal_cfg)]
77-
#[cfg($top(any(
78-
feature = "bindgen",
79-
not(any(
80-
all(
81-
any(target_arch = "x86_64", target_arch = "aarch64"),
82-
any(target_os = "linux", target_os = "macos", target_os = "windows"),
83-
any(
84-
target_env = "gnu",
85-
target_env = "musl",
86-
target_env = "msvc",
87-
target_env = ""
88-
)
89-
),
90-
all(target_arch = "x86", target_os = "windows", target_env = "msvc"),
91-
all(target_arch = "x86", target_os = "linux", target_env = "gnu"),
92-
all(target_arch = "riscv64", target_os = "linux", target_env = "gnu")
93-
))
94-
)))]
95-
$item
96-
};
97-
($item:item) => {
98-
bindgen_available!(any, $item);
99-
};
100-
}
101-
102-
bindgen_available!(
103-
mod sys_bindgen;
104-
);
10574
mod cc_builder;
10675
mod cmake_builder;
76+
#[cfg(feature = "bindgen")]
77+
mod sys_bindgen;
10778

10879
pub(crate) fn get_aws_lc_include_path(manifest_dir: &Path) -> PathBuf {
10980
manifest_dir.join("aws-lc").join("include")
@@ -334,21 +305,20 @@ fn execute_command(executable: &OsStr, args: &[&OsStr]) -> TestCommandResult {
334305
}
335306
}
336307

337-
bindgen_available!(
338-
fn generate_bindings(manifest_dir: &Path, prefix: &Option<String>, bindings_path: &PathBuf) {
339-
let options = BindingOptions {
340-
build_prefix: prefix.clone(),
341-
include_ssl: cfg!(feature = "ssl"),
342-
disable_prelude: true,
343-
};
308+
#[cfg(feature = "bindgen")]
309+
fn generate_bindings(manifest_dir: &Path, prefix: &Option<String>, bindings_path: &PathBuf) {
310+
let options = BindingOptions {
311+
build_prefix: prefix.clone(),
312+
include_ssl: cfg!(feature = "ssl"),
313+
disable_prelude: true,
314+
};
344315

345-
let bindings = sys_bindgen::generate_bindings(manifest_dir, &options);
316+
let bindings = sys_bindgen::generate_bindings(manifest_dir, &options);
346317

347-
bindings
348-
.write(Box::new(std::fs::File::create(bindings_path).unwrap()))
349-
.expect("written bindings");
350-
}
351-
);
318+
bindings
319+
.write(Box::new(std::fs::File::create(bindings_path).unwrap()))
320+
.expect("written bindings");
321+
}
352322

353323
#[cfg(feature = "bindgen")]
354324
fn generate_src_bindings(manifest_dir: &Path, prefix: &Option<String>, src_bindings_path: &Path) {
@@ -589,13 +559,12 @@ fn is_bindgen_required() -> bool {
589559
|| !has_pregenerated()
590560
}
591561

592-
bindgen_available!(
593-
fn internal_bindgen_supported() -> bool {
594-
let cv = bindgen::clang_version();
595-
emit_warning(format!("Clang version: {}", cv.full));
596-
true
597-
}
598-
);
562+
#[cfg(feature = "bindgen")]
563+
fn internal_bindgen_supported() -> bool {
564+
let cv = bindgen::clang_version();
565+
emit_warning(format!("Clang version: {}", cv.full));
566+
true
567+
}
599568

600569
fn is_no_prefix() -> bool {
601570
unsafe { AWS_LC_SYS_NO_PREFIX }
@@ -694,29 +663,26 @@ fn is_crt_static() -> bool {
694663
features.contains("crt-static")
695664
}
696665

697-
bindgen_available!(
698-
fn handle_bindgen(manifest_dir: &Path, prefix: &Option<String>) -> bool {
699-
if internal_bindgen_supported() && !is_external_bindgen_requested().unwrap_or(false) {
700-
emit_warning(format!(
701-
"Generating bindings - internal bindgen. Platform: {}",
702-
effective_target()
703-
));
704-
let gen_bindings_path = out_dir().join("bindings.rs");
705-
generate_bindings(manifest_dir, prefix, &gen_bindings_path);
706-
emit_rustc_cfg("use_bindgen_pregenerated");
707-
true
708-
} else {
709-
false
710-
}
711-
}
712-
);
713-
714-
bindgen_available!(
715-
not,
716-
fn handle_bindgen(_manifest_dir: &Path, _prefix: &Option<String>) -> bool {
666+
#[cfg(feature = "bindgen")]
667+
fn handle_bindgen(manifest_dir: &Path, prefix: &Option<String>) -> bool {
668+
if internal_bindgen_supported() && !is_external_bindgen_requested().unwrap_or(false) {
669+
emit_warning(format!(
670+
"Generating bindings - internal bindgen. Platform: {}",
671+
effective_target()
672+
));
673+
let gen_bindings_path = out_dir().join("bindings.rs");
674+
generate_bindings(manifest_dir, prefix, &gen_bindings_path);
675+
emit_rustc_cfg("use_bindgen_pregenerated");
676+
true
677+
} else {
717678
false
718679
}
719-
);
680+
}
681+
682+
#[cfg(not(feature = "bindgen"))]
683+
fn handle_bindgen(_manifest_dir: &Path, _prefix: &Option<String>) -> bool {
684+
false
685+
}
720686

721687
fn main() {
722688
initialize();

0 commit comments

Comments
 (0)