Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the bindings into a new uniffi_bindings crate. #2296

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,122 changes: 475 additions & 647 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"uniffi_bindgen",
"uniffi_bindings",
"uniffi_build",
"uniffi_core",
"uniffi_macros",
Expand Down Expand Up @@ -67,7 +68,7 @@ members = [
"fixtures/type-limits",
"fixtures/large-enum",
"fixtures/large-error",
"fixtures/enum-types",
"fixtures/enum-types", "uniffi_bindings",
]

resolver = "2"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ criterion = "0.5.1"
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }

[dev-dependencies]
uniffi_bindgen = {path = "../../uniffi_bindgen", features = ["bindgen-tests"]}
#[dev-dependencies]
#uniffi_bindings = {path = "../../uniffi_bindings", features = ["bindgen-tests"]}

[[bench]]
name = "benchmarks"
Expand Down
1 change: 1 addition & 0 deletions fixtures/docstring-proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ uniffi = { path = "../../uniffi", features = ["build"] }
glob = "0.3"
uniffi = { path = "../../uniffi", features = ["bindgen-tests"] }
uniffi_bindgen = { path = "../../uniffi_bindgen" }
uniffi_bindings = { path = "../../uniffi_bindings" }
uniffi_testing = { path = "../../uniffi_testing" }

