Skip to content

Commit 075efd9

Browse files
authored
Make uniffi_build optional in uniffi_macros (mozilla#2019)
* 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.
1 parent 968e625 commit 075efd9

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

fixtures/uitests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ name = "uniffi_uitests"
1111

1212
[dependencies]
1313
uniffi = { workspace = true }
14-
uniffi_macros = {path = "../../uniffi_macros"}
14+
uniffi_macros = { path = "../../uniffi_macros", features = ["trybuild"] }
1515
thiserror = "1.0"
1616

1717
[dev-dependencies]

uniffi_bindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ goblin = "0.8"
2222
heck = "0.4"
2323
once_cell = "1.12"
2424
paste = "1.0"
25-
serde = "1"
25+
serde = { version = "1", features = ["derive"] }
2626
toml = "0.5"
2727
uniffi_meta = { path = "../uniffi_meta", version = "=0.26.1" }
2828
uniffi_testing = { path = "../uniffi_testing", version = "=0.26.1" }

uniffi_macros/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ fs-err = "2.7.0"
2121
once_cell = "1.10.0"
2222
proc-macro2 = "1.0"
2323
quote = "1.0"
24-
serde = "1.0.136"
24+
serde = { version = "1.0.136", features = ["derive"] }
2525
syn = { version = "2.0", features = ["full", "visit-mut"] }
2626
toml = "0.5.9"
27-
uniffi_build = { path = "../uniffi_build", version = "=0.26.1" }
27+
uniffi_build = { path = "../uniffi_build", version = "=0.26.1", optional = true }
2828
uniffi_meta = { path = "../uniffi_meta", version = "=0.26.1" }
2929

3030
[features]
3131
default = []
32+
# Enable the generate_and_include_scaffolding! macro
33+
trybuild = [ "dep:uniffi_build" ]
3234
# Enable extra features that require a nightly compiler:
3335
# * Add the full module path of exported items to FFI metadata instead of just the crate name.
3436
# This may be used by language backends to generate nested module structures in the future.

uniffi_macros/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
//! Macros for `uniffi`.
88
9+
#[cfg(feature = "trybuild")]
910
use camino::Utf8Path;
1011
use proc_macro::TokenStream;
1112
use quote::quote;
@@ -343,6 +344,7 @@ pub fn use_udl_object(tokens: TokenStream) -> TokenStream {
343344
/// uniffi_macros::generate_and_include_scaffolding!("path/to/my/interface.udl");
344345
/// ```
345346
#[proc_macro]
347+
#[cfg(feature = "trybuild")]
346348
pub fn generate_and_include_scaffolding(udl_file: TokenStream) -> TokenStream {
347349
let udl_file = syn::parse_macro_input!(udl_file as LitStr);
348350
let udl_file_string = udl_file.value();

0 commit comments

Comments
 (0)