Skip to content

Commit fbe146f

Browse files
authored
Stop supporting typedef extern, [ExternalInterface=...] in UDL etc. (#2355)
This consolidates how external types are expressed in UDL. Instead of ``` [External="crate_name"] typedef extern MyEnum [ExternalInterface="crate_name"] typedef extern MyInterface ``` you would use: ``` [External="crate_name"] typedef enum MyEnum [External="crate_name"] typedef interface MyInterface ``` See the docs and upgrading notes in this commit for more.
1 parent fa02b83 commit fbe146f

File tree

15 files changed

+318
-321
lines changed

15 files changed

+318
-321
lines changed

docs/manual/src/Upgrading.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# v0.28.x -> v0.29.x
1+
# Upgrading v0.28.x -> v0.29.x
2+
3+
We've made a number of breaking changes in this release, particularly
4+
to:
5+
6+
* Custom types (both UDL and proc-macros impacted)
7+
* External Types (UDL impacted)
28

39
## Custom types
410

@@ -32,3 +38,45 @@ uniffi::custom_type!(NewCustomType, BridgeType, {
3238

3339
The `custom_type!` macro is more flexible than the old system - eg, the closures can be omitted in many cases where `From` and `Into` exist.
3440
See the [Custom Types](./types/custom_types.md) for details.
41+
42+
## External Types
43+
44+
External types can no longer be described in UDL via `extern` - instead, you must specify the type.
45+
46+
For example:
47+
```
48+
[External="crate_name"]
49+
typedef extern MyEnum
50+
```
51+
is no longer accepted - you must use, eg:
52+
```
53+
[External="crate_name"]
54+
typedef enum MyEnum
55+
```
56+
57+
Edge-cases broken include:
58+
59+
* Different variations of the `External` attribute (eg, `[ExternalInterface]`) are no longer supported; eg, `[ExternalInterface=".."] typedef extern ...` becomes `[External=".."] typedef interface ...` )
60+
* The `[Rust=..]` attribute has been removed - you should just remove the attribute entirely.
61+
62+
See [Remote and External Types](./types/remote_ext_types.md) for more detail.
63+
64+
## Remote Types
65+
66+
The macros `ffi_converter_forward` and all `use_*` macros (eg, `use_udl_record!`, `use_udl_object!`, `use_udl_enum!` etc)
67+
are now unnecessary so have been removed.
68+
69+
See [Remote and External Types](./types/remote_ext_types.md) for more detail.
70+
71+
## Shared Rust/UDL types
72+
73+
The `Rust` attribute has been removed - use the same typedef syntax described above for External Types.
74+
75+
```
76+
[Rust="record"]
77+
typedef extern One;
78+
```
79+
becomes
80+
```
81+
typedef record One;
82+
```

docs/manual/src/tutorial/foreign_language_bindings.md

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ You can now run `uniffi-bindgen` from your project using `cargo run --features=u
3333
### Multi-crate workspaces
3434

3535
In a multiple crates workspace, you can create a separate crate for running `uniffi-bindgen`:
36+
3637
- Name the crate `uniffi-bindgen`, add it to your workspace.
3738
- Add this dependency to `Cargo.toml`: `uniffi = {version = "0.XX.0", features = ["cli"] }`
3839
- As above, add the `uniffi-bindgen` binary target
@@ -57,6 +58,7 @@ Then look in the `out` directory.
5758
When using library mode, if multiple crates get built into the library that use UniFFI, all will have bindings generated for them.
5859

5960
Library mode comes with some extra requirements:
61+
6062
- It must be run from within the cargo workspace of your project
6163
- Each crate must use exactly 1 UDL file when compiling the Rust library. However, crates can have
6264
multiple UDL files as long as they ensure only one is used for any particular build,

docs/manual/src/types/remote_ext_types.md

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Supported values for the typedef type:
8080
* Records: `record`, `dictionary` or `struct`
8181
* Objects: `object`, `impl` or `interface`
8282
* Traits: `trait`, `callback` or `trait_with_foreign`
83+
* Custom types: `custom`
8384

8485
# Special cases for remote types
8586

docs/manual/src/udl/external_types.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Using types defined outside a UDL.
2+
3+
Often you need to refer to types described outside of this UDL - they
4+
may be defined in a proc-macro in this crate or defined in an external crate.
5+
6+
You declare such types using:
7+
```idl
8+
typedef [type] [TypeName];
9+
```
10+
`TypeName` is then able to be used as a normal type in this UDL (ie, be returned from functions, in records, etc)
11+
12+
`type` indicates the actual type of `TypeName` and can be any of the following values:
13+
* "enum" for Enums.
14+
* "record", "dictionary" or "struct" for Records.
15+
* "object", "impl" or "interface" for objects.
16+
* "trait", "callback" or "trait_with_foreign" for traits.
17+
* "custom" for Custom Types.
18+
19+
for example, if this crate has:
20+
```rust
21+
#[derive(::uniffi::Object)]
22+
struct MyObject { ... }
23+
```
24+
our UDL could use this type with:
25+
```
26+
typedef interface MyObject;
27+
```
28+
29+
# External Crates
30+
31+
The `[External="crate_name"]` attribute can be used whenever the type is in another crate - whether in UDL or in a proc-macro.
32+
33+
```
34+
[External = "other_crate"]
35+
typedef interface OtherObject;
36+
```

fixtures/ext-types/lib/src/ext-types-lib.udl

+11-12
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,34 @@ namespace imported_types_lib {
2525
// A type defined in a .udl file in the `uniffi-one` crate (ie, in
2626
// `../../uniffi-one/src/uniffi-one.udl`)
2727
[External="uniffi_one"]
28-
typedef extern UniffiOneType;
28+
typedef dictionary UniffiOneType;
2929

3030
// An enum in the same crate
3131
[External="uniffi_one"]
32-
typedef extern UniffiOneEnum;
32+
typedef enum UniffiOneEnum;
3333

3434
// An interface in the same crate
35-
[ExternalInterface="uniffi_one"]
36-
typedef extern UniffiOneInterface;
35+
[External="uniffi_one"]
36+
typedef interface UniffiOneInterface;
3737

3838
// An UDL defined trait
39-
[ExternalTrait="uniffi_one"]
40-
typedef extern UniffiOneUDLTrait;
39+
[External="uniffi_one"]
40+
typedef trait UniffiOneUDLTrait;
4141

4242
// A type defined via procmacros in an external crate
43-
[ExternalExport="uniffi_one"]
44-
typedef extern UniffiOneProcMacroType;
43+
[External="uniffi_one"]
44+
typedef dictionary UniffiOneProcMacroType;
4545

4646
// A Custom (ie, "wrapped") type defined externally in `../../custom-types/src/lib.rs`,
47-
// but because it's in a UDL it's still "external" from our POV, so same as the `.udl` type above.
4847
[External="ext_types_custom"]
49-
typedef extern Guid;
48+
typedef custom Guid;
5049

5150
// And re-use the `custom-types` example - this exposes `Url` and `Handle`
5251
[External="custom_types"]
53-
typedef extern Url;
52+
typedef custom Url;
5453

5554
[External="custom_types"]
56-
typedef extern Handle;
55+
typedef custom Handle;
5756

5857
// Here are some different kinds of remote types - the types are described
5958
// in this UDL, but the types themselves are defined in a different crate.

fixtures/proc-macro-no-implicit-prelude/src/proc-macro.udl

+5-16
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,11 @@ dictionary Zero {
33
string inner;
44
};
55

6-
// NOTE: `[Rust=..]` is deprecated and this test hasn't migrated.
7-
// This helps testing the attribute, so don't remove them unless you are removing support entirely!
8-
[Rust="record"]
9-
typedef extern One;
10-
11-
[Rust="enum"]
12-
typedef extern MaybeBool;
13-
14-
[Rust="interface"]
15-
typedef extern Object;
16-
17-
[Rust="trait"]
18-
typedef extern Trait;
19-
20-
[Rust="trait_with_foreign"]
21-
typedef extern TraitWithForeign;
6+
typedef record One;
7+
typedef enum MaybeBool;
8+
typedef interface Object;
9+
typedef trait Trait;
10+
typedef trait_with_foreign TraitWithForeign;
2211

2312
// Then stuff defined here but referencing the imported types.
2413
dictionary Externals {
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace uitests {};
2+
3+
typedef extern Foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Unfortunately, path is relative to a temporary build directory :-/
2+
uniffi_macros::generate_and_include_scaffolding!("../../../../fixtures/uitests/src/typedef_extern.udl");
3+
4+
fn main() { /* empty main required by `trybuild` */}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: Failed to generate scaffolding from UDL file at ../../../../fixtures/uitests/src/typedef_extern.udl: `typedef extern` is no longer supported.
2+
You must replace `extern` with the type of the object:
3+
* "enum" for Enums.
4+
* "record", "dictionary" or "struct" for Records.
5+
* "object", "impl" or "interface" for objects.
6+
* "trait", "callback" or "trait_with_foreign" for traits.
7+
* "custom" for Custom Types.
8+
9+
For example:
10+
[External="crate_name"]
11+
typedef extern ExternalEnum;
12+
13+
Would be replaced with:
14+
[External="crate_name"]
15+
typedef enum ExternalEnum;
16+
17+
See https://mozilla.github.io/uniffi-rs/next/types/remote_ext_types.html for more.
18+
--> tests/ui/typedef_extern.rs:2:1
19+
|
20+
2 | uniffi_macros::generate_and_include_scaffolding!("../../../../fixtures/uitests/src/typedef_extern.udl");
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= note: this error originates in the macro `uniffi_macros::generate_and_include_scaffolding` (in Nightly builds, run with -Z macro-backtrace for more info)

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ nav:
5959
- ./udl/functions.md
6060
- ./udl/interfaces.md
6161
- ./udl/records.md
62+
- ./udl/external_types.md
6263
- ./udl/docstrings.md
6364
- 'Proc macros':
6465
- ./proc_macro/index.md

0 commit comments

Comments
 (0)