-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multiple async packages not working together
Future continuation callback is a single global callback on Rust side. Its used to signal bindings from Rust when a future is ready. The problem is if multiple async packages set this callback, only one of these callbacks will be used by Rust code for futures from both packages. The current implementation of this callback simply sends the continuation future result into a channel, but the channel type was using `C.int8_t`, which turns out to be a different type for each package, and channel raises an error when wrong type is being sent in the channel. Luckily this callback is very simple, and it doesn't matter which package's callback is trigerred. So the fix is to use a channel type that is the same for both packages, regular `int8` instead of `C.int8_t`.
- Loading branch information
Showing
9 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( | ||
"github.com/NordSecurity/uniffi-bindgen-go/binding_tests/generated/issue45" | ||
"testing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Ensure multiple futures packages work fine together, the other one being | ||
// the "futures" fixture from uniffi-rs. | ||
// https://github.com/NordSecurity/uniffi-bindgen-go/issues/45 | ||
|
||
func TestIssue45(t *testing.T) { | ||
record := issue45.GetAsyncRecord() | ||
assert.Equal(t, record.Id, "foo") | ||
assert.Equal(t, record.Tag, "bar") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "uniffi-go-fixture-issue45" | ||
version = "1.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["lib", "cdylib"] | ||
name = "uniffi_go_issue45" | ||
|
||
[dependencies] | ||
uniffi = {path = "../../../3rd-party/uniffi-rs/uniffi"} | ||
uniffi_macros = {path = "../../../3rd-party/uniffi-rs/uniffi_macros"} | ||
|
||
[build-dependencies] | ||
uniffi_build = {path = "../../../3rd-party/uniffi-rs/uniffi_build", features=["builtin-bindgen"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/issue45.udl").unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
namespace issue45 {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* 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/. */ | ||
|
||
#[derive(uniffi::Record)] | ||
struct Record { | ||
id: String, | ||
tag: String, | ||
} | ||
|
||
// Ensure multiple futures packages work fine together, the other one being | ||
// the "futures" fixture from uniffi-rs. | ||
// https://github.com/NordSecurity/uniffi-bindgen-go/issues/45 | ||
#[uniffi::export] | ||
async fn get_async_record() -> Record { | ||
Record { | ||
id: "foo".to_string(), | ||
tag: "bar".to_string(), | ||
} | ||
} | ||
|
||
include!(concat!(env!("OUT_DIR"), "/issue45.uniffi.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters