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.rs52
3 files changed, 92 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..8e585bfa95
--- /dev/null
+++ b/third_party/rust/uniffi_build/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"a6db989e5a3d597219df0a9c94541130b7db607efd8606043cd1187971020639","src/lib.rs":"47ff3d1a18456164414af1c20cd5df129401e5257cc15552ecc39afed8970707"},"package":"001964dd3682d600084b3aaf75acf9c3426699bc27b65e96bb32d175a31c74e9"} \ 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..3fe7ee5cf0
--- /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.25.3"
+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.25.3"
+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..0cb865db82
--- /dev/null
+++ b/third_party/rust/uniffi_build/src/lib.rs
@@ -0,0 +1,52 @@
+/* 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.
+///
+/// This function will attempt to locate and parse a corresponding Cargo.toml to
+/// determine the crate name which will host this UDL.
+///
+/// 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}");
+ println!("cargo:rerun-if-env-changed=UNIFFI_TESTS_DISABLE_EXTENSIONS");
+ let out_dir = env::var("OUT_DIR").context("$OUT_DIR missing?!")?;
+ uniffi_bindgen::generate_component_scaffolding(udl_file, Some(out_dir.as_ref()), false)
+}
+
+/// Like generate_scaffolding, but uses the specified crate_name instead of locating and parsing
+/// Cargo.toml.
+pub fn generate_scaffolding_for_crate(
+ udl_file: impl AsRef<Utf8Path>,
+ crate_name: &str,
+) -> 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_for_crate(
+ udl_file,
+ crate_name,
+ Some(out_dir.as_ref()),
+ false,
+ )
+}