diff --git a/Cargo.lock b/Cargo.lock index dceccaa87..21a661c00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,51 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +[[package]] +name = "askama" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139" +dependencies = [ + "askama_derive", + "askama_escape", + "askama_shared", +] + +[[package]] +name = "askama_derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71" +dependencies = [ + "askama_shared", + "proc-macro2", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_shared" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0" +dependencies = [ + "askama_escape", + "mime", + "mime_guess", + "nom", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", +] + [[package]] name = "async-io" version = "1.10.0" @@ -132,6 +177,15 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -930,7 +984,7 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67f07131a2b944c2b42b6a58104600ef049c11df5454478d2b44ff5dfe58d149" dependencies = [ - "goblin", + "goblin 0.6.0", ] [[package]] @@ -1141,6 +1195,17 @@ dependencies = [ "regex", ] +[[package]] +name = "goblin" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7666983ed0dd8d21a6f6576ee00053ca0926fb281a5522577a4dbd0f1b54143" +dependencies = [ + "log", + "plain", + "scroll", +] + [[package]] name = "goblin" version = "0.6.0" @@ -1348,7 +1413,7 @@ checksum = "7580a02d700ecc9e06c72b7aace6e74427a56a69310f18fdd420a5fac3832969" dependencies = [ "fs-err", "glob", - "goblin", + "goblin 0.6.0", ] [[package]] @@ -1433,7 +1498,7 @@ dependencies = [ "flate2", "fs-err", "glob", - "goblin", + "goblin 0.6.0", "human-panic", "ignore", "indoc", @@ -1467,6 +1532,7 @@ dependencies = [ "tracing", "tracing-subscriber", "trycmd", + "uniffi_bindgen", "ureq", "zip", ] @@ -1511,6 +1577,12 @@ dependencies = [ "serde", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.5.4" @@ -1586,6 +1658,16 @@ dependencies = [ "memoffset", ] +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -1848,6 +1930,12 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "paste" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" + [[package]] name = "path-slash" version = "0.2.1" @@ -2884,6 +2972,38 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "uniffi_bindgen" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cc4af3c0180c7e86c4a3acf2b6587af04ba2567b1e948993df10f421796621" +dependencies = [ + "anyhow", + "askama", + "bincode", + "camino", + "clap 3.2.23", + "fs-err", + "goblin 0.5.4", + "heck", + "once_cell", + "paste", + "serde", + "serde_json", + "toml", + "uniffi_meta", + "weedle2", +] + +[[package]] +name = "uniffi_meta" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9417cc653937681436b93838d8c5f97a5b8c58697813982ee8810bd1dc3b57" +dependencies = [ + "serde", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -3068,6 +3188,15 @@ dependencies = [ "webpki", ] +[[package]] +name = "weedle2" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e79c5206e1f43a2306fd64bdb95025ee4228960f2e6c5a8b173f3caaf807741" +dependencies = [ + "nom", +] + [[package]] name = "wepoll-ffi" version = "0.1.2" diff --git a/Cargo.toml b/Cargo.toml index f22761319..e71507bbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ cargo-options = "0.5.2" cargo-zigbuild = "0.14.1" cargo-xwin = { version = "0.12.2", default-features = false } cbindgen = { version = "0.24.2", default-features = false } +uniffi_bindgen = "0.21.0" flate2 = "1.0.18" goblin = "0.6.0" human-panic = { version = "1.0.3", optional = true } diff --git a/Changelog.md b/Changelog.md index 972dfea9e..ceb3b6508 100644 --- a/Changelog.md +++ b/Changelog.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add support for 32-bit x86 FreeBSD target in [#1254](https://github.com/PyO3/maturin/pull/1254) * Add `[tool.maturin.include]` and `[tool.maturin.exclude]` and deprecate `[tool.maturin.sdist-include]` [#1255](https://github.com/PyO3/maturin/pull/1255) * Ignore sdist tar ball instead of error out in [#1259](https://github.com/PyO3/maturin/pull/1259) +* Add support for [`uniffi`](https://github.com/mozilla/uniffi-rs) bindings in [#1275](https://github.com/PyO3/maturin/pull/1275) ## [0.13.7] - 2022-10-29 diff --git a/README.md b/README.md index 83c20ff4d..559d54bb3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ _formerly pyo3-pack_ [![Maturin User Guide](https://img.shields.io/badge/user-guide-brightgreen?logo=readthedocs&style=flat-square)](https://maturin.rs) [![Chat on Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?logo=gitter&style=flat-square)](https://gitter.im/PyO3/Lobby) -Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages. +Build and publish crates with pyo3, rust-cpython, cffi and uniffi bindings as well as rust binaries as python packages. This project is meant as a zero configuration replacement for [setuptools-rust](https://github.com/PyO3/setuptools-rust) and [milksnake](https://github.com/getsentry/milksnake). It supports building wheels for python 3.5+ on windows, linux, mac and freebsd, can upload them to [pypi](https://pypi.org/) and has basic pypy support. diff --git a/src/build_context.rs b/src/build_context.rs index 1a9bec9dc..5b0e39f80 100644 --- a/src/build_context.rs +++ b/src/build_context.rs @@ -4,7 +4,7 @@ use crate::build_options::CargoOptions; use crate::compile::warn_missing_py_init; use crate::module_writer::{ add_data, write_bin, write_bindings_module, write_cffi_module, write_python_part, - write_wasm_launcher, WheelWriter, + write_uniffi_module, write_wasm_launcher, WheelWriter, }; use crate::project_layout::ProjectLayout; use crate::python_interpreter::InterpreterKind; @@ -29,8 +29,6 @@ use std::path::{Path, PathBuf}; /// The way the rust code is used in the wheel #[derive(Clone, Debug, PartialEq, Eq)] pub enum BridgeModel { - /// A native module with c bindings, i.e. `#[no_mangle] extern "C" ` - Cffi, /// A rust binary to be shipped a python package /// The String is the name of the bindings /// providing crate, e.g. pyo3, the number is the minimum minor python version @@ -42,6 +40,10 @@ pub enum BridgeModel { /// for all cpython versions (pypy still needs multiple versions). /// The numbers are the minimum major and minor version BindingsAbi3(u8, u8), + /// A native module with c bindings, i.e. `#[no_mangle] extern "C" ` + Cffi, + /// A native module generated from uniffi + UniFfi, } impl BridgeModel { @@ -71,11 +73,12 @@ impl BridgeModel { impl Display for BridgeModel { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - BridgeModel::Cffi => write!(f, "cffi"), BridgeModel::Bin(Some((name, _))) => write!(f, "{} bin", name), BridgeModel::Bin(None) => write!(f, "bin"), BridgeModel::Bindings(name, _) => write!(f, "{}", name), BridgeModel::BindingsAbi3(..) => write!(f, "pyo3"), + BridgeModel::Cffi => write!(f, "cffi"), + BridgeModel::UniFfi => write!(f, "uniffi"), } } } @@ -199,7 +202,6 @@ impl BuildContext { .context("Failed to create the target directory for the wheels")?; let wheels = match &self.bridge { - BridgeModel::Cffi => self.build_cffi_wheel()?, BridgeModel::Bin(None) => self.build_bin_wheel(None)?, BridgeModel::Bin(Some(..)) => self.build_bin_wheels(&self.interpreter)?, BridgeModel::Bindings(..) => self.build_binding_wheels(&self.interpreter)?, @@ -240,6 +242,8 @@ impl BuildContext { } built_wheels } + BridgeModel::Cffi => self.build_cffi_wheel()?, + BridgeModel::UniFfi => self.build_uniffi_wheel()?, }; Ok(wheels) @@ -751,6 +755,61 @@ impl BuildContext { Ok(wheels) } + fn write_uniffi_wheel( + &self, + artifact: BuildArtifact, + platform_tags: &[PlatformTag], + ext_libs: Vec, + ) -> Result { + let (tag, tags) = self + .target + .get_universal_tags(platform_tags, self.universal2)?; + + let mut writer = WheelWriter::new( + &tag, + &self.out, + &self.metadata21, + &tags, + self.excludes(Format::Wheel)?, + )?; + self.add_external_libs(&mut writer, &[&artifact], &[ext_libs])?; + + write_uniffi_module( + &mut writer, + &self.project_layout, + self.manifest_path.parent().unwrap(), + &self.target_dir, + &self.module_name, + &artifact.path, + self.target.target_os(), + self.editable, + self.pyproject_toml.as_ref(), + )?; + + self.add_pth(&mut writer)?; + add_data(&mut writer, self.project_layout.data.as_deref())?; + let wheel_path = writer.finish()?; + Ok((wheel_path, "py3".to_string())) + } + + /// Builds a wheel with uniffi bindings + pub fn build_uniffi_wheel(&self) -> Result> { + let mut wheels = Vec::new(); + let artifact = self.compile_cdylib(None, None)?; + let (policy, external_libs) = self.auditwheel(&artifact, &self.platform_tag, None)?; + let platform_tags = if self.platform_tag.is_empty() { + vec![policy.platform_tag()] + } else { + self.platform_tag.clone() + }; + let (wheel_path, tag) = self.write_uniffi_wheel(artifact, &platform_tags, external_libs)?; + + println!("📦 Built wheel to {}", wheel_path.display()); + wheels.push((wheel_path, tag)); + + Ok(wheels) + } + fn write_bin_wheel( &self, python_interpreter: Option<&PythonInterpreter>, diff --git a/src/build_options.rs b/src/build_options.rs index c6836a1e7..1faccafa3 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -162,7 +162,7 @@ pub struct BuildOptions { pub find_interpreter: bool, /// Which kind of bindings to use. - #[arg(short, long, value_parser = ["pyo3", "pyo3-ffi", "rust-cpython", "cffi", "bin"])] + #[arg(short, long, value_parser = ["pyo3", "pyo3-ffi", "rust-cpython", "cffi", "uniffi", "bin"])] pub bindings: Option, /// The directory to store the built wheels in. Defaults to a new "wheels" @@ -347,7 +347,7 @@ impl BuildOptions { println!("🐍 Using {} to generate the cffi bindings", interpreter); Ok(vec![interpreter]) } - BridgeModel::Bin(None) => Ok(vec![]), + BridgeModel::Bin(None) | BridgeModel::UniFfi => Ok(vec![]), BridgeModel::BindingsAbi3(major, minor) => { if target.is_windows() { // Ideally, we wouldn't want to use any python interpreter without abi3 at all. @@ -838,6 +838,8 @@ fn find_bindings( Some(("pyo3-ffi".to_string(), minor)) } else if deps.contains_key("cpython") { Some(("rust-cpython".to_string(), MINIMUM_PYTHON_MINOR)) + } else if deps.contains_key("uniffi") { + Some(("uniffi".to_string(), MINIMUM_PYTHON_MINOR)) } else { None } @@ -860,7 +862,7 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result
) -> Result
) -> Result
{ cargo_rustc.bin.push(binding_target.name.clone()); } - BridgeModel::Cffi | BridgeModel::Bindings(..) | BridgeModel::BindingsAbi3(..) => { + BridgeModel::Cffi + | BridgeModel::UniFfi + | BridgeModel::Bindings(..) + | BridgeModel::BindingsAbi3(..) => { cargo_rustc.lib = true; // https://github.com/rust-lang/rust/issues/59302#issue-422994250 // We must only do this for libraries as it breaks binaries diff --git a/src/main.rs b/src/main.rs index 086654d69..d40d11ed6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,8 +72,13 @@ enum Opt { /// /// Note that this command doesn't create entrypoints Develop { - /// Which kind of bindings to use. Possible values are pyo3, rust-cpython, cffi and bin - #[arg(short = 'b', long = "bindings", alias = "binding-crate")] + /// Which kind of bindings to use + #[arg( + short = 'b', + long = "bindings", + alias = "binding-crate", + value_parser = ["pyo3", "pyo3-ffi", "rust-cpython", "cffi", "uniffi", "bin"] + )] bindings: Option, /// Pass --release to cargo #[arg(short = 'r', long)] @@ -258,7 +263,7 @@ fn pep517(subcommand: Pep517Command) -> Result<()> { .get_platform_tag(&[PlatformTag::Linux], context.universal2)?; vec![format!("cp{}{}-abi3-{}", major, minor, platform)] } - BridgeModel::Bin(None) | BridgeModel::Cffi => { + BridgeModel::Bin(None) | BridgeModel::Cffi | BridgeModel::UniFfi => { context .target .get_universal_tags(&[PlatformTag::Linux], context.universal2)? diff --git a/src/module_writer.rs b/src/module_writer.rs index 91a2ec14a..15dc5faed 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -1,5 +1,6 @@ //! The wheel format is (mostly) specified in PEP 427 use crate::project_layout::ProjectLayout; +use crate::target::Os; use crate::{ pyproject_toml::Format, BridgeModel, Metadata21, PyProjectToml, PythonInterpreter, Target, }; @@ -812,6 +813,120 @@ pub fn write_cffi_module( Ok(()) } +fn generate_uniffi_bindings(crate_dir: &Path, target_dir: &Path) -> Result { + let binding_dir = target_dir.join("maturin").join("uniffi"); + fs::create_dir_all(&binding_dir)?; + + let pattern = crate_dir.join("src").join("*.udl"); + let udls = glob::glob(pattern.to_str().unwrap())? + .map(|p| p.unwrap()) + .collect::>(); + if udls.is_empty() { + bail!("No UDL files found in {}", crate_dir.join("src").display()); + } else if udls.len() > 1 { + bail!( + "Multiple UDL files found in {}", + crate_dir.join("src").display() + ); + } + + let udl = &udls[0]; + uniffi_bindgen::generate_bindings( + udl.as_path().try_into().expect("path contains non-utf8"), + None, + vec!["python"], + Some( + binding_dir + .as_path() + .try_into() + .expect("path contains non-utf8"), + ), + None, + false, + )?; + let py_binding_name = udl.file_stem().unwrap(); + let py_binding = binding_dir.join(py_binding_name).with_extension("py"); + Ok(py_binding) +} + +/// Creates the uniffi module with the shared library +#[allow(clippy::too_many_arguments)] +pub fn write_uniffi_module( + writer: &mut impl ModuleWriter, + project_layout: &ProjectLayout, + crate_dir: &Path, + target_dir: &Path, + module_name: &str, + artifact: &Path, + target_os: Os, + editable: bool, + pyproject_toml: Option<&PyProjectToml>, +) -> Result<()> { + let uniffi_binding = generate_uniffi_bindings(crate_dir, target_dir)?; + let binding_name = uniffi_binding.file_stem().unwrap().to_str().unwrap(); + let py_init = format!("from .{} import * # NOQA\n", binding_name); + // uniffi bindings hardcoded the extension filenames + let dylib_name = match target_os { + Os::Macos => format!("libuniffi_{}.dylib", binding_name), + Os::Windows => format!("uniffi_{}.dll", binding_name), + _ => format!("libuniffi_{}.so", binding_name), + }; + + let module; + + if let Some(python_module) = &project_layout.python_module { + if !editable { + write_python_part(writer, python_module, pyproject_toml) + .context("Failed to add the python module to the package")?; + } + + if editable { + let target = python_module.join(&dylib_name); + fs::copy(artifact, &target).context(format!( + "Failed to copy {} to {}", + artifact.display(), + target.display() + ))?; + + let target = python_module.join(binding_name).with_extension("py"); + fs::copy(&uniffi_binding, &target).context(format!( + "Failed to copy {} to {}", + uniffi_binding.display(), + target.display() + ))?; + } + + let relative = project_layout + .rust_module + .strip_prefix(python_module.parent().unwrap()) + .unwrap(); + module = relative.join(&project_layout.extension_name); + if !editable { + writer.add_directory(&module)?; + } + } else { + module = PathBuf::from(module_name); + writer.add_directory(&module)?; + writer.add_bytes(&module.join("__init__.py"), py_init.as_bytes())?; + let type_stub = project_layout + .rust_module + .join(format!("{}.pyi", module_name)); + if type_stub.exists() { + println!("📖 Found type stub file at {}.pyi", module_name); + writer.add_file(&module.join("__init__.pyi"), type_stub)?; + writer.add_bytes(&module.join("py.typed"), b"")?; + } + }; + + if !editable || project_layout.python_module.is_none() { + let target = module.join(binding_name).with_extension("py"); + writer.add_file(&target, uniffi_binding)?; + writer.add_file_with_permissions(&module.join(dylib_name), artifact, 0o755)?; + } + + Ok(()) +} + /// Adds a data directory with a scripts directory with the binary inside it pub fn write_bin( writer: &mut impl ModuleWriter, diff --git a/test-crates/uniffi-mixed/.gitignore b/test-crates/uniffi-mixed/.gitignore new file mode 100644 index 000000000..0ada524f5 --- /dev/null +++ b/test-crates/uniffi-mixed/.gitignore @@ -0,0 +1,4 @@ +uniffi_mixed/math.py +uniffi_mixed/*.dylib +uniffi_mixed/*.dll +uniffi_mixed/*.so diff --git a/test-crates/uniffi-mixed/Cargo.lock b/test-crates/uniffi-mixed/Cargo.lock new file mode 100644 index 000000000..7f2aed843 --- /dev/null +++ b/test-crates/uniffi-mixed/Cargo.lock @@ -0,0 +1,603 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + +[[package]] +name = "askama" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139" +dependencies = [ + "askama_derive", + "askama_escape", + "askama_shared", +] + +[[package]] +name = "askama_derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71" +dependencies = [ + "askama_shared", + "proc-macro2", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_shared" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0" +dependencies = [ + "askama_escape", + "mime", + "mime_guess", + "nom", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + +[[package]] +name = "camino" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "fs-err" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541" + +[[package]] +name = "goblin" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7666983ed0dd8d21a6f6576ee00053ca0926fb281a5522577a4dbd0f1b54143" +dependencies = [ + "log", + "plain", + "scroll", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "os_str_bytes" +version = "6.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" + +[[package]] +name = "paste" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "scroll" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdbda6ac5cd1321e724fa9cee216f3a61885889b896f073b8f82322789c5250e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "semver" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +dependencies = [ + "serde", +] + +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "uniffi" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f54af5ada67d1173457a99a7bb44a7917f63e7466764cb4714865c7a6678b830" +dependencies = [ + "anyhow", + "bytes", + "camino", + "cargo_metadata", + "log", + "once_cell", + "paste", + "static_assertions", + "uniffi_macros", +] + +[[package]] +name = "uniffi-mixed" +version = "0.1.0" +dependencies = [ + "uniffi", + "uniffi_build", + "uniffi_macros", +] + +[[package]] +name = "uniffi_bindgen" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cc4af3c0180c7e86c4a3acf2b6587af04ba2567b1e948993df10f421796621" +dependencies = [ + "anyhow", + "askama", + "bincode", + "camino", + "clap", + "fs-err", + "goblin", + "heck", + "once_cell", + "paste", + "serde", + "serde_json", + "toml", + "uniffi_meta", + "weedle2", +] + +[[package]] +name = "uniffi_build" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "510287c368a9386eb731ebe824a6fc6c82a105e20d020af1aa20519c1c1561db" +dependencies = [ + "anyhow", + "camino", + "uniffi_bindgen", +] + +[[package]] +name = "uniffi_macros" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8604503caa2cbcf271578dc51ca236d40e3b22e1514ffa2e638e2c39f6ad10" +dependencies = [ + "bincode", + "camino", + "fs-err", + "once_cell", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", + "uniffi_build", + "uniffi_meta", +] + +[[package]] +name = "uniffi_meta" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9417cc653937681436b93838d8c5f97a5b8c58697813982ee8810bd1dc3b57" +dependencies = [ + "serde", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "weedle2" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e79c5206e1f43a2306fd64bdb95025ee4228960f2e6c5a8b173f3caaf807741" +dependencies = [ + "nom", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/test-crates/uniffi-mixed/Cargo.toml b/test-crates/uniffi-mixed/Cargo.toml new file mode 100644 index 000000000..92e9f6ee7 --- /dev/null +++ b/test-crates/uniffi-mixed/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "uniffi-mixed" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "uniffi_mixed" +crate-type = ["cdylib"] + +[dependencies] +uniffi = "0.21.0" +uniffi_macros = "0.21.0" + +[build-dependencies] +uniffi_build = { version = "0.21.0", features = ["builtin-bindgen"] } diff --git a/test-crates/uniffi-mixed/build.rs b/test-crates/uniffi-mixed/build.rs new file mode 100644 index 000000000..3fa862624 --- /dev/null +++ b/test-crates/uniffi-mixed/build.rs @@ -0,0 +1,3 @@ +fn main() { + uniffi_build::generate_scaffolding("./src/math.udl").unwrap(); +} diff --git a/test-crates/uniffi-mixed/check_installed/check_installed.py b/test-crates/uniffi-mixed/check_installed/check_installed.py new file mode 100644 index 000000000..4c0e558ea --- /dev/null +++ b/test-crates/uniffi-mixed/check_installed/check_installed.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import uniffi_mixed + +assert uniffi_mixed.add(1, 2) == 3 + +print("SUCCESS") diff --git a/test-crates/uniffi-mixed/pyproject.toml b/test-crates/uniffi-mixed/pyproject.toml new file mode 100644 index 000000000..7824761af --- /dev/null +++ b/test-crates/uniffi-mixed/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["maturin>=0.13,<0.14"] +build-backend = "maturin" \ No newline at end of file diff --git a/test-crates/uniffi-mixed/src/lib.rs b/test-crates/uniffi-mixed/src/lib.rs new file mode 100644 index 000000000..c379ab39c --- /dev/null +++ b/test-crates/uniffi-mixed/src/lib.rs @@ -0,0 +1,5 @@ +fn add(a: u32, b: u32) -> u32 { + a + b +} + +uniffi_macros::include_scaffolding!("math"); diff --git a/test-crates/uniffi-mixed/src/math.udl b/test-crates/uniffi-mixed/src/math.udl new file mode 100644 index 000000000..b0359a10b --- /dev/null +++ b/test-crates/uniffi-mixed/src/math.udl @@ -0,0 +1,3 @@ +namespace math { + u32 add(u32 a, u32 b); +}; diff --git a/test-crates/uniffi-mixed/test_uniffi_mixed.py b/test-crates/uniffi-mixed/test_uniffi_mixed.py new file mode 100644 index 000000000..94f8843aa --- /dev/null +++ b/test-crates/uniffi-mixed/test_uniffi_mixed.py @@ -0,0 +1,5 @@ +import uniffi_mixed + + +def test_add(): + assert uniffi_mixed.add(1, 2) == 3 diff --git a/test-crates/uniffi-mixed/uniffi_mixed/__init__.py b/test-crates/uniffi-mixed/uniffi_mixed/__init__.py new file mode 100644 index 000000000..513bf0250 --- /dev/null +++ b/test-crates/uniffi-mixed/uniffi_mixed/__init__.py @@ -0,0 +1 @@ +from .math import * # NOQA diff --git a/test-crates/uniffi-pure/Cargo.lock b/test-crates/uniffi-pure/Cargo.lock new file mode 100644 index 000000000..d83e2ff41 --- /dev/null +++ b/test-crates/uniffi-pure/Cargo.lock @@ -0,0 +1,603 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + +[[package]] +name = "askama" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139" +dependencies = [ + "askama_derive", + "askama_escape", + "askama_shared", +] + +[[package]] +name = "askama_derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71" +dependencies = [ + "askama_shared", + "proc-macro2", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_shared" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0" +dependencies = [ + "askama_escape", + "mime", + "mime_guess", + "nom", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + +[[package]] +name = "camino" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "fs-err" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541" + +[[package]] +name = "goblin" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7666983ed0dd8d21a6f6576ee00053ca0926fb281a5522577a4dbd0f1b54143" +dependencies = [ + "log", + "plain", + "scroll", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "os_str_bytes" +version = "6.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" + +[[package]] +name = "paste" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "scroll" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdbda6ac5cd1321e724fa9cee216f3a61885889b896f073b8f82322789c5250e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "semver" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +dependencies = [ + "serde", +] + +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "uniffi" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f54af5ada67d1173457a99a7bb44a7917f63e7466764cb4714865c7a6678b830" +dependencies = [ + "anyhow", + "bytes", + "camino", + "cargo_metadata", + "log", + "once_cell", + "paste", + "static_assertions", + "uniffi_macros", +] + +[[package]] +name = "uniffi-pure" +version = "0.1.0" +dependencies = [ + "uniffi", + "uniffi_build", + "uniffi_macros", +] + +[[package]] +name = "uniffi_bindgen" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cc4af3c0180c7e86c4a3acf2b6587af04ba2567b1e948993df10f421796621" +dependencies = [ + "anyhow", + "askama", + "bincode", + "camino", + "clap", + "fs-err", + "goblin", + "heck", + "once_cell", + "paste", + "serde", + "serde_json", + "toml", + "uniffi_meta", + "weedle2", +] + +[[package]] +name = "uniffi_build" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "510287c368a9386eb731ebe824a6fc6c82a105e20d020af1aa20519c1c1561db" +dependencies = [ + "anyhow", + "camino", + "uniffi_bindgen", +] + +[[package]] +name = "uniffi_macros" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8604503caa2cbcf271578dc51ca236d40e3b22e1514ffa2e638e2c39f6ad10" +dependencies = [ + "bincode", + "camino", + "fs-err", + "once_cell", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", + "uniffi_build", + "uniffi_meta", +] + +[[package]] +name = "uniffi_meta" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9417cc653937681436b93838d8c5f97a5b8c58697813982ee8810bd1dc3b57" +dependencies = [ + "serde", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "weedle2" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e79c5206e1f43a2306fd64bdb95025ee4228960f2e6c5a8b173f3caaf807741" +dependencies = [ + "nom", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/test-crates/uniffi-pure/Cargo.toml b/test-crates/uniffi-pure/Cargo.toml new file mode 100644 index 000000000..2f63d5597 --- /dev/null +++ b/test-crates/uniffi-pure/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "uniffi-pure" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "uniffi_pure" +crate-type = ["cdylib"] + +[dependencies] +uniffi = "0.21.0" +uniffi_macros = "0.21.0" + +[build-dependencies] +uniffi_build = { version = "0.21.0", features = ["builtin-bindgen"] } \ No newline at end of file diff --git a/test-crates/uniffi-pure/build.rs b/test-crates/uniffi-pure/build.rs new file mode 100644 index 000000000..3fa862624 --- /dev/null +++ b/test-crates/uniffi-pure/build.rs @@ -0,0 +1,3 @@ +fn main() { + uniffi_build::generate_scaffolding("./src/math.udl").unwrap(); +} diff --git a/test-crates/uniffi-pure/check_installed/check_installed.py b/test-crates/uniffi-pure/check_installed/check_installed.py new file mode 100644 index 000000000..c71c9ad3f --- /dev/null +++ b/test-crates/uniffi-pure/check_installed/check_installed.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import uniffi_pure + +assert uniffi_pure.add(1, 2) == 3 + +print("SUCCESS") diff --git a/test-crates/uniffi-pure/pyproject.toml b/test-crates/uniffi-pure/pyproject.toml new file mode 100644 index 000000000..7824761af --- /dev/null +++ b/test-crates/uniffi-pure/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["maturin>=0.13,<0.14"] +build-backend = "maturin" \ No newline at end of file diff --git a/test-crates/uniffi-pure/src/lib.rs b/test-crates/uniffi-pure/src/lib.rs new file mode 100644 index 000000000..c379ab39c --- /dev/null +++ b/test-crates/uniffi-pure/src/lib.rs @@ -0,0 +1,5 @@ +fn add(a: u32, b: u32) -> u32 { + a + b +} + +uniffi_macros::include_scaffolding!("math"); diff --git a/test-crates/uniffi-pure/src/math.udl b/test-crates/uniffi-pure/src/math.udl new file mode 100644 index 000000000..b0359a10b --- /dev/null +++ b/test-crates/uniffi-pure/src/math.udl @@ -0,0 +1,3 @@ +namespace math { + u32 add(u32 a, u32 b); +}; diff --git a/test-crates/uniffi-pure/test_uniffi_pure.py b/test-crates/uniffi-pure/test_uniffi_pure.py new file mode 100644 index 000000000..a899f06e6 --- /dev/null +++ b/test-crates/uniffi-pure/test_uniffi_pure.py @@ -0,0 +1,5 @@ +import uniffi_pure + + +def test_add(): + assert uniffi_pure.add(1, 2) == 3 diff --git a/tests/cmd/build.stdout b/tests/cmd/build.stdout index 1dcee50c6..64baecfeb 100644 --- a/tests/cmd/build.stdout +++ b/tests/cmd/build.stdout @@ -39,7 +39,7 @@ Options: -b, --bindings Which kind of bindings to use - [possible values: pyo3, pyo3-ffi, rust-cpython, cffi, bin] + [possible values: pyo3, pyo3-ffi, rust-cpython, cffi, uniffi, bin] -o, --out The directory to store the built wheels in. Defaults to a new "wheels" directory in the diff --git a/tests/cmd/develop.stdout b/tests/cmd/develop.stdout index fed40fc95..963588bc7 100644 --- a/tests/cmd/develop.stdout +++ b/tests/cmd/develop.stdout @@ -10,7 +10,9 @@ Arguments: Options: -b, --bindings - Which kind of bindings to use. Possible values are pyo3, rust-cpython, cffi and bin + Which kind of bindings to use + + [possible values: pyo3, pyo3-ffi, rust-cpython, cffi, uniffi, bin] -r, --release Pass --release to cargo diff --git a/tests/cmd/publish.stdout b/tests/cmd/publish.stdout index f8f9d78d2..1e5ff873c 100644 --- a/tests/cmd/publish.stdout +++ b/tests/cmd/publish.stdout @@ -73,7 +73,7 @@ Options: -b, --bindings Which kind of bindings to use - [possible values: pyo3, pyo3-ffi, rust-cpython, cffi, bin] + [possible values: pyo3, pyo3-ffi, rust-cpython, cffi, uniffi, bin] -o, --out The directory to store the built wheels in. Defaults to a new "wheels" directory in the diff --git a/tests/run.rs b/tests/run.rs index 6a021565d..1876246ab 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -103,6 +103,26 @@ fn develop_cffi_mixed() { )); } +#[test] +fn develop_uniffi_pure() { + handle_result(develop::test_develop( + "test-crates/uniffi-pure", + None, + "develop-uniffi-pure", + false, + )); +} + +#[test] +fn develop_uniffi_mixed() { + handle_result(develop::test_develop( + "test-crates/uniffi-mixed", + None, + "develop-uniffi-mixed", + false, + )); +} + #[test] fn develop_hello_world() { handle_result(develop::test_develop( @@ -244,6 +264,28 @@ fn integration_cffi_mixed() { )); } +#[test] +fn integration_uniffi_pure() { + handle_result(integration::test_integration( + "test-crates/uniffi-pure", + None, + "integration-uniffi-pure", + false, + None, + )); +} + +#[test] +fn integration_uniffi_mixed() { + handle_result(integration::test_integration( + "test-crates/uniffi-mixed", + None, + "integration-uniffi-mixed", + false, + None, + )); +} + #[test] fn integration_hello_world() { handle_result(integration::test_integration(