Skip to content

Commit ed9362a

Browse files
authored
Improve docs re: proc macros (#1848)
1 parent 41e3f95 commit ed9362a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

docs/manual/src/proc_macro/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ true for all of UniFFI, so proceed with caution and the knowledge that things ma
2323

2424
## Build workflow
2525

26-
Library mode is recommended when using UniFFI proc-macros (See the [Foreign language bindings docs](../tutorial/foreign_language_bindings.md) for more info).
26+
Be sure to use library mode when using UniFFI proc-macros (See the [Foreign language bindings docs](../tutorial/foreign_language_bindings.md) for more info).
2727

2828
If your crate's API is declared using only proc-macros and not UDL files, call the `uniffi::setup_scaffolding` macro at the top of your source code:
2929

docs/manual/src/tutorial/Rust_scaffolding.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ uniffi = "0.XX.0"
1414
uniffi = { version = "0.XX.0", features = ["build"] }
1515
```
1616

17-
Then create a `build.rs` file next to `Cargo.toml` that uses `uniffi` to generate the Rust scaffolding code.
17+
As noted in [Describing the interface](udl_file.md), UniFFI currently supports two methods of interface definitions: UDL files and proc macros.
18+
If you are using only proc macros, you can skip some boilerplate in your crate setup as well.
19+
20+
### Setup for crates using UDL
21+
22+
Crates using UDL need a `build.rs` file next to `Cargo.toml`. This uses `uniffi` to generate the Rust scaffolding code.
1823

1924
```rust
2025
fn main() {
@@ -30,7 +35,18 @@ uniffi::include_scaffolding!("math");
3035

3136
**Note:** The file name is always `<namespace>.uniffi.rs`.
3237

33-
Great! `add` is ready to see the outside world!
38+
### Setup for crates using only proc macros
39+
40+
If you are only using proc macros, you can skip `build.rs` entirely!
41+
All you need to do is add this to the top of `lib.rs`
42+
NOTE: This function takes an optional parameter, the [`namespace`](../udl/namespace.md) used by the component.
43+
If not specified, the crate name will be used as the namespace.
44+
45+
```rust
46+
uniffi::setup_scaffolding!();
47+
```
48+
49+
**⚠ Warning ⚠** Do not call both `uniffi::setup_scaffolding!()` and `uniffi::include_scaffolding!!()` in the same crate.
3450

3551
### Libraries that depend on UniFFI components
3652

docs/manual/src/tutorial/foreign_language_bindings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ creating a binary for each crate that uses UniFFI. You can avoid this by creati
3838

3939
Then your can run `uniffi-bindgen` from any create in your project using `cargo run -p uniffi-bindgen [args]`
4040

41-
## Running uniffi-bindgen using a library file
41+
## Running uniffi-bindgen using a library file (RECOMMENDED)
4242

4343
Use `generate --library` to generate foreign bindings by using a cdylib file built for your library.
4444
This flag was added in UniFFI 0.24 and can be more convenient than specifying the UDL file -- especially when multiple UniFFI-ed crates are built together in one library.
45-
The plan is to make library mode the default in a future UniFFI version.
45+
The plan is to make library mode the default in a future UniFFI version, and it is highly recommended to specify the flag for now (because some features simply don't work otherwise).
4646

4747
Taking `example/arithmetic` as an example, you can generate the bindings with:
4848
```

0 commit comments

Comments
 (0)