You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>As already noted UniFFI supports two methods of interface definitions: UDL files and proc macros.</p>
1489
-
<p>If you use proc macros you can skip the next section, but if you use UDL files, you need to generate Rust "scaffolding" - code to implement what's described in the UDL.</p>
1488
+
<p>UniFFI requires that our generated Rust "scaffolding" code is included in your project. For proc macros, most of this is conveniently generated by the macros.</p>
1489
+
<p>If you use UDL files, you need to generate this "scaffolding" then include the generated .rs in your project.</p>
1490
1490
<h2id="rust-scaffolding-code-for-udl">Rust scaffolding code for UDL</h2>
1491
1491
<p>Crates using UDL need a <code>build.rs</code> file next to <code>Cargo.toml</code>. This uses <code>uniffi</code> to generate the Rust scaffolding code.</p>
<p>NOTE: This function takes an optional parameter, the <ahref="../udl/namespace.html"><code>namespace</code></a> used by the component.
1506
-
If not specified, the crate name will be used as the namespace.</p>
1507
-
<p><strong>⚠ Warning ⚠</strong> Do not call both <code>uniffi::setup_scaffolding!()</code> and <code>uniffi::include_scaffolding!!()</code> in the same crate.</p>
1505
+
<p>Don't use <code>uniffi::setup_scaffolding!()</code> in a crate which uses <code>uniffi::include_scaffolding!()</code>.</p>
1506
+
<p>If you don't specify a <ahref="../udl/namespace.html"><code>namespace</code></a> the crate name is used.</p>
1508
1507
<h3id="libraries-that-depend-on-uniffi-components">Libraries that depend on UniFFI components</h3>
1509
1508
<p>Suppose you want to create a shared library that includes one or more
1510
1509
components using UniFFI. The typical way to achieve this is to create a new
<h1id="describing-the-interface">Describing the interface</h1>
1440
-
<p>There are two ways of describing your interface:
1441
-
1 - with a UDL file (a type of IDL, Interface Definition Language);
1442
-
2 - with <ahref="../proc_macro/index.html">Rust procmacros</a>, similarly to how <code>wasm-bindgen</code> work. This avoids repeating your interface definitions in a separate file. Unfortunately, our docs aren't quite as good for that yet though.</p>
1443
-
<h2id="the-udl-file">The UDL File</h2>
1458
+
<p>There are two ways of describing your interface:</p>
1459
+
<h2id="proc-macros">Proc macros</h2>
1460
+
<p><ahref="../proc_macro/index.html">Rust proc macros</a> can describe your interface - you'd define the function as:</p>
<p>You need to <ahref="./Rust_scaffolding.md"">set up the scaffolding</a> with <code>uniffi::setup_scaffolding!()</code> - but that's it.</p>
1465
+
<h2id="a-udl-file">A UDL File</h2>
1444
1466
<p>We describe in a UDL (a type of IDL, Interface Definition Language) file <em>what</em> is exposed and available to foreign-language bindings. In this case, we are only playing with primitive types (<code>u32</code>) and not custom data structures but we still want to expose the <code>add</code> method.<br/>
1445
1467
Let's create a <code>math.udl</code> file in the <code>math</code> crate's <code>src/</code> folder:</p>
0 commit comments