Skip to content
Draft
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
8 changes: 4 additions & 4 deletions fixtures/ext-types/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use uniffi_one::{
use uniffi_sublib::SubLibType;
use url::Url;

uniffi::use_udl_record!(uniffi_sublib, SubLibType);
uniffi::use_udl_trait!(uniffi_one, UniffiOneTrait);

pub struct CombinedType {
pub uoe: UniffiOneEnum,
pub uot: UniffiOneType,
Expand Down Expand Up @@ -66,10 +69,7 @@ fn get_combined_type(existing: Option<CombinedType>) -> CombinedType {
#[derive(Default, uniffi::Record)]
pub struct ObjectsType {
pub maybe_trait: Option<Arc<dyn UniffiOneTrait>>,
// XXX - can't refer to UniffiOneInterface here - #1854
//pub maybe_interface: Option<Arc<UniffiOneInterface>>,
// Use this in the meantime so the tests can still refer to it.
pub maybe_interface: Option<u8>,
pub maybe_interface: Option<Arc<UniffiOneInterface>>,
pub sub: SubLibType,
}

Expand Down
3 changes: 3 additions & 0 deletions fixtures/ext-types/proc-macro-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ uniffi::use_udl_record!(ext_types_guid, Guid);
uniffi::use_udl_record!(custom_types, Url);
uniffi::use_udl_record!(custom_types, Handle);

uniffi::use_udl_trait!(uniffi_one, UniffiOneTrait);
uniffi::use_udl_record!(uniffi_one, UniffiOneProcMacroType);

#[derive(uniffi::Record)]
pub struct CombinedType {
pub uoe: UniffiOneEnum,
Expand Down
1 change: 1 addition & 0 deletions fixtures/ext-types/sub-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;
use uniffi_one::{UniffiOneEnum, UniffiOneInterface, UniffiOneTrait};

uniffi::use_udl_object!(uniffi_one, UniffiOneInterface);
uniffi::use_udl_trait!(uniffi_one, UniffiOneTrait);
uniffi::use_udl_enum!(uniffi_one, UniffiOneEnum);

#[derive(Default, uniffi::Record)]
Expand Down
12 changes: 12 additions & 0 deletions uniffi_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ pub fn use_udl_object(tokens: TokenStream) -> TokenStream {
}.into()
}

#[proc_macro]
pub fn use_udl_trait(tokens: TokenStream) -> TokenStream {
let util::ExternalTypeItem {
crate_ident,
type_ident,
..
} = parse_macro_input!(tokens);
quote! {
::uniffi::ffi_converter_arc_forward!(dyn #type_ident, #crate_ident::UniFfiTag, crate::UniFfiTag);
}.into()
}

/// A helper macro to generate and include component scaffolding.
///
/// This is a convenience macro designed for writing `trybuild`-style tests and
Expand Down
28 changes: 6 additions & 22 deletions uniffi_macros/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,37 +209,21 @@ pub(crate) fn tagged_impl_header(
udl_mode: bool,
) -> TokenStream {
let trait_name = Ident::new(trait_name, Span::call_site());
if udl_mode {
quote! { impl ::uniffi::#trait_name<crate::UniFfiTag> for #ident }
} else {
quote! { impl<T> ::uniffi::#trait_name<T> for #ident }
}
quote! { impl ::uniffi::#trait_name<crate::UniFfiTag> for #ident }
}

pub(crate) fn derive_all_ffi_traits(ty: &Ident, udl_mode: bool) -> TokenStream {
if udl_mode {
quote! { ::uniffi::derive_ffi_traits!(local #ty); }
} else {
quote! { ::uniffi::derive_ffi_traits!(blanket #ty); }
}
quote! { ::uniffi::derive_ffi_traits!(local #ty); }
}

pub(crate) fn derive_ffi_traits(ty: &Ident, udl_mode: bool, trait_names: &[&str]) -> TokenStream {
let trait_idents = trait_names
.iter()
.map(|name| Ident::new(name, Span::call_site()));
if udl_mode {
quote! {
#(
::uniffi::derive_ffi_traits!(impl #trait_idents<crate::UniFfiTag> for #ty);
)*
}
} else {
quote! {
#(
::uniffi::derive_ffi_traits!(impl<UT> #trait_idents<UT> for #ty);
)*
}
quote! {
#(
::uniffi::derive_ffi_traits!(impl #trait_idents<crate::UniFfiTag> for #ty);
)*
}
}

Expand Down
6 changes: 3 additions & 3 deletions uniffi_meta/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a> ExternalTypeConverter<'a> {
module_path,
name,
kind: ExternalKind::DataClass,
tagged: false,
tagged: true,
}
}
Type::Custom {
Expand All @@ -202,7 +202,7 @@ impl<'a> ExternalTypeConverter<'a> {
module_path,
name,
kind: ExternalKind::DataClass,
tagged: false,
tagged: true,
}
}
Type::Object {
Expand All @@ -212,7 +212,7 @@ impl<'a> ExternalTypeConverter<'a> {
module_path,
name,
kind: ExternalKind::Interface,
tagged: false,
tagged: true,
},
Type::CallbackInterface { module_path, name }
if self.is_module_path_external(&module_path) =>
Expand Down
9 changes: 0 additions & 9 deletions uniffi_udl/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,6 @@ impl TypedefAttributes {
_ => None,
})
}

pub(super) fn external_tagged(&self) -> Option<bool> {
// If it was "exported" via a proc-macro the FfiConverter was not tagged.
self.0.iter().find_map(|attr| match attr {
Attribute::External { export, .. } => Some(!*export),
Attribute::Rust { .. } => Some(false),
_ => None,
})
}
}

impl TryFrom<&weedle::attribute::ExtendedAttributeList<'_>> for TypedefAttributes {
Expand Down
3 changes: 1 addition & 2 deletions uniffi_udl/src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,12 @@ impl TypeFinder for weedle::TypedefDefinition<'_> {
// must be external
None => {
let kind = attrs.external_kind().expect("External missing kind");
let tagged = attrs.external_tagged().expect("External missing tagged");
Type::External {
name,
namespace: "".to_string(), // we don't know this yet
module_path: attrs.get_crate_name(),
kind,
tagged,
tagged: true,
}
}
};
Expand Down