rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Support Clang parameter nullability attributes: _Nonnull & _Nullable for C headers

Open 3xau1o opened this issue 4 months ago • 0 comments

Swift imports C apis while taking into account clang nullability attributes: _Nullable & _Nonnull which results in Optional<UnsafePointer<T> and UnsafePointer<T> for the respective Swift generated C bindings, these should map to the Rust option equivalent

There was a previous attempt to use implement this feature https://github.com/rust-lang/rust-bindgen/issues/1876, however the title is wrong, as these are clang level annotations and not objective-c exclusive annotations, in other words, hey can work on any plain C header, and are independent from objective-c rust support

Sources:

  • https://github.com/swiftlang/swift/blob/main/docs/HowSwiftImportsCAPIs.md#nullable-and-non-nullable-pointers
  • https://clang.llvm.org/docs/AttributeReference.html#nullability-attributes

3xau1o avatar Aug 05 '25 23:08 3xau1o