Skip to content

Commit

Permalink
Clippy fix; emit warning when generating bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Apr 18, 2024
1 parent a105b4e commit abd8eb3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn test_command(executable: &OsStr, args: &[&OsStr]) -> TestCommandResult {
any(target_env = "gnu", target_env = "musl", target_env = "")
))
))]
fn generate_bindings(manifest_dir: &Path, prefix: Option<String>, bindings_path: &PathBuf) {
fn generate_bindings(manifest_dir: &Path, prefix: &Option<String>, bindings_path: &PathBuf) {
let options = BindingOptions {
build_prefix: prefix.clone(),
include_ssl: cfg!(feature = "ssl"),
Expand All @@ -193,7 +193,7 @@ fn generate_bindings(manifest_dir: &Path, prefix: Option<String>, bindings_path:
}

#[cfg(feature = "bindgen")]
fn generate_src_bindings(manifest_dir: &Path, prefix: Option<String>, src_bindings_path: &Path) {
fn generate_src_bindings(manifest_dir: &Path, prefix: &Option<String>, src_bindings_path: &Path) {
bindgen::generate_bindings(
manifest_dir,
&BindingOptions {
Expand Down Expand Up @@ -222,6 +222,10 @@ fn emit_rustc_cfg(cfg: &str) {
println!("cargo:rustc-cfg={cfg}");
}

fn emit_warning(message: &str) {
println!("cargo:warning={message}");
}

fn target_os() -> String {
cargo_env("CARGO_CFG_TARGET_OS")
}
Expand Down Expand Up @@ -350,8 +354,9 @@ fn main() {
if is_internal_bindgen() {
#[cfg(feature = "bindgen")]
{
emit_warning(&format!("Generating src bindings. Platform: {}", target()));
let src_bindings_path = Path::new(&manifest_dir).join("src");
generate_src_bindings(&manifest_dir, prefix.clone(), &src_bindings_path);
generate_src_bindings(&manifest_dir, &prefix, &src_bindings_path);
bindings_available = true;
}
} else if is_bindgen_required() {
Expand All @@ -364,8 +369,12 @@ fn main() {
))
))]
if !is_external_bindgen() {
emit_warning(&format!(
"Generating bindings - internal bindgen. Platform: {}",
target()
));
let gen_bindings_path = out_dir().join("bindings.rs");
generate_bindings(&manifest_dir, prefix.clone(), &gen_bindings_path);
generate_bindings(&manifest_dir, &prefix, &gen_bindings_path);
emit_rustc_cfg("use_bindgen_generated");
bindings_available = true;
}
Expand All @@ -374,6 +383,10 @@ fn main() {
}

if !bindings_available && !cfg!(feature = "ssl") {
emit_warning(&format!(
"Generating bindings - external bindgen. Platform: {}",
target()
));
let gen_bindings_path = out_dir().join("bindings.rs");
let result = invoke_external_bindgen(&manifest_dir, &prefix, &gen_bindings_path);
match result {
Expand Down Expand Up @@ -454,7 +467,7 @@ pub(crate) struct BindingOptions {
fn invoke_external_bindgen(
manifest_dir: &Path,
prefix: &Option<String>,
gen_bindings_path: &PathBuf,
gen_bindings_path: &Path,
) -> Result<(), String> {
if !test_command("bindgen".as_ref(), &["--version".as_ref()]).status {
return Err("External bindgen command not found.".to_string());
Expand Down

0 comments on commit abd8eb3

Please sign in to comment.