You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -293,7 +293,15 @@ All function attributes are just local overrides for the same options found in t
293
293
* prefix
294
294
* postfix
295
295
296
+
## Generating Swift Bindings
296
297
298
+
In addition to parsing function names in C/C++ header files, the Swift compiler can make use of the `swift_name` attribute on functions to generate more idiomatic names for imported functions and methods.
299
+
300
+
This attribute is commonly used in Objective-C/C/C++ via the `NS_SWIFT_NAME` and `CF_SWIFT_NAME` macros.
301
+
302
+
Given configuration in the cbindgen.toml, `cbindgen` can generate these attributes for you by guessing an appropriate method signature based on the existing function name (and type, if it is a method in an `impl` block).
303
+
304
+
This is controlled by the `swift_name_macro` option in the cbindgen.toml.
297
305
298
306
299
307
## cbindgen.toml
@@ -545,6 +553,13 @@ args = "horizontal"
545
553
# default: nothing is emitted for must_use functions
546
554
must_use = "MUST_USE_FUNC"
547
555
556
+
# An optional string that, if present, will be used to generate Swift function
557
+
# and method signatures for generated functions, for example "CF_SWIFT_NAME".
558
+
# If no such macro is available in your toolchain, you can define one using the
559
+
# `header` option in cbindgen.toml
560
+
# default: no swift_name function attributes are generated
561
+
swift_name_macro = "CF_SWIFT_NAME"
562
+
548
563
# A rule to use to rename function argument names. The renaming assumes the input
549
564
# is the Rust standard snake_case, however it accepts all the different rename_args
550
565
# inputs. This means many options here are no-ops or redundant.
0 commit comments