Skip to content

Commit b0fb3a3

Browse files
committed
(chore): patch the uniffi library instead of downgrading
1 parent e630cf0 commit b0fb3a3

5 files changed

Lines changed: 76 additions & 10 deletions

File tree

.gitlab/images/rust/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ RUN apt-get update && apt-get install -y \
1111

1212
# Rust deps
1313
RUN rustup set profile default && rustup component add clippy rustfmt
14-
RUN cargo install just cargo-ndk \
15-
&& cargo install wasm-bindgen-cli --version 0.2.113 \
16-
&& rm -rf /usr/local/cargo/registry
14+
RUN cargo install just wasm-bindgen-cli cargo-ndk && rm -rf /usr/local/cargo/registry
1715

1816
# Android NDK
1917
RUN curl -L -o /tmp/ndk.zip "https://dl.google.com/android/repository/android-ndk-r27c-linux.zip" \
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Merged into the auto-generated rust_modules/wasm/Cargo.toml by ubrn.
22
# Disables rs-core's default `native-transport` feature so the wasm crate
33
# only pulls in the wasm32-compatible `tonic-web-wasm-client` transport.
4-
# Pin wasm-bindgen
54
[dependencies]
6-
polycentric-core = { default-features = false }
7-
wasm-bindgen = "=0.2.113"
5+
polycentric-core = { default-features = false }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
diff --git a/crates/ubrn_bindgen/src/bindings/gen_rust/mod.rs b/crates/ubrn_bindgen/src/bindings/gen_rust/mod.rs
2+
index f21884f978b3457cc67d1ba7122816dbf8b796b2..f0913aea2df850dcacf4ac6ff81c45e3d0404f41 100644
3+
--- a/crates/ubrn_bindgen/src/bindings/gen_rust/mod.rs
4+
+++ b/crates/ubrn_bindgen/src/bindings/gen_rust/mod.rs
5+
@@ -95,8 +95,16 @@ impl FlavorParams<'_> {
6+
}
7+
}
8+
9+
-fn callback_fn_ident() -> Ident {
10+
- ident("JsCallbackFn")
11+
+// wasm-bindgen >=0.2.114 collapses #[wasm_bindgen]-exposed structs that
12+
+// share an identical Rust ident into one JS class breaking foreign-future callbacks.
13+
+// Suffix the ident with the containing module's name so each is a distinct Rust type.
14+
+// See https://github.com/wasm-bindgen/wasm-bindgen/pull/4977
15+
+fn callback_fn_ident(module: &Ident) -> Ident {
16+
+ use heck::ToUpperCamelCase;
17+
+ ident(&format!(
18+
+ "JsCallbackFn{}",
19+
+ module.to_string().to_upper_camel_case()
20+
+ ))
21+
}
22+
23+
fn wasm_flavor() -> FlavorParams<'static> {
24+
@@ -305,7 +313,7 @@ impl<'a> ComponentTemplate<'a> {
25+
26+
let module_ident = cb.module_ident();
27+
let js_class = cb.js_module_ident();
28+
- let callback_fn_ident = callback_fn_ident();
29+
+ let callback_fn_ident = callback_fn_ident(&module_ident);
30+
31+
quote! {
32+
mod #module_ident {
33+
@@ -348,7 +356,8 @@ impl<'a> ComponentTemplate<'a> {
34+
35+
fn ffi_callback(&mut self, cb: &FfiCallbackFunction2) -> TokenStream {
36+
let uniffi_ident = self.uniffi_ident();
37+
- let callback_fn_ident = callback_fn_ident();
38+
+ let cb_module_ident = cb.module_ident();
39+
+ let callback_fn_ident = callback_fn_ident(&cb_module_ident);
40+
41+
let js_method_decl = self.js_callback_method_decl(&callback_fn_ident, cb.callback());
42+
43+
@@ -512,8 +521,9 @@ impl<'a> ComponentTemplate<'a> {
44+
let field_ident = ident(field_name);
45+
let js_field_ident = camel_case_ident(field_name);
46+
if st.is_callback_method(field_name) {
47+
- let callback_fn_ident = callback_fn_ident();
48+
let alias_ident = st.method_alias_ident(field_name);
49+
+ let mod_ident = st.method_mod_ident(field_name);
50+
+ let callback_fn_ident = callback_fn_ident(&mod_ident);
51+
quote! {
52+
#[wasm_bindgen(method, getter, js_name = #js_field_ident)]
53+
fn #field_ident(this: &VTableJs) -> #alias_ident::#callback_fn_ident;
54+
@@ -737,7 +747,7 @@ impl<'a> ComponentTemplate<'a> {
55+
}
56+
FfiType::Callback(cb) => {
57+
let mod_ident = snake_case_ident(cb);
58+
- let callback_fn_ident = callback_fn_ident();
59+
+ let callback_fn_ident = callback_fn_ident(&mod_ident);
60+
quote! { #mod_ident::#callback_fn_ident }
61+
}
62+
FfiType::Reference(_) | FfiType::MutReference(_) => {

pnpm-lock.yaml

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ packages:
55
- tools/*
66

77
catalog:
8-
typescript: ^5.9.3
98
'@noble/hashes': ^1.8.0
9+
typescript: ^5.9.3
1010

1111
linkWorkspacePackages: true
12+
13+
patchedDependencies:
14+
uniffi-bindgen-react-native@0.31.0-2: patches/uniffi-bindgen-react-native@0.31.0-2.patch

0 commit comments

Comments
 (0)