Skip to content

Commit

Permalink
Make uniffi_build optional in uniffi_macros (#2019)
Browse files Browse the repository at this point in the history
* Add missing derive feature to serde dependency

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.

* Make `uniffi_build` optional in `uniffi_macros`

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.
  • Loading branch information
mgeisler authored Mar 11, 2024
1 parent 968e625 commit 075efd9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fixtures/uitests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 4 additions & 2 deletions uniffi_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ 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" }
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.
Expand Down
2 changes: 2 additions & 0 deletions uniffi_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

//! Macros for `uniffi`.
#[cfg(feature = "trybuild")]
use camino::Utf8Path;
use proc_macro::TokenStream;
use quote::quote;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 075efd9

Please sign in to comment.