in aws-lc-fips-sys/builder/main.rs [707:803]
fn invoke_external_bindgen(
manifest_dir: &Path,
options: &BindingOptions,
gen_bindings_path: &Path,
) -> Result<(), String> {
verify_bindgen()?;
emit_warning(&format!(
"Generating bindings - external bindgen. Platform: '{}' Prefix: '{:?}'",
effective_target(),
&options.build_prefix
));
let mut clang_args = prepare_clang_args(
manifest_dir,
&BindingOptions {
// For external bindgen, we don't want the prefix headers to be included.
// The bindgen-cli will add prefixes to the symbols to form the correct link name.
build_prefix: None,
include_ssl: options.include_ssl,
disable_prelude: options.disable_prelude,
},
);
let header = get_rust_include_path(manifest_dir)
.join("rust_wrapper.h")
.display()
.to_string();
if options.include_ssl {
clang_args.extend([String::from("-DAWS_LC_RUST_INCLUDE_SSL")]);
}
let sym_prefix: String;
let mut bindgen_params = vec![];
if let Some(prefix_str) = &options.build_prefix {
sym_prefix = if target_os().to_lowercase() == "macos"
|| target_os().to_lowercase() == "ios"
|| (target_os().to_lowercase() == "windows" && target_arch() == "x86")
{
format!("_{prefix_str}_")
} else {
format!("{prefix_str}_")
};
bindgen_params.extend(vec!["--prefix-link-name", sym_prefix.as_str()]);
}
// These flags needs to be kept in sync with the setup in bindgen::prepare_bindings_builder
// If `bindgen-cli` makes backwards incompatible changes, we will update the parameters below
// to conform with the most recent release. We will guide consumers to likewise use the
// latest version of bindgen-cli.
bindgen_params.extend(vec![
"--allowlist-file",
r".*(/|\\)openssl((/|\\)[^/\\]+)+\.h",
"--allowlist-file",
r".*(/|\\)rust_wrapper\.h",
"--rustified-enum",
r"point_conversion_form_t",
"--default-macro-constant-type",
r"signed",
"--with-derive-default",
"--with-derive-partialeq",
"--with-derive-eq",
"--raw-line",
COPYRIGHT,
"--generate",
"functions,types,vars,methods,constructors,destructors",
header.as_str(),
"--rust-target",
r"1.59",
"--output",
gen_bindings_path.to_str().unwrap(),
"--formatter",
r"rustfmt",
]);
if !options.disable_prelude {
bindgen_params.extend(["--raw-line", PRELUDE]);
}
bindgen_params.push("--");
clang_args
.iter()
.for_each(|x| bindgen_params.push(x.as_str()));
let cmd_params: Vec<OsString> = bindgen_params.iter().map(OsString::from).collect();
let cmd_params: Vec<&OsStr> = cmd_params.iter().map(OsString::as_os_str).collect();
let result = execute_command("bindgen".as_ref(), cmd_params.as_ref());
if !result.status {
return Err(format!(
"\n\n\
bindgen-PARAMS: {}\n\
bindgen-STDOUT: {}\n\
bindgen-STDERR: {}",
bindgen_params.join(" "),
result.stdout.as_ref(),
result.stderr.as_ref()
));
}
Ok(())
}