Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report bindgen version #494

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ fn generate_src_bindings(manifest_dir: &Path, prefix: &Option<String>, src_bindi
..Default::default()
},
)
.write_to_file(src_bindings_path.join(format!("{}.rs", target_platform_prefix("crypto"))))
.expect("write bindings");
.write_to_file(src_bindings_path.join(format!("{}.rs", target_platform_prefix("crypto"))))
.expect("write bindings");

bindgen::generate_bindings(
manifest_dir,
Expand All @@ -215,8 +215,8 @@ fn generate_src_bindings(manifest_dir: &Path, prefix: &Option<String>, src_bindi
..Default::default()
},
)
.write_to_file(src_bindings_path.join(format!("{}.rs", target_platform_prefix("crypto_ssl"))))
.expect("write bindings");
.write_to_file(src_bindings_path.join(format!("{}.rs", target_platform_prefix("crypto_ssl"))))
.expect("write bindings");
}

fn emit_rustc_cfg(cfg: &str) {
Expand Down Expand Up @@ -358,6 +358,7 @@ fn is_bindgen_required() -> bool {
|| !has_pregenerated()
}

#[allow(dead_code)]
fn internal_bindgen_supported() -> bool {
// TODO: internal bindgen creates invalid bindings on FreeBSD
// See: https://github.com/aws/aws-lc-rs/issues/476
Expand Down Expand Up @@ -553,11 +554,7 @@ impl Debug for BindingOptions {
}
}

fn invoke_external_bindgen(
manifest_dir: &Path,
prefix: &Option<String>,
gen_bindings_path: &Path,
) -> Result<(), String> {
fn verify_bindgen() -> Result<(), String> {
let result = execute_command("bindgen".as_ref(), &["--version".as_ref()]);
if !result.status {
if !result.executed {
Expand All @@ -571,6 +568,40 @@ fn invoke_external_bindgen(
}
return Err("External bindgen command failed.".to_string());
}
let mut major_version: u32 = 0;
let mut minor_version: u32 = 0;
let mut patch_version: u32 = 0;
let bindgen_version = result.stdout.split(' ').skip(1).next();
justsmth marked this conversation as resolved.
Show resolved Hide resolved
if let Some(version) = bindgen_version {
let version_parts: Vec<&str> = version.trim().split('.').collect();
if version_parts.len() == 3 {
major_version = version_parts[0].parse::<u32>().unwrap_or(0);
minor_version = version_parts[1].parse::<u32>().unwrap_or(0);
patch_version = version_parts[2].parse::<u32>().unwrap_or(0);
}
}
// We currently expect to support all bindgen versions >= 0.69.3
if major_version == 0 && (minor_version < 69 || (minor_version == 69 && patch_version < 3)) {
eprintln!(
"bindgen-cli was used. Detected version was: {}.{}.{} \n\
If this is not the latest version, consider upgrading : \
`cargo install --force --locked bindgen-cli`\
\n\
See our User Guide for more information about bindgen:\
https://aws.github.io/aws-lc-rs/index.html",
major_version, minor_version, patch_version
);
Comment on lines +585 to +593
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eprintln!(
"bindgen-cli was used. Detected version was: {}.{}.{} \n\
If this is not the latest version, consider upgrading : \
`cargo install --force --locked bindgen-cli`\
\n\
See our User Guide for more information about bindgen:\
https://aws.github.io/aws-lc-rs/index.html",
major_version, minor_version, patch_version
);
eprintln!(
"bindgen-cli was used. Detected version was: {major_version}.{minor_version}.{patch_version} \n\
If this is not the latest version, consider upgrading : \
`cargo install --force --locked bindgen-cli`\
\n\
See our User Guide for more information about bindgen:\
https://aws.github.io/aws-lc-rs/index.html"
);

}
Ok(())
}

fn invoke_external_bindgen(
manifest_dir: &Path,
prefix: &Option<String>,
gen_bindings_path: &Path,
) -> Result<(), String> {
verify_bindgen()?;

let options = BindingOptions {
build_prefix: None,
include_ssl: false,
Expand Down
Loading