Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make mod_path() consistent with/without nightly feature #2330

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
18 changes: 11 additions & 7 deletions uniffi_macros/src/setup_scaffolding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ use uniffi_meta::UNIFFI_CONTRACT_VERSION;

pub fn setup_scaffolding(namespace: String) -> Result<TokenStream> {
let module_path = mod_path()?;
let ffi_contract_version_ident = format_ident!("ffi_{module_path}_uniffi_contract_version");
let normalized_module_path = module_path.replace("::", "__");
let ffi_contract_version_ident =
format_ident!("ffi_{normalized_module_path}_uniffi_contract_version");
let namespace_upper = namespace.to_ascii_uppercase();
let namespace_const_ident = format_ident!("UNIFFI_META_CONST_NAMESPACE_{namespace_upper}");
let namespace_static_ident = format_ident!("UNIFFI_META_NAMESPACE_{namespace_upper}");
let ffi_rustbuffer_alloc_ident = format_ident!("ffi_{module_path}_rustbuffer_alloc");
let ffi_rustbuffer_from_bytes_ident = format_ident!("ffi_{module_path}_rustbuffer_from_bytes");
let ffi_rustbuffer_free_ident = format_ident!("ffi_{module_path}_rustbuffer_free");
let ffi_rustbuffer_reserve_ident = format_ident!("ffi_{module_path}_rustbuffer_reserve");
let reexport_hack_ident = format_ident!("{module_path}_uniffi_reexport_hack");
let ffi_rust_future_scaffolding_fns = rust_future_scaffolding_fns(&module_path);
let ffi_rustbuffer_alloc_ident = format_ident!("ffi_{normalized_module_path}_rustbuffer_alloc");
let ffi_rustbuffer_from_bytes_ident =
format_ident!("ffi_{normalized_module_path}_rustbuffer_from_bytes");
let ffi_rustbuffer_free_ident = format_ident!("ffi_{normalized_module_path}_rustbuffer_free");
let ffi_rustbuffer_reserve_ident =
format_ident!("ffi_{normalized_module_path}_rustbuffer_reserve");
let reexport_hack_ident = format_ident!("{normalized_module_path}_uniffi_reexport_hack");
let ffi_rust_future_scaffolding_fns = rust_future_scaffolding_fns(&normalized_module_path);

Ok(quote! {
// Unit struct to parameterize the FfiConverter trait.
Expand Down
9 changes: 9 additions & 0 deletions uniffi_meta/src/ffi_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,37 @@
/// FFI symbol name for a top-level function
pub fn fn_symbol_name(namespace: &str, name: &str) -> String {
let namespace = namespace.replace("::", "__");
let name = name.to_ascii_lowercase();
format!("uniffi_{namespace}_fn_func_{name}")
}

/// FFI symbol name for an object constructor
pub fn constructor_symbol_name(namespace: &str, object_name: &str, name: &str) -> String {
let namespace = namespace.replace("::", "__");
let object_name = object_name.to_ascii_lowercase();
let name = name.to_ascii_lowercase();
format!("uniffi_{namespace}_fn_constructor_{object_name}_{name}")
}

/// FFI symbol name for an object method
pub fn method_symbol_name(namespace: &str, object_name: &str, name: &str) -> String {
let namespace = namespace.replace("::", "__");
let object_name = object_name.to_ascii_lowercase();
let name = name.to_ascii_lowercase();
format!("uniffi_{namespace}_fn_method_{object_name}_{name}")
}

/// FFI symbol name for the `clone` function for an object.
pub fn clone_fn_symbol_name(namespace: &str, object_name: &str) -> String {
let namespace = namespace.replace("::", "__");
let object_name = object_name.to_ascii_lowercase();
format!("uniffi_{namespace}_fn_clone_{object_name}")
}

/// FFI symbol name for the `free` function for an object.
pub fn free_fn_symbol_name(namespace: &str, object_name: &str) -> String {
let namespace = namespace.replace("::", "__");
let object_name = object_name.to_ascii_lowercase();
format!("uniffi_{namespace}_fn_free_{object_name}")
}
Expand All @@ -50,25 +55,29 @@ pub fn init_callback_vtable_fn_symbol_name(
namespace: &str,
callback_interface_name: &str,
) -> String {
let namespace = namespace.replace("::", "__");
let callback_interface_name = callback_interface_name.to_ascii_lowercase();
format!("uniffi_{namespace}_fn_init_callback_vtable_{callback_interface_name}")
}

/// FFI checksum symbol name for a top-level function
pub fn fn_checksum_symbol_name(namespace: &str, name: &str) -> String {
let namespace = namespace.replace("::", "__");
let name = name.to_ascii_lowercase();
format!("uniffi_{namespace}_checksum_func_{name}")
}

/// FFI checksum symbol name for an object constructor
pub fn constructor_checksum_symbol_name(namespace: &str, object_name: &str, name: &str) -> String {
let namespace = namespace.replace("::", "__");
let object_name = object_name.to_ascii_lowercase();
let name = name.to_ascii_lowercase();
format!("uniffi_{namespace}_checksum_constructor_{object_name}_{name}")
}

/// FFI checksum symbol name for an object method
pub fn method_checksum_symbol_name(namespace: &str, object_name: &str, name: &str) -> String {
let namespace = namespace.replace("::", "__");
let object_name = object_name.to_ascii_lowercase();
let name = name.to_ascii_lowercase();
format!("uniffi_{namespace}_checksum_method_{object_name}_{name}")
Expand Down