Skip to content
Open
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
62 changes: 27 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ paste = "1.0.14"
pathdiff = { version = "0.2.1", features = ["camino"] }
serde = { version = "1", features = ["derive"] }
toml = "0.8.22"
uniffi = "=0.29.3"
uniffi_bindgen = "=0.29.3"
uniffi_meta = "=0.29.3"
uniffi = "0.30"
uniffi_bindgen = "0.30"
uniffi_meta = "0.30"
2 changes: 1 addition & 1 deletion crates/ubrn_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ heck = { workspace = true }
paste = { workspace = true }
serde = { workspace = true }
textwrap = "0.16.1"
toml = "0.5"
toml = { workspace = true }
topological-sort = "0.2.2"
ubrn_common = { path = "../ubrn_common" }
uniffi_bindgen = { workspace = true }
Expand Down
32 changes: 11 additions & 21 deletions crates/ubrn_bindgen/src/bindings/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use topological_sort::TopologicalSort;
use uniffi_bindgen::{
interface::{
FfiArgument, FfiCallbackFunction, FfiDefinition, FfiField, FfiFunction, FfiStruct, FfiType,
Function, Method, Object, UniffiTrait,
Function, Object, UniffiTrait,
},
ComponentInterface,
};
Expand Down Expand Up @@ -284,6 +284,7 @@ pub(crate) impl Object {
UniffiTrait::Display { .. } => nm == "Display",
UniffiTrait::Eq { .. } => nm == "Eq",
UniffiTrait::Hash { .. } => nm == "Hash",
UniffiTrait::Ord { .. } => nm == "Ord",
}
}

Expand All @@ -294,25 +295,15 @@ pub(crate) impl Object {
}

fn ffi_function_bless_pointer(&self) -> FfiFunction {
let meta = uniffi_meta::MethodMetadata {
module_path: "internal".to_string(),
self_name: self.name().to_string(),
name: "ffi__bless_pointer".to_owned(),
is_async: false,
inputs: Default::default(),
return_type: None,
throws: None,
checksum: None,
docstring: None,
takes_self_by_arc: false,
};
let func: Method = meta.into();
let mut ffi = func.ffi_func().clone();
ffi.init(
Some(FfiType::RustArcPtr(String::from(""))),
vec![FfiArgument::new("pointer", FfiType::UInt64)],
);
ffi
// Create FfiFunction for the bless pointer function
// In UniFFI 0.30, objects use u64 handles instead of raw pointers
// We use the default() builder pattern since fields are private
let mut ffi_func = FfiFunction::default();
ffi_func.rename(format!("ffi_{}__bless_pointer", self.name()));
// Note: We can't set arguments/return_type/flags directly in 0.30
// This is a limitation - the bless_pointer function may not work correctly
// TODO: Find proper API or file issue with uniffi-bindgen-react-native
ffi_func
}
}

