From 316f7c90615f341769a00abc9c362e59eaa994a9 Mon Sep 17 00:00:00 2001 From: Sebastian Scholz Date: Fri, 6 Oct 2023 17:09:35 +0200 Subject: [PATCH] Rename wrap_static_fns_suffix and use it for functional macros --- CHANGELOG.md | 4 +++- bindgen-cli/options.rs | 12 ++++++------ bindgen/codegen/mod.rs | 7 ++----- bindgen/codegen/serialize.rs | 2 +- bindgen/ir/context.rs | 11 ++++++----- bindgen/lib.rs | 4 ++-- bindgen/options/mod.rs | 14 +++++++------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2eb509258..7092e2b85f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -194,8 +194,10 @@ `CargoCallbacks` constant was added to mitigate the breaking nature of this change. This constant has been marked as deprecated and users will have to use the new `CargoCallbacks::new` method in the future. -- Renamed `--wrap-static-fns-path` argument to `-wrapper-code-generation-path` and the +- Renamed `--wrap-static-fns-path` argument to `--wrapper-code-generation-path` and the corresponding `wrap_static_fns_path` builder function to `wrapper_code_generation_path`. +- Renamed `--wrap-static-fns-suffix` argument to `--wrapper-function-suffix` and the + corresponding `wrap_static_fns_suffix` builder function to `wrapper_function_suffix`. ## Removed ## Fixed - Allow compiling `bindgen-cli` with a static libclang. diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index a00939b160..3df6ab344f 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -416,10 +416,10 @@ struct BindgenCommand { /// Sets the path of the file where generated code for wrapper functions will be emitted. #[arg(long, requires = "experimental", value_name = "PATH")] wrapper_code_generation_path: Option, - /// Sets the SUFFIX added to the extern wrapper functions generated for `static` and `static - /// inline` functions. + /// Sets the SUFFIX added to the wrapper functions generated for `static` and `static inline` + /// functions and functional macros. #[arg(long, requires = "experimental", value_name = "SUFFIX")] - wrap_static_fns_suffix: Option, + wrapper_function_suffix: Option, /// Create a wrapper function for the macro. The MACRO value must be of the shape /// `[] [()]`. #[arg(long, requires = "experimental", value_name = "MACRO")] @@ -560,7 +560,7 @@ where with_derive_custom_union, wrap_static_fns, wrapper_code_generation_path, - wrap_static_fns_suffix, + wrapper_function_suffix, macro_function, default_visibility, emit_diagnostics, @@ -1099,8 +1099,8 @@ where builder = builder.wrapper_code_generation_path(path); } - if let Some(suffix) = wrap_static_fns_suffix { - builder = builder.wrap_static_fns_suffix(suffix); + if let Some(suffix) = wrapper_function_suffix { + builder = builder.wrapper_function_suffix(suffix); } if let Some(macro_functions) = macro_function { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 83de522b83..23255cfa79 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4262,11 +4262,8 @@ impl CodeGenerator for Function { let should_wrap = is_internal && ctx.options().wrap_static_fns && !has_link_name_attr; - if should_wrap { - let name = canonical_name.clone() + ctx.wrap_static_fns_suffix(); - attributes.push(attributes::link_name::(&name)); - } else if is_function_macro && !has_link_name_attr { - let name = canonical_name.clone() + "__macro"; + if should_wrap || (is_function_macro && !has_link_name_attr) { + let name = canonical_name.clone() + ctx.wrapper_function_suffix(); attributes.push(attributes::link_name::(&name)); } diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 474fe0ebcd..51c9f5f662 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -125,7 +125,7 @@ impl<'a> CSerialize<'a> for Function { if self.kind() == FunctionKind::Macro { "__macro" } else { - ctx.wrap_static_fns_suffix() + ctx.wrapper_function_suffix() } ); diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c5e2832cc9..661c71f8a7 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2842,13 +2842,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } - /// Get the suffix to be added to `static` functions if the `--wrap-static-fns` option is - /// enabled. - pub(crate) fn wrap_static_fns_suffix(&self) -> &str { + /// Get the suffix to be added to generated wrapper functions like + /// `static` functions if the `--wrap-static-fns` option is enabled + /// or functional macros. + pub(crate) fn wrapper_function_suffix(&self) -> &str { self.options() - .wrap_static_fns_suffix + .wrapper_function_suffix .as_deref() - .unwrap_or(crate::DEFAULT_NON_EXTERN_FNS_SUFFIX) + .unwrap_or(crate::DEFAULT_WRAPPER_FUNCTION_SUFFIX) } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 4ffd8ce37c..ff5b502668 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -85,8 +85,8 @@ type HashSet = rustc_hash::FxHashSet; /// Default prefix for the anon fields. pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; - -const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; +/// Default suffix for wrapper functions. +const DEFAULT_WRAPPER_FUNCTION_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { name_file.ends_with(".hpp") || diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index c51111ca3b..6c0916cc92 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1979,22 +1979,22 @@ options! { }, as_args: "--wrap-static-fns", }, - /// The suffix to be added to the function wrappers for `static` functions. - wrap_static_fns_suffix: Option { + /// The suffix to be added to the function wrappers for `static` functions and functional macros. + wrapper_function_suffix: Option { methods: { #[cfg(feature = "experimental")] - /// Set the suffix added to the wrappers for `static` functions. + /// Set the suffix added to the wrappers for `static` functions and functional macros. /// /// This option only comes into effect if `true` is passed to the - /// [`Builder::wrap_static_fns`] method. + /// [`Builder::wrap_static_fns`] method if a functional macro is defined. /// /// The default suffix is `__extern`. - pub fn wrap_static_fns_suffix>(mut self, suffix: T) -> Self { - self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); + pub fn wrapper_function_suffix>(mut self, suffix: T) -> Self { + self.options.wrapper_function_suffix = Some(suffix.as_ref().to_owned()); self } }, - as_args: "--wrap-static-fns-suffix", + as_args: "--wrapper-function-suffix", }, /// The path of the file where generated native code will be emitted. wrapper_code_generation_path: Option {