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

Fix so cargo_metadata isn't a dependency without the cargo_metadata feature #2200

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion fixtures/benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ criterion = "0.5.1"
uniffi = { workspace = true, features = ["build"] }

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

[[bench]]
name = "benchmarks"
Expand Down
3 changes: 2 additions & 1 deletion fixtures/benchmarks/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use clap::Parser;
use std::env;
use uniffi_benchmarks::Args;
use uniffi_bindgen::bindings::{
kotlin_run_script, python_run_script, swift_run_script, RunScriptOptions,
kotlin_test::run_script as kotlin_run_script, python_test::run_script as python_run_script,
swift_test::run_script as swift_run_script, RunScriptOptions,
};

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bindgen = ["dep:uniffi_bindgen"]
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" ]
bindgen-tests = [ "dep:uniffi_bindgen", "uniffi_bindgen/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
9 changes: 2 additions & 7 deletions uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ pub use uniffi_macros::*;
#[cfg(feature = "cli")]
mod cli;
#[cfg(feature = "bindgen-tests")]
pub use uniffi_bindgen::bindings::kotlin_run_test;
#[cfg(feature = "bindgen-tests")]
pub use uniffi_bindgen::bindings::python_run_test;
#[cfg(feature = "bindgen-tests")]
pub use uniffi_bindgen::bindings::ruby_run_test;
#[cfg(feature = "bindgen-tests")]
pub use uniffi_bindgen::bindings::swift_run_test;
pub use uniffi_bindgen::bindings::{kotlin_test, python_test, ruby_test, swift_test};

#[cfg(feature = "bindgen")]
pub use uniffi_bindgen::{
bindings::{
Expand Down
7 changes: 4 additions & 3 deletions uniffi_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ keywords = ["ffi", "bindgen"]
readme = "../README.md"

[features]
default = ["cargo_metadata"]
cargo_metadata = ["dep:cargo_metadata"]
default = ["cargo-metadata"]
cargo-metadata = ["dep:cargo_metadata"]
bindgen-tests = ["cargo-metadata", "dep:uniffi_testing"]

[dependencies]
anyhow = "1"
Expand All @@ -29,7 +30,7 @@ paste = "1.0"
serde = { version = "1", features = ["derive"] }
toml = "0.5"
uniffi_meta = { path = "../uniffi_meta", version = "=0.28.0" }
uniffi_testing = { path = "../uniffi_testing", version = "=0.28.0" }
uniffi_testing = { path = "../uniffi_testing", version = "=0.28.0", optional = true }
uniffi_udl = { path = "../uniffi_udl", version = "=0.28.0" }
# Don't include the `unicode-linebreak` or `unicode-width` since that functionality isn't needed for
# docstrings.
Expand Down
4 changes: 2 additions & 2 deletions uniffi_bindgen/src/bindings/kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::process::Command;

mod gen_kotlin;
use gen_kotlin::{generate_bindings, Config};
mod test;
pub use test::{run_script, run_test};
#[cfg(feature = "bindgen-tests")]
pub mod test;

pub struct KotlinBindingGenerator;
impl BindingGenerator for KotlinBindingGenerator {
Expand Down
20 changes: 11 additions & 9 deletions uniffi_bindgen/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@
//! along with some helpers for executing foreign language scripts or tests.

mod kotlin;
pub use kotlin::{
run_script as kotlin_run_script, run_test as kotlin_run_test, KotlinBindingGenerator,
};
pub use kotlin::KotlinBindingGenerator;
mod python;
pub use python::{
run_script as python_run_script, run_test as python_run_test, PythonBindingGenerator,
};
pub use python::PythonBindingGenerator;
mod ruby;
pub use ruby::{run_test as ruby_run_test, RubyBindingGenerator};
pub use ruby::RubyBindingGenerator;
mod swift;
pub use swift::{
run_script as swift_run_script, run_test as swift_run_test, SwiftBindingGenerator,
pub use swift::SwiftBindingGenerator;

#[cfg(feature = "bindgen-tests")]
pub use self::{
kotlin::test as kotlin_test, python::test as python_test, ruby::test as ruby_test,
swift::test as swift_test,
};

#[cfg(feature = "bindgen-tests")]
/// Mode for the `run_script` function defined for each language
#[derive(Clone, Debug)]
pub struct RunScriptOptions {
pub show_compiler_messages: bool,
}

#[cfg(feature = "bindgen-tests")]
impl Default for RunScriptOptions {
fn default() -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions uniffi_bindgen/src/bindings/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use anyhow::Result;
use fs_err as fs;

mod gen_python;
mod test;
#[cfg(feature = "bindgen-tests")]
pub mod test;
use crate::{Component, GenerationSettings};
use gen_python::{generate_python_bindings, Config};
pub use test::{run_script, run_test};

pub struct PythonBindingGenerator;

Expand Down
4 changes: 2 additions & 2 deletions uniffi_bindgen/src/bindings/ruby/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use anyhow::{Context, Result};
use fs_err as fs;

mod gen_ruby;
mod test;
#[cfg(feature = "bindgen-tests")]
pub mod test;
use gen_ruby::{Config, RubyWrapper};
pub use test::run_test;

pub struct RubyBindingGenerator;
impl BindingGenerator for RubyBindingGenerator {
Expand Down
5 changes: 3 additions & 2 deletions uniffi_bindgen/src/bindings/swift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ use std::process::Command;

mod gen_swift;
use gen_swift::{generate_bindings, Config};
mod test;
pub use test::{run_script, run_test};

#[cfg(feature = "bindgen-tests")]
pub mod test;

/// The Swift bindings generated from a [`crate::ComponentInterface`].
///
Expand Down
6 changes: 3 additions & 3 deletions uniffi_bindgen/src/library_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl CratePathMap {
// TODO: we probably need external overrides passed in (maybe via
// `config_file_override` - what are the semantics of that?)
// Anyway: for now we just do this.
#[cfg(feature = "cargo_metadata")]
#[cfg(feature = "cargo-metadata")]
fn new() -> Result<Self> {
Ok(Self::from(
cargo_metadata::MetadataCommand::new()
Expand All @@ -155,7 +155,7 @@ impl CratePathMap {
))
}

#[cfg(not(feature = "cargo_metadata"))]
#[cfg(not(feature = "cargo-metadata"))]
fn new() -> Result<Self> {
Ok(Self::default())
}
Expand All @@ -166,7 +166,7 @@ impl CratePathMap {
}

// all this to get a few paths!?
#[cfg(feature = "cargo_metadata")]
#[cfg(feature = "cargo-metadata")]
impl From<cargo_metadata::Metadata> for CratePathMap {
fn from(metadata: cargo_metadata::Metadata) -> Self {
let paths: HashMap<String, Utf8PathBuf> = metadata
Expand Down
8 changes: 4 additions & 4 deletions uniffi_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ pub(crate) fn build_foreign_language_testcases(tokens: TokenStream) -> TokenStre
);
let run_test = match test_file_pathbuf.extension() {
Some("kts") => quote! {
::uniffi::kotlin_run_test
::uniffi::kotlin_test::run_test
},
Some("swift") => quote! {
::uniffi::swift_run_test
::uniffi::swift_test::run_test
},
Some("py") => quote! {
::uniffi::python_run_test
::uniffi::python_test::run_test
},
Some("rb") => quote! {
::uniffi::ruby_run_test
::uniffi::ruby_test::run_test
},
_ => panic!("Unexpected extension for test script: {test_file_name}"),
};
Expand Down