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
74 changes: 39 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.0"
uniffi_bindgen = "=0.30.0"
uniffi_meta = "=0.30.0"
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
5 changes: 4 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 All @@ -86,3 +85,7 @@ pub fn ffi_callback_name(nm: &str) -> Result<String, askama::Error> {
pub fn ffi_struct_name(nm: &str) -> Result<String, askama::Error> {
Ok(format!("Uniffi{}", nm.to_upper_camel_case()))
}

pub fn sanitize_for_macro(s: &str) -> Result<String, askama::Error> {
Ok(s.replace("::", "_"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{%- let cb_name = callback.name()|ffi_callback_name %}
{%- let guard_name = cb_name|fmt("BRIDGING_{}") %}
#ifndef {{ guard_name }}_DEFINED
#define {{ guard_name }}_DEFINED
namespace {{ ci.cpp_namespace() }} {
using CallInvoker = uniffi_runtime::UniffiCallInvoker;

// Wrapper struct already declared in CallbackWrapperDecl.cpp

template <> struct Bridging<{{ cb_name }}Wrapper> {
static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, {{ cb_name }}Wrapper rsCallbackWrapper) {
{{ cb_name }} rsCallback = rsCallbackWrapper.callback;
{%- let cb_id = callback.name()|fmt("--{}") %}
return jsi::Function::createFromHostFunction(
rt,
jsi::PropNameID::forAscii(rt, "{{ cb_id }}"),
{{ callback.arguments().len() }},
[rsCallback, callInvoker](
jsi::Runtime &rt,
const jsi::Value &thisValue,
const jsi::Value *arguments,
size_t count) -> jsi::Value
{
return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
}
);
}

static jsi::Value intoRust(
jsi::Runtime &rt,
std::shared_ptr<CallInvoker> callInvoker,
const jsi::Value &thisValue,
const jsi::Value *args,
size_t count,
{{ cb_name}} func) {
// Convert the arguments into the Rust, with Bridging<T>::fromJs,
// then call the rs_callback with those arguments.
{%- call cpp::cpp_fn_rust_caller_body_with_func_name(callback, "func") %}
}
};

} // namespace {{ ci.cpp_namespace() }}
#endif // {{ guard_name }}_DEFINED

Loading