Skip to content

Commit

Permalink
Make uniffi_build optional in uniffi_macros
Browse files Browse the repository at this point in the history
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 committed Mar 8, 2024
1 parent 0a5e2eb commit 5b9956b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 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
4 changes: 3 additions & 1 deletion uniffi_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ quote = "1.0"
serde = "1.0.136"
syn = { version = "2.0", features = ["full", "visit-mut"] }
toml = "0.5.9"
uniffi_build = { path = "../uniffi_build", version = "=0.26.0" }
uniffi_build = { path = "../uniffi_build", version = "=0.26.0", optional = true }
uniffi_meta = { path = "../uniffi_meta", version = "=0.26.0" }

[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 5b9956b

Please sign in to comment.