summaryrefslogtreecommitdiffstats
path: root/third_party/rust/uniffi_build
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/uniffi_build')
-rw-r--r--third_party/rust/uniffi_build/.cargo-checksum.json1
-rw-r--r--third_party/rust/uniffi_build/Cargo.toml39
-rw-r--r--third_party/rust/uniffi_build/src/lib.rs31
3 files changed, 71 insertions, 0 deletions
diff --git a/third_party/rust/uniffi_build/.cargo-checksum.json b/third_party/rust/uniffi_build/.cargo-checksum.json
new file mode 100644
index 0000000000..c5bdbe8be2
--- /dev/null
+++ b/third_party/rust/uniffi_build/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"b0825cba8bdc4e5592b196c95bc55ef417324b440270642b8d6ed7c87f6c853b","src/lib.rs":"e344fb4e5390a17f151456d8d902b554399ef8934744ea4c7aa27f285ab59dfa"},"package":"0ee1a28368ff3d83717e3d3e2e15a66269c43488c3f036914131bb68892f29fb"} \ No newline at end of file
diff --git a/third_party/rust/uniffi_build/Cargo.toml b/third_party/rust/uniffi_build/Cargo.toml
new file mode 100644
index 0000000000..c7a0cced61
--- /dev/null
+++ b/third_party/rust/uniffi_build/Cargo.toml
@@ -0,0 +1,39 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2021"
+name = "uniffi_build"
+version = "0.23.0"
+authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
+description = "a multi-language bindings generator for rust (build script helpers)"
+homepage = "https://mozilla.github.io/uniffi-rs"
+documentation = "https://mozilla.github.io/uniffi-rs"
+keywords = [
+ "ffi",
+ "bindgen",
+]
+license = "MPL-2.0"
+repository = "https://github.com/mozilla/uniffi-rs"
+
+[dependencies.anyhow]
+version = "1"
+
+[dependencies.camino]
+version = "1.0.8"
+
+[dependencies.uniffi_bindgen]
+version = "=0.23.0"
+default-features = false
+
+[features]
+builtin-bindgen = []
+default = []
diff --git a/third_party/rust/uniffi_build/src/lib.rs b/third_party/rust/uniffi_build/src/lib.rs
new file mode 100644
index 0000000000..6a5bb9bad8
--- /dev/null
+++ b/third_party/rust/uniffi_build/src/lib.rs
@@ -0,0 +1,31 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use anyhow::{Context, Result};
+use camino::Utf8Path;
+use std::env;
+
+/// Generate the rust "scaffolding" required to build a uniffi component.
+///
+/// Given the path to an UDL file, this function will call the `uniffi-bindgen`
+/// command-line tool to generate the `pub extern "C"` functions and other supporting
+/// code required to expose the defined interface from Rust. The expectation is that
+/// this will be called from a crate's build script, and the resulting file will
+/// be `include!()`ed into the build.
+///
+/// Given an UDL file named `example.udl`, the generated scaffolding will be written
+/// into a file named `example.uniffi.rs` in the `$OUT_DIR` directory.
+pub fn generate_scaffolding(udl_file: impl AsRef<Utf8Path>) -> Result<()> {
+ let udl_file = udl_file.as_ref();
+
+ println!("cargo:rerun-if-changed={udl_file}");
+ // The UNIFFI_TESTS_DISABLE_EXTENSIONS variable disables some bindings, but it is evaluated
+ // at *build* time, so we need to rebuild when it changes.
+ println!("cargo:rerun-if-env-changed=UNIFFI_TESTS_DISABLE_EXTENSIONS");
+ // Why don't we just depend on uniffi-bindgen and call the public functions?
+ // Calling the command line helps making sure that the generated swift/Kotlin/whatever
+ // bindings were generated with the same version of uniffi as the Rust scaffolding code.
+ let out_dir = env::var("OUT_DIR").context("$OUT_DIR missing?!")?;
+ uniffi_bindgen::generate_component_scaffolding(udl_file, None, Some(out_dir.as_ref()), false)
+}