[features]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ uniffi::build_foreign_language_testcases!(

#[cfg(test)]
mod tests {
use uniffi_bindgen::{bindings::*, BindingGenerator};
use uniffi_bindgen::BindingGenerator;
use uniffi_bindings::*;
use uniffi_testing::UniFFITestHelper;

const DOCSTRINGS: &[&str] = &[
Expand Down
1 change: 1 addition & 0 deletions fixtures/docstring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ camino = "1.0.8"
glob = "0.3"
uniffi = { path = "../../uniffi", features = ["bindgen-tests"] }
uniffi_bindgen = { path = "../../uniffi_bindgen" }
uniffi_bindings = { path = "../../uniffi_bindings" }
uniffi_testing = { path = "../../uniffi_testing" }

[features]
Expand Down
3 changes: 2 additions & 1 deletion fixtures/docstring/tests/test_generated_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ uniffi::build_foreign_language_testcases!(
#[cfg(test)]
mod tests {
use camino::Utf8PathBuf;
use uniffi_bindgen::{bindings::*, BindingGenerator};
use uniffi_bindgen::BindingGenerator;
use uniffi_bindings::*;
use uniffi_testing::UniFFITestHelper;

const DOCSTRINGS: &[&str] = &[
Expand Down
4 changes: 4 additions & 0 deletions move-bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rm -rf uniffi_bindings/src
mv uniffi_bindgen/src/bindings uniffi_bindings/src
mv uniffi_bindings/src/mod.rs uniffi_bindings/src/lib.rs
mv uniffi_bindgen/src/backend uniffi_bindings/src/backend
9 changes: 5 additions & 4 deletions uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ readme = "../README.md"

[dependencies]
uniffi_bindgen = { path = "../uniffi_bindgen", version = "=0.28.2", optional = true }
uniffi_bindings = { path = "../uniffi_bindings", version = "=0.28.2", optional = true }
uniffi_build = { path = "../uniffi_build", version = "=0.28.2", optional = true }
uniffi_core = { path = "../uniffi_core", version = "=0.28.2" }
uniffi_macros = { path = "../uniffi_macros", version = "=0.28.2" }
Expand All @@ -29,21 +30,21 @@ trybuild = "1"
[features]
default = ["cargo-metadata"]
# Printout tracing information on FFI calls. Useful for debugging issues with the bindings code.
ffi-trace = ["uniffi_core/ffi-trace", "uniffi_bindgen/ffi-trace"]
ffi-trace = ["uniffi_core/ffi-trace", "uniffi_bindings/ffi-trace"]
# Support for features needed by the `build.rs` script. Enable this in your
# `build-dependencies`.
build = [ "dep:uniffi_build" ]
# Support for `uniffi_bindgen::{generate_bindings, generate_component_scaffolding}`.
# Enable this feature for your `uniffi-bindgen` binaries if you don't need the full CLI.
bindgen = ["dep:uniffi_bindgen"]
cargo-metadata = ["dep:cargo_metadata", "uniffi_bindgen?/cargo-metadata"]
bindgen = ["dep:uniffi_bindgen", "dep:uniffi_bindings"]
cargo-metadata = ["dep:cargo_metadata", "uniffi_bindgen?/cargo-metadata", "uniffi_bindings?/cargo-metadata"]

# Support for `uniffi_bindgen_main()`. Enable this feature for your
# `uniffi-bindgen` binaries.
cli = [ "bindgen", "dep:clap", "dep:camino" ]
# Support for running example/fixture tests for `uniffi-bindgen`. You probably
# don't need to enable this.
bindgen-tests = [ "dep:uniffi_bindgen", "uniffi_bindgen/bindgen-tests" ]
bindgen-tests = [ "dep:uniffi_bindings", "uniffi_bindings/bindgen-tests" ]
# Enable support for Tokio's futures.
# This must still be opted into on a per-function basis using `#[uniffi::export(async_runtime = "tokio")]`.
tokio = ["uniffi_core/tokio"]
Expand Down
2 changes: 1 addition & 1 deletion uniffi/src/cli/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::Result;
use camino::Utf8PathBuf;
use clap::{Args, Parser};

use uniffi_bindgen::bindings::{generate_swift_bindings, SwiftBindingsOptions};
use uniffi_bindings::{generate_swift_bindings, SwiftBindingsOptions};

#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
Expand Down
2 changes: 1 addition & 1 deletion uniffi/src/cli/uniffi_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::{bail, Context, Result};
use camino::Utf8PathBuf;
use clap::{Parser, Subcommand};
use std::fmt;
use uniffi_bindgen::bindings::*;
use uniffi_bindings::*;

/// Enumeration of all foreign language targets currently supported by our CLI.
///
Expand Down
9 changes: 5 additions & 4 deletions uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ pub use uniffi_macros::*;
#[cfg(feature = "cli")]
mod cli;
#[cfg(feature = "bindgen-tests")]
pub use uniffi_bindgen::bindings::{kotlin_test, python_test, ruby_test, swift_test};
pub use uniffi_bindings::{kotlin_test, python_test, ruby_test, swift_test};

#[cfg(all(feature = "cargo-metadata", feature = "bindgen"))]
pub use uniffi_bindgen::cargo_metadata::CrateConfigSupplier as CargoMetadataConfigSupplier;
#[cfg(feature = "bindgen")]
pub use uniffi_bindgen::library_mode::generate_bindings as generate_bindings_library_mode;
#[cfg(feature = "bindgen")]
pub use uniffi_bindgen::{
bindings::{
KotlinBindingGenerator, PythonBindingGenerator, RubyBindingGenerator, SwiftBindingGenerator,
},
generate_bindings, generate_component_scaffolding, generate_component_scaffolding_for_crate,
print_repr,
};
#[cfg(feature = "bindgen")]
pub use uniffi_bindings::{
KotlinBindingGenerator, PythonBindingGenerator, RubyBindingGenerator, SwiftBindingGenerator,
};
#[cfg(feature = "build")]
pub use uniffi_build::{generate_scaffolding, generate_scaffolding_for_crate};
#[cfg(feature = "bindgen-tests")]
Expand Down
8 changes: 0 additions & 8 deletions uniffi_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,17 @@ readme = "../README.md"
[features]
default = ["cargo-metadata"]
cargo-metadata = ["dep:cargo_metadata"]
bindgen-tests = ["cargo-metadata", "dep:uniffi_testing"]
ffi-trace = ["uniffi_testing?/ffi-trace"]

[dependencies]
anyhow = "1"
rinja = { version = "0.3", default-features = false, features = ["config"] }
camino = "1.0.8"
cargo_metadata = { version = "0.15", optional = true }
fs-err = "2.7.0"
glob = "0.3"
goblin = "0.8"
heck = "0.5"
once_cell = "1.12"
paste = "1.0"
serde = { version = "1", features = ["derive"] }
toml = "0.5"
uniffi_meta = { path = "../uniffi_meta", version = "=0.28.2" }
uniffi_testing = { path = "../uniffi_testing", version = "=0.28.2", optional = true }
uniffi_udl = { path = "../uniffi_udl", version = "=0.28.2" }
# Don't include the `unicode-linebreak` or `unicode-width` since that functionality isn't needed for
# docstrings.
textwrap = { version = "0.16", features=["smawk"], default-features = false }
17 changes: 1 addition & 16 deletions uniffi_bindgen/rinja.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
[general]
# Directories to search for templates, relative to the crate root.
dirs = [ "src/scaffolding/templates", "src/bindings/kotlin/templates", "src/bindings/python/templates", "src/bindings/swift/templates", "src/bindings/ruby/templates" ]

[[syntax]]
name = "kt"

[[syntax]]
name = "py"

[[syntax]]
name = "swift"

[[syntax]]
name = "c"
dirs = [ "src/scaffolding/templates" ]

[[syntax]]
name = "rs"

[[syntax]]
name = "rb"
33 changes: 0 additions & 33 deletions uniffi_bindgen/src/bindings/kotlin/gen_kotlin/variant.rs

This file was deleted.

2 changes: 0 additions & 2 deletions uniffi_bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ use std::io::prelude::*;
use std::io::ErrorKind;
use std::process::Command;

pub mod backend;
pub mod bindings;
pub mod interface;
pub mod library_mode;
pub mod macro_metadata;
Expand Down
38 changes: 38 additions & 0 deletions uniffi_bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "uniffi_bindings"
description = "The builtin Kotlin/Python/Ruby/Swift bindings for UniFII"
documentation = "https://mozilla.github.io/uniffi-rs"
homepage = "https://mozilla.github.io/uniffi-rs"
repository = "https://github.com/mozilla/uniffi-rs"
version = "0.28.2"
license = "MPL-2.0"
edition = "2021"

[features]
default=["bindgen-tests", "kotlin", "python", "ruby", "swift"]
bindgen-tests = ["cargo-metadata", "dep:uniffi_testing"]
cargo-metadata = ["dep:cargo_metadata"]
ffi-trace = ["uniffi_testing?/ffi-trace"]
kotlin = []
python = []
ruby = []
swift = []

[dependencies]
anyhow = "1"
rinja = { version = "0.3", default-features = false, features = ["config"] }
camino = "1.0.8"
cargo_metadata = { version = "0.15", optional = true }
fs-err = "2.7.0"
glob = "0.3"
heck = "0.5"
once_cell = "1.12"
paste = "1.0"
serde = { version = "1", features = ["derive"] }
toml = "0.5"
# Don't include the `unicode-linebreak` or `unicode-width` since that functionality isn't needed for
# docstrings.
textwrap = { version = "0.16", features=["smawk"], default-features = false }
uniffi_bindgen = { path = "../uniffi_bindgen", version = "=0.28.2" }
uniffi_meta = { path = "../uniffi_meta", version = "=0.28.2" }
uniffi_testing = { path = "../uniffi_testing", version = "=0.28.2", optional = true }
18 changes: 18 additions & 0 deletions uniffi_bindings/rinja.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[general]
# Directories to search for templates, relative to the crate root.
dirs = [ "src/kotlin/templates", "src/python/templates", "src/swift/templates", "src/ruby/templates" ]

[[syntax]]
name = "c"

[[syntax]]
name = "kt"

[[syntax]]
name = "py"

[[syntax]]
name = "swift"

[[syntax]]
name = "rb"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

//! Backend-agnostic rinja filters

use crate::interface::{
AsType, CallbackInterface, ComponentInterface, Enum, FfiType, Function, Object, Record,
use uniffi_bindgen::interface::{
AsType, CallbackInterface, ComponentInterface, Enum, FfiType, Object, Record,
};
use rinja::Result;
use std::fmt;
Expand Down Expand Up @@ -49,12 +49,6 @@ pub fn get_record_definition<'a>(ci: &'a ComponentInterface, name: &str) -> Resu
.ok_or_else(|| lookup_error!("record {name} not found"))
}

/// Get a Function definition by name
pub fn get_function_definition<'a>(ci: &'a ComponentInterface, name: &str) -> Result<&'a Function> {
ci.get_function_definition(name)
.ok_or_else(|| lookup_error!("function {name} not found"))
}

/// Get an Object definition by name
pub fn get_object_definition<'a>(ci: &'a ComponentInterface, name: &str) -> Result<&'a Object> {
ci.get_object_definition(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
mod config;
pub mod filters;

pub use crate::interface::{Literal, Type};
pub use uniffi_bindgen::interface::{Literal, Type};
pub use config::TemplateExpression;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::CodeType;
use crate::ComponentInterface;
use uniffi_bindgen::ComponentInterface;

#[derive(Debug)]
pub struct CallbackInterfaceCodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::{AsCodeType, CodeType};
use crate::backend::{Literal, Type};
use crate::ComponentInterface;
use uniffi_bindgen::ComponentInterface;

#[derive(Debug)]
pub struct OptionalCodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::CodeType;
use crate::ComponentInterface;
use uniffi_bindgen::ComponentInterface;

#[derive(Debug)]
pub struct CustomCodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::CodeType;
use crate::backend::Literal;
use crate::ComponentInterface;
use uniffi_bindgen::ComponentInterface;

#[derive(Debug)]
pub struct EnumCodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::CodeType;
use crate::ComponentInterface;
use uniffi_bindgen::ComponentInterface;

#[derive(Debug)]
pub struct ExternalCodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::CodeType;
use crate::ComponentInterface;
use uniffi_bindgen::ComponentInterface;
use paste::paste;

macro_rules! impl_code_type_for_miscellany {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};

use crate::backend::TemplateExpression;

use crate::interface::*;
use uniffi_bindgen::interface::*;

mod callback_interface;
mod compounds;
Expand All @@ -25,7 +25,6 @@ mod miscellany;
mod object;
mod primitives;
mod record;
mod variant;

trait CodeType: Debug {
/// The language specific label used to reference this type. This will be used in
Expand Down
Loading