Skip to content

Commit

Permalink
Ensure bridging header function prototypes are valid
Browse files Browse the repository at this point in the history
Compiling my swift project I am seeing:

```
Generated/mycrateFFI.h:75:45: error: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]
```

for the `ffi_mycrate_uniffi_contract_version` and
`uniffi_mycrate_checksum_func_myfun` declarations.

This is because they take no arguments which is emitted as `()`, for C `(void)`
is required, C++ is happy with either.

Add a specific case to `swift::arg_list_ffi_decl` to handle this. The resulting diff is:

```
--- mycrateFFI.h	2023-04-06 10:38:25.645130502 +0100
+++ mycrateFFI.h	2023-04-06 11:01:12.415958817 +0100
@@ -73,9 +73,11 @@ RustBuffer ffi_mycrate_rustbuffer_reserv
 );

 uint32_t ffi_mycrate_uniffi_contract_version(
+    void

 );

 uint16_t uniffi_mycrate_checksum_func_myfun(
+    void

 );
```
  • Loading branch information
ijc committed Apr 6, 2023
1 parent c5aa9aa commit b607131
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions uniffi_bindgen/src/bindings/swift/templates/macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@
// Note unfiltered name but ffi_type_name filters.
-#}
{%- macro arg_list_ffi_decl(func) %}
{%- for arg in func.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() -}}{% if !loop.last || func.has_rust_call_status_arg() %}, {% endif %}
{%- endfor %}
{%- if func.has_rust_call_status_arg() %}RustCallStatus *_Nonnull out_status{% endif %}
{%- if func.arguments().len() > 0 %}
{%- for arg in func.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() -}}{% if !loop.last || func.has_rust_call_status_arg() %}, {% endif %}
{%- endfor %}
{%- if func.has_rust_call_status_arg() %}RustCallStatus *_Nonnull out_status{% endif %}
{%- else %}
{%- if func.has_rust_call_status_arg() %}RustCallStatus *_Nonnull out_status{%- else %}void{% endif %}
{% endif %}
{%- endmacro -%}

{%- macro async(func) %}
Expand Down

0 comments on commit b607131

Please sign in to comment.