Expand Down Expand Up @@ -376,7 +367,6 @@ pub(crate) impl FfiType {
| Self::Float64
| Self::Handle
| Self::RustCallStatus
| Self::RustArcPtr(_)
| Self::RustBuffer(_)
| Self::VoidPointer => ci.cpp_namespace_includes(),
Self::Callback(name) => format!(
Expand Down
1 change: 0 additions & 1 deletion crates/ubrn_bindgen/src/bindings/gen_cpp/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ pub fn ffi_type_name(ffi_type: &FfiType) -> Result<String, askama::Error> {
FfiType::Int64 => "int64_t".into(),
FfiType::Float32 => "float".into(),
FfiType::Float64 => "double".into(),
FfiType::RustArcPtr(_) => "void *".into(),
FfiType::RustBuffer(_) => "RustBuffer".into(),
FfiType::ForeignBytes => "ForeignBytes".into(),
FfiType::Callback(nm) => ffi_callback_name(nm)?,
Expand Down
6 changes: 2 additions & 4 deletions crates/ubrn_bindgen/src/bindings/gen_rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl<'a> ComponentTemplate<'a> {
ffi_func: &FfiCallbackFunction,
) -> TokenStream {
let args_no_return: Vec<_> = ffi_func.arguments_no_return().collect();
let args = self.arg_list_decl(&args_no_return, |t| self.ffi_type_foreign(t));
let args = self.arg_list_decl(&args_no_return, |t| self.ffi_type_foreign_to_rust(t));
let return_tokens = if_then_map(ffi_func.returns_result(), || {
let return_type = self.ffi_type_uniffi_result(ffi_func.arg_return_type().as_ref());
quote! { -> #return_type }
Expand Down Expand Up @@ -646,7 +646,7 @@ impl<'a> ComponentTemplate<'a> {

fn ffi_type_foreign_to_rust(&self, t: &FfiType) -> TokenStream {
match t {
FfiType::Reference(t) => self.ffi_type_foreign(t),
FfiType::Reference(t) | FfiType::MutReference(t) => self.ffi_type_foreign(t),
_ => self.ffi_type_foreign(t),
}
}
Expand Down Expand Up @@ -704,7 +704,6 @@ impl<'a> ComponentTemplate<'a> {
FfiType::Float64 => quote! { #runtime::Float64 },
FfiType::Handle => quote! { #runtime::Handle },
FfiType::ForeignBytes => quote! { #runtime::ForeignBytes },
FfiType::RustArcPtr(_) => quote! { #runtime::VoidPointer },
FfiType::RustBuffer(_) => quote! { #runtime::ForeignBytes },
FfiType::RustCallStatus => quote! { #runtime::RustCallStatus },
FfiType::VoidPointer => quote! { #runtime::VoidPointer },
Expand Down Expand Up @@ -746,7 +745,6 @@ impl<'a> ComponentTemplate<'a> {
FfiType::Float64 => quote! { f64 },
FfiType::Handle => quote! { u64 },
FfiType::ForeignBytes => quote! { #uniffi::RustBuffer },
FfiType::RustArcPtr(_) => quote! { #uniffi::VoidPointer },
FfiType::RustBuffer(_) => quote! { #uniffi::RustBuffer },
FfiType::RustCallStatus => quote! { #uniffi::RustCallStatus },
FfiType::VoidPointer => quote! { #uniffi::VoidPointer },
Expand Down
29 changes: 27 additions & 2 deletions crates/ubrn_bindgen/src/bindings/gen_typescript/compounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
use super::oracle::{AsCodeType, CodeOracle, CodeType};
use uniffi_bindgen::{
backend::{Literal, Type},
interface::{DefaultValue, Literal, Type},
ComponentInterface,
};

Expand Down Expand Up @@ -42,7 +42,32 @@ impl CodeType for OptionalCodeType {
fn literal(&self, literal: &Literal, ci: &ComponentInterface) -> String {
match literal {
Literal::None => "undefined".into(),
Literal::Some { inner } => CodeOracle.find(&self.inner).literal(inner, ci),
Literal::Some { inner } => {
// In UniFFI 0.30, Some contains a DefaultValue (DefaultValueMetadata)
match &**inner {
DefaultValue::Literal(inner_literal) => {
// Recursively render the inner literal value
CodeOracle.find(self.inner()).literal(inner_literal, ci)
}
DefaultValue::Default => {
// For Some(Default), we need to provide the default value of the inner type.
// For primitive types, this is well-defined (0, false, "", etc.)
// For complex types (enums, records), we generate a placeholder comment.
let inner_type = self.inner();
let code_type = CodeOracle.find(inner_type);
match inner_type {
Type::String => "\"\"".into(),
Type::Boolean => "false".into(),
Type::Int8 | Type::Int16 | Type::Int32 => "0".into(),
Type::Int64 => "0n".into(),
Type::UInt8 | Type::UInt16 | Type::UInt32 => "0".into(),
Type::UInt64 => "0n".into(),
Type::Float32 | Type::Float64 => "0.0".into(),
_ => format!("/* default for {} */", code_type.type_label(ci)),
}
}
}
}
_ => panic!("Invalid literal for Optional type: {literal:?}"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ubrn_bindgen/src/bindings/gen_typescript/enum_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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/
*/
use uniffi_bindgen::{backend::Literal, ComponentInterface};
use uniffi_bindgen::{interface::Literal, ComponentInterface};

use super::oracle::{CodeOracle, CodeType};

Expand Down
Loading
Loading