Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly export scaffolding symbols #23

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#### v0.4.1+v0.25.0

----

- Scaffolding: Decorate public functions with `__declspec(dllexport)` under Windows

#### v0.4.0+v0.25.0

----
Expand Down
35 changes: 23 additions & 12 deletions bindgen/src/bindings/cpp/templates/cpp_scaffolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
{% else %}
{% endmatch %}

#if defined(_WIN32) || defined(_WIN64)
#define UNIFFI_EXPORT __declspec(dllexport)
#else
#define UNIFFI_EXPORT
#endif

#include <stdio.h>
#include <stdint.h>
#include <bit>
Expand Down Expand Up @@ -148,7 +154,7 @@ HandleMap<{{ typ|canonical_name }}> {{ name }}_map;
extern "C" {
#endif

RustBuffer {{ ci.ffi_rustbuffer_alloc().name() }}(int32_t size, RustCallStatus *out_status) {
UNIFFI_EXPORT RustBuffer {{ ci.ffi_rustbuffer_alloc().name() }}(int32_t size, RustCallStatus *out_status) {
out_status->code = 0;

RustBuffer buf = {
Expand All @@ -160,7 +166,7 @@ RustBuffer {{ ci.ffi_rustbuffer_alloc().name() }}(int32_t size, RustCallStatus *
return std::move(buf);
}

RustBuffer {{ ci.ffi_rustbuffer_from_bytes().name() }}(ForeignBytes bytes, RustCallStatus *out_status) {
UNIFFI_EXPORT RustBuffer {{ ci.ffi_rustbuffer_from_bytes().name() }}(ForeignBytes bytes, RustCallStatus *out_status) {
out_status->code = 0;

RustBuffer buf = {
Expand All @@ -174,13 +180,13 @@ RustBuffer {{ ci.ffi_rustbuffer_from_bytes().name() }}(ForeignBytes bytes, RustC
return std::move(buf);
}

void {{ ci.ffi_rustbuffer_free().name() }}(RustBuffer buf, RustCallStatus *out_status) {
UNIFFI_EXPORT void {{ ci.ffi_rustbuffer_free().name() }}(RustBuffer buf, RustCallStatus *out_status) {
out_status->code = 0;

delete[] buf.data;
}

RustBuffer {{ ci.ffi_rustbuffer_reserve().name() }}(RustBuffer buffer, int32_t additional, RustCallStatus *out_status) {
UNIFFI_EXPORT RustBuffer {{ ci.ffi_rustbuffer_reserve().name() }}(RustBuffer buffer, int32_t additional, RustCallStatus *out_status) {
out_status->code = 0;

RustBuffer buf = {
Expand All @@ -194,7 +200,8 @@ RustBuffer {{ ci.ffi_rustbuffer_reserve().name() }}(RustBuffer buffer, int32_t a

{% for func in ci.function_definitions() %}
{% let ffi_func = func.ffi_func() %}
{%- match ffi_func.return_type() -%}
UNIFFI_EXPORT
{% match ffi_func.return_type() -%}
{% when Some with (return_type) %}{{ return_type|ffi_type_name }} {% when None %}void {% endmatch %}{{ ffi_func.name() }}(
{%- for arg in ffi_func.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() }}{% if !loop.last || ffi_func.has_rust_call_status_arg() %}, {% endif -%}
Expand Down Expand Up @@ -223,7 +230,7 @@ RustBuffer {{ ci.ffi_rustbuffer_reserve().name() }}(RustBuffer buffer, int32_t a

{% for func in ci.callback_interface_definitions() %}
{% let ffi_func = func.ffi_init_callback() %}
void {{ ffi_func.name() }}(ForeignCallback callback_stub, RustCallStatus *out_status) {
UNIFFI_EXPORT void {{ ffi_func.name() }}(ForeignCallback callback_stub, RustCallStatus *out_status) {
out_status->code = 0;

{{ func|ffi_converter_name }}::fn_handle.store(reinterpret_cast<uint64_t>(callback_stub));
Expand All @@ -234,7 +241,8 @@ void {{ ffi_func.name() }}(ForeignCallback callback_stub, RustCallStatus *out_st

{% for ctor in obj.constructors() %}
{% let ffi_ctor = ctor.ffi_func() %}
{%- match ffi_ctor.return_type() -%}
UNIFFI_EXPORT
{% match ffi_ctor.return_type() -%}
{% when Some with (return_type) %}{{ return_type|ffi_type_name }} {% when None %}void {% endmatch %}{{ ffi_ctor.name() }}(
{%- for arg in ffi_ctor.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() }}{% if !loop.last || ffi_ctor.has_rust_call_status_arg() %}, {% endif -%}
Expand All @@ -255,7 +263,8 @@ void {{ ffi_func.name() }}(ForeignCallback callback_stub, RustCallStatus *out_st
{% endfor %}

{% let ffi_dtor = obj.ffi_object_free() %}
{%- match ffi_dtor.return_type() -%}
UNIFFI_EXPORT
{% match ffi_dtor.return_type() -%}
{% when Some with (return_type) %}{{ return_type|ffi_type_name }} {% when None %}void {% endmatch %}{{ ffi_dtor.name() }}(
{%- for arg in ffi_dtor.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() }}{% if !loop.last || ffi_dtor.has_rust_call_status_arg() %}, {% endif -%}
Expand All @@ -271,7 +280,8 @@ void {{ ffi_func.name() }}(ForeignCallback callback_stub, RustCallStatus *out_st

{% for func in obj.methods() %}
{% let ffi_func = func.ffi_func() %}
{%- match ffi_func.return_type() -%}
UNIFFI_EXPORT
{% match ffi_func.return_type() -%}
{% when Some with (return_type) %}{{ return_type|ffi_type_name }} {% when None %}void {% endmatch %}{{ ffi_func.name() }}(
{%- for arg in ffi_func.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() }}{% if !loop.last || ffi_func.has_rust_call_status_arg() %}, {% endif -%}
Expand Down Expand Up @@ -302,7 +312,8 @@ void {{ ffi_func.name() }}(ForeignCallback callback_stub, RustCallStatus *out_st
{% endfor %}

{% for func in ci.iter_futures_ffi_function_definitons() %}
{%- match func.return_type() -%}
UNIFFI_EXPORT
{% match func.return_type() -%}
{% when Some with (return_type) %}{{ return_type|ffi_type_name }} {% when None %}void {% endmatch %}{{ func.name() }}(
{%- for arg in func.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() }}{% if !loop.last || func.has_rust_call_status_arg() %}, {% endif -%}
Expand All @@ -321,11 +332,11 @@ void {{ ffi_func.name() }}(ForeignCallback callback_stub, RustCallStatus *out_st
{% endfor %}

{% for checksum in ci.iter_checksums() %}
uint16_t {{ checksum.0 }}() { return {{ checksum.1 }}; }
UNIFFI_EXPORT uint16_t {{ checksum.0 }}() { return {{ checksum.1 }}; }
{% endfor %}

{% let contract_fn = ci.ffi_uniffi_contract_version() %}
uint32_t {{ contract_fn.name() }}() { return {{ ci.uniffi_contract_version() }}; }
UNIFFI_EXPORT uint32_t {{ contract_fn.name() }}() { return {{ ci.uniffi_contract_version() }}; }

#ifdef __cplusplus
}
Expand Down
Loading