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

Add package name to RustBufferI if it needs it #44

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions bindgen/src/gen_go/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,14 @@ pub mod filters {
}

/// FFI type name to be used to reference cgo types
pub fn ffi_type_name<T: Clone + Into<FfiType>>(type_: &T) -> Result<String, askama::Error> {
pub fn ffi_type_name(type_: &Type) -> Result<String, askama::Error> {
let ffi_type: FfiType = type_.clone().into();
let result = match ffi_type {
FfiType::RustArcPtr(_) => "unsafe.Pointer".into(),
FfiType::RustBuffer(_) => "RustBufferI".into(),
FfiType::RustBuffer(_) => match type_ {
Type::External { namespace, .. } => format!("{}.RustBufferI", namespace),
_ => "RustBufferI".into(),
},
_ => format!("C.{}", oracle().ffi_type_label(&ffi_type)),
};
Ok(result)
Expand Down
21 changes: 21 additions & 0 deletions binding_tests/issue43_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package binding_tests

import (
"testing"

"github.com/NordSecurity/uniffi-bindgen-go/binding_tests/generated/issue43"
"github.com/stretchr/testify/assert"
)

// Ensure you can call async functions which return types in a different package.
// See https://github.com/NordSecurity/uniffi-bindgen-go/issues/43

func TestIssue43(t *testing.T) {
record := issue43.GetAsyncExternalType()
assert.Equal(t, record.Id, "foo")
assert.Equal(t, record.Tag, "bar")
}
1 change: 1 addition & 0 deletions fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ uniffi-go-fixture-destroy = { path = "destroy" }
uniffi-go-fixture-errors = { path = "errors" }
uniffi-go-fixture-name-case = { path = "name-case" }
uniffi-go-fixture-objects = { path = "objects" }
uniffi-go-fixture-issue43 = { path = "regressions/issue43" }
uniffi-go-fixture-issue45 = { path = "regressions/issue45" }
17 changes: 17 additions & 0 deletions fixtures/regressions/issue43/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "uniffi-go-fixture-issue43"
version = "1.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["lib", "cdylib"]
name = "uniffi_go_issue43"

[dependencies]
uniffi = {path = "../../../3rd-party/uniffi-rs/uniffi"}
uniffi_macros = {path = "../../../3rd-party/uniffi-rs/uniffi_macros"}
uniffi-go-fixture-issue45 = {path = "../issue45"}

[build-dependencies]
uniffi_build = {path = "../../../3rd-party/uniffi-rs/uniffi_build", features=["builtin-bindgen"]}
7 changes: 7 additions & 0 deletions fixtures/regressions/issue43/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

fn main() {
uniffi_build::generate_scaffolding("./src/issue43.udl").unwrap();
}
1 change: 1 addition & 0 deletions fixtures/regressions/issue43/src/issue43.udl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace issue43 {};
13 changes: 13 additions & 0 deletions fixtures/regressions/issue43/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[uniffi::export]
async fn get_async_external_type() -> uniffi_go_issue45::Record {
uniffi_go_issue45::Record {
id: "foo".to_string(),
tag: "bar".to_string(),
}
}

include!(concat!(env!("OUT_DIR"), "/issue43.uniffi.rs"));
6 changes: 3 additions & 3 deletions fixtures/regressions/issue45/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[derive(uniffi::Record)]
struct Record {
id: String,
tag: String,
pub struct Record {
pub id: String,
pub tag: String,
}

// Ensure multiple futures packages work fine together, the other one being
Expand Down
1 change: 1 addition & 0 deletions fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod uniffi_fixtures {
// Go specific
uniffi_go_destroy::uniffi_reexport_scaffolding!();
uniffi_go_errors::uniffi_reexport_scaffolding!();
uniffi_go_issue43::uniffi_reexport_scaffolding!();
uniffi_go_issue45::uniffi_reexport_scaffolding!();
uniffi_go_name_case::uniffi_reexport_scaffolding!();
uniffi_go_objects::uniffi_reexport_scaffolding!();
Expand Down
Loading