From 8f2712868e9aa77fb4b2ed81abee04dbd50d36c4 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Mon, 11 Mar 2024 14:05:40 +0100 Subject: [PATCH 1/2] Add missing derive feature to serde dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code built without this, but that seems to because of an accident since the derive feature is not a default serde feature. I noticed this when trying to make uniffi_build an optional dependency of uniffi_macros — for some reason I don’t understand, this would make `cargo build -p uniffi_macros` fail wtih: error: cannot find derive macro `Deserialize` in this scope --> uniffi_macros/src/util.rs:29:14 | 29 | #[derive(Deserialize)] | ^^^^^^^^^^^ | The error makes sense since the derive feature wasn’t enabled. What does not make sense to me is that the error wasn’t triggered before. --- uniffi_bindgen/Cargo.toml | 2 +- uniffi_macros/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/uniffi_bindgen/Cargo.toml b/uniffi_bindgen/Cargo.toml index 419c0c095a..816c283f29 100644 --- a/uniffi_bindgen/Cargo.toml +++ b/uniffi_bindgen/Cargo.toml @@ -22,7 +22,7 @@ goblin = "0.8" heck = "0.4" once_cell = "1.12" paste = "1.0" -serde = "1" +serde = { version = "1", features = ["derive"] } toml = "0.5" uniffi_meta = { path = "../uniffi_meta", version = "=0.26.1" } uniffi_testing = { path = "../uniffi_testing", version = "=0.26.1" } diff --git a/uniffi_macros/Cargo.toml b/uniffi_macros/Cargo.toml index 2a3626e8db..0f62aa5012 100644 --- a/uniffi_macros/Cargo.toml +++ b/uniffi_macros/Cargo.toml @@ -21,7 +21,7 @@ fs-err = "2.7.0" once_cell = "1.10.0" proc-macro2 = "1.0" quote = "1.0" -serde = "1.0.136" +serde = { version = "1.0.136", features = ["derive"] } syn = { version = "2.0", features = ["full", "visit-mut"] } toml = "0.5.9" uniffi_build = { path = "../uniffi_build", version = "=0.26.1" } From 0a5a8687ad58bb771d1547954119daabc92b63ac Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Fri, 8 Mar 2024 16:57:49 +0100 Subject: [PATCH 2/2] Make `uniffi_build` optional in `uniffi_macros` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As far as I can see, the dependency on uniffi_build is not needed for the macros used by regular clients of UniFFI — it is only used to create a convenience macro for the UI tests. I named the new feature “trybuild” after the description of the macro. Please let me know if you have preferences for a better name. The overall goal here is to minimize the number of crates I need to vendor to use UniFFI — I’m hoping to get away with checking in the generated target language sources, so I’m currently focusing on the dependencies in the rest of the code base. --- fixtures/uitests/Cargo.toml | 2 +- uniffi_macros/Cargo.toml | 4 +++- uniffi_macros/src/lib.rs | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fixtures/uitests/Cargo.toml b/fixtures/uitests/Cargo.toml index 1f68b84e49..c61082d247 100644 --- a/fixtures/uitests/Cargo.toml +++ b/fixtures/uitests/Cargo.toml @@ -11,7 +11,7 @@ name = "uniffi_uitests" [dependencies] uniffi = { workspace = true } -uniffi_macros = {path = "../../uniffi_macros"} +uniffi_macros = { path = "../../uniffi_macros", features = ["trybuild"] } thiserror = "1.0" [dev-dependencies] diff --git a/uniffi_macros/Cargo.toml b/uniffi_macros/Cargo.toml index 0f62aa5012..e121dd8853 100644 --- a/uniffi_macros/Cargo.toml +++ b/uniffi_macros/Cargo.toml @@ -24,11 +24,13 @@ quote = "1.0" serde = { version = "1.0.136", features = ["derive"] } syn = { version = "2.0", features = ["full", "visit-mut"] } toml = "0.5.9" -uniffi_build = { path = "../uniffi_build", version = "=0.26.1" } +uniffi_build = { path = "../uniffi_build", version = "=0.26.1", optional = true } uniffi_meta = { path = "../uniffi_meta", version = "=0.26.1" } [features] default = [] +# Enable the generate_and_include_scaffolding! macro +trybuild = [ "dep:uniffi_build" ] # Enable extra features that require a nightly compiler: # * Add the full module path of exported items to FFI metadata instead of just the crate name. # This may be used by language backends to generate nested module structures in the future. diff --git a/uniffi_macros/src/lib.rs b/uniffi_macros/src/lib.rs index 8bfc56f2f5..380572d1d6 100644 --- a/uniffi_macros/src/lib.rs +++ b/uniffi_macros/src/lib.rs @@ -6,6 +6,7 @@ //! Macros for `uniffi`. +#[cfg(feature = "trybuild")] use camino::Utf8Path; use proc_macro::TokenStream; use quote::quote; @@ -343,6 +344,7 @@ pub fn use_udl_object(tokens: TokenStream) -> TokenStream { /// uniffi_macros::generate_and_include_scaffolding!("path/to/my/interface.udl"); /// ``` #[proc_macro] +#[cfg(feature = "trybuild")] pub fn generate_and_include_scaffolding(udl_file: TokenStream) -> TokenStream { let udl_file = syn::parse_macro_input!(udl_file as LitStr); let udl_file_string = udl_file.value();