Skip to content

Commit 316f7c9

Browse files
committedOct 6, 2023
Rename wrap_static_fns_suffix and use it for functional macros
1 parent 1485cd0 commit 316f7c9

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed
 

‎CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@
194194
`CargoCallbacks` constant was added to mitigate the breaking nature of this
195195
change. This constant has been marked as deprecated and users will have to
196196
use the new `CargoCallbacks::new` method in the future.
197-
- Renamed `--wrap-static-fns-path` argument to `-wrapper-code-generation-path` and the
197+
- Renamed `--wrap-static-fns-path` argument to `--wrapper-code-generation-path` and the
198198
corresponding `wrap_static_fns_path` builder function to `wrapper_code_generation_path`.
199+
- Renamed `--wrap-static-fns-suffix` argument to `--wrapper-function-suffix` and the
200+
corresponding `wrap_static_fns_suffix` builder function to `wrapper_function_suffix`.
199201
## Removed
200202
## Fixed
201203
- Allow compiling `bindgen-cli` with a static libclang.

‎bindgen-cli/options.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,10 @@ struct BindgenCommand {
416416
/// Sets the path of the file where generated code for wrapper functions will be emitted.
417417
#[arg(long, requires = "experimental", value_name = "PATH")]
418418
wrapper_code_generation_path: Option<PathBuf>,
419-
/// Sets the SUFFIX added to the extern wrapper functions generated for `static` and `static
420-
/// inline` functions.
419+
/// Sets the SUFFIX added to the wrapper functions generated for `static` and `static inline`
420+
/// functions and functional macros.
421421
#[arg(long, requires = "experimental", value_name = "SUFFIX")]
422-
wrap_static_fns_suffix: Option<String>,
422+
wrapper_function_suffix: Option<String>,
423423
/// Create a wrapper function for the macro. The MACRO value must be of the shape
424424
/// `[<return type>] <macro name>[(<comma separated list of arguments>)]`.
425425
#[arg(long, requires = "experimental", value_name = "MACRO")]
@@ -560,7 +560,7 @@ where
560560
with_derive_custom_union,
561561
wrap_static_fns,
562562
wrapper_code_generation_path,
563-
wrap_static_fns_suffix,
563+
wrapper_function_suffix,
564564
macro_function,
565565
default_visibility,
566566
emit_diagnostics,
@@ -1099,8 +1099,8 @@ where
10991099
builder = builder.wrapper_code_generation_path(path);
11001100
}
11011101

1102-
if let Some(suffix) = wrap_static_fns_suffix {
1103-
builder = builder.wrap_static_fns_suffix(suffix);
1102+
if let Some(suffix) = wrapper_function_suffix {
1103+
builder = builder.wrapper_function_suffix(suffix);
11041104
}
11051105

11061106
if let Some(macro_functions) = macro_function {

‎bindgen/codegen/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4262,11 +4262,8 @@ impl CodeGenerator for Function {
42624262
let should_wrap =
42634263
is_internal && ctx.options().wrap_static_fns && !has_link_name_attr;
42644264

4265-
if should_wrap {
4266-
let name = canonical_name.clone() + ctx.wrap_static_fns_suffix();
4267-
attributes.push(attributes::link_name::<true>(&name));
4268-
} else if is_function_macro && !has_link_name_attr {
4269-
let name = canonical_name.clone() + "__macro";
4265+
if should_wrap || (is_function_macro && !has_link_name_attr) {
4266+
let name = canonical_name.clone() + ctx.wrapper_function_suffix();
42704267
attributes.push(attributes::link_name::<true>(&name));
42714268
}
42724269

‎bindgen/codegen/serialize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a> CSerialize<'a> for Function {
125125
if self.kind() == FunctionKind::Macro {
126126
"__macro"
127127
} else {
128-
ctx.wrap_static_fns_suffix()
128+
ctx.wrapper_function_suffix()
129129
}
130130
);
131131

‎bindgen/ir/context.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2842,13 +2842,14 @@ If you encounter an error missing from this list, please file an issue or a PR!"
28422842
}
28432843
}
28442844

2845-
/// Get the suffix to be added to `static` functions if the `--wrap-static-fns` option is
2846-
/// enabled.
2847-
pub(crate) fn wrap_static_fns_suffix(&self) -> &str {
2845+
/// Get the suffix to be added to generated wrapper functions like
2846+
/// `static` functions if the `--wrap-static-fns` option is enabled
2847+
/// or functional macros.
2848+
pub(crate) fn wrapper_function_suffix(&self) -> &str {
28482849
self.options()
2849-
.wrap_static_fns_suffix
2850+
.wrapper_function_suffix
28502851
.as_deref()
2851-
.unwrap_or(crate::DEFAULT_NON_EXTERN_FNS_SUFFIX)
2852+
.unwrap_or(crate::DEFAULT_WRAPPER_FUNCTION_SUFFIX)
28522853
}
28532854
}
28542855

‎bindgen/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ type HashSet<K> = rustc_hash::FxHashSet<K>;
8585

8686
/// Default prefix for the anon fields.
8787
pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_";
88-
89-
const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern";
88+
/// Default suffix for wrapper functions.
89+
const DEFAULT_WRAPPER_FUNCTION_SUFFIX: &str = "__extern";
9090

9191
fn file_is_cpp(name_file: &str) -> bool {
9292
name_file.ends_with(".hpp") ||

‎bindgen/options/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1979,22 +1979,22 @@ options! {
19791979
},
19801980
as_args: "--wrap-static-fns",
19811981
},
1982-
/// The suffix to be added to the function wrappers for `static` functions.
1983-
wrap_static_fns_suffix: Option<String> {
1982+
/// The suffix to be added to the function wrappers for `static` functions and functional macros.
1983+
wrapper_function_suffix: Option<String> {
19841984
methods: {
19851985
#[cfg(feature = "experimental")]
1986-
/// Set the suffix added to the wrappers for `static` functions.
1986+
/// Set the suffix added to the wrappers for `static` functions and functional macros.
19871987
///
19881988
/// This option only comes into effect if `true` is passed to the
1989-
/// [`Builder::wrap_static_fns`] method.
1989+
/// [`Builder::wrap_static_fns`] method if a functional macro is defined.
19901990
///
19911991
/// The default suffix is `__extern`.
1992-
pub fn wrap_static_fns_suffix<T: AsRef<str>>(mut self, suffix: T) -> Self {
1993-
self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned());
1992+
pub fn wrapper_function_suffix<T: AsRef<str>>(mut self, suffix: T) -> Self {
1993+
self.options.wrapper_function_suffix = Some(suffix.as_ref().to_owned());
19941994
self
19951995
}
19961996
},
1997-
as_args: "--wrap-static-fns-suffix",
1997+
as_args: "--wrapper-function-suffix",
19981998
},
19991999
/// The path of the file where generated native code will be emitted.
20002000
wrapper_code_generation_path: Option<PathBuf> {

0 commit comments

Comments
 (0)