diff --git a/src/lib.rs b/src/lib.rs index bb7f6e9b7..b4399bb0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ pub use crate::module_writer::{ pub use crate::new_project::{init_project, new_project, GenerateProjectOptions}; pub use crate::pyproject_toml::PyProjectToml; pub use crate::python_interpreter::PythonInterpreter; +pub use crate::source_distribution::find_path_deps; #[cfg(feature = "upload")] pub use crate::upload::{upload, upload_ui, PublishOpt, Registry, UploadError}; pub use auditwheel::PlatformTag; diff --git a/src/main.rs b/src/main.rs index 7fc868019..da594cdf9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,8 @@ use clap::{Parser, Subcommand}; #[cfg(feature = "scaffolding")] use maturin::{ci::GenerateCI, init_project, new_project, GenerateProjectOptions}; use maturin::{ - develop, write_dist_info, BridgeModel, BuildOptions, CargoOptions, DevelopOptions, PathWriter, - PythonInterpreter, Target, TargetTriple, + develop, find_path_deps, write_dist_info, BridgeModel, BuildOptions, CargoOptions, + DevelopOptions, PathWriter, PythonInterpreter, Target, TargetTriple, }; #[cfg(feature = "schemars")] use maturin::{generate_json_schema, GenerateJsonSchemaOptions}; @@ -433,13 +433,29 @@ fn run() -> Result<()> { develop(develop_options, &venv_dir)?; } Command::SDist { manifest_path, out } => { + // Get cargo metadata to check for path dependencies + let cargo_metadata_result = cargo_metadata::MetadataCommand::new() + .cargo_path("cargo") + .manifest_path( + manifest_path + .as_deref() + .unwrap_or_else(|| std::path::Path::new("Cargo.toml")), + ) + .verbose(true) + .exec(); + + let has_path_deps = cargo_metadata_result + .ok() + .and_then(|metadata| find_path_deps(&metadata).ok()) + .map(|path_deps| !path_deps.is_empty()) + .unwrap_or(false); // If we can't get metadata, don't force all features let build_options = BuildOptions { out, cargo: CargoOptions { manifest_path, - // Enable all features to ensure all optional path dependencies are packaged - // into source distribution - all_features: true, + // Only enable all features when we have local path dependencies + // to ensure they are packaged into source distribution + all_features: has_path_deps, ..Default::default() }, ..Default::default() diff --git a/src/source_distribution.rs b/src/source_distribution.rs index efe4fc414..856d72724 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -25,7 +25,7 @@ use tracing::{debug, trace}; /// foo = { path = "path/to/foo" } /// ``` #[derive(Debug, Clone)] -struct PathDependency { +pub struct PathDependency { /// `Cargo.toml` path of the path dependency manifest_path: PathBuf, /// workspace root of the path dependency @@ -307,7 +307,7 @@ fn add_crate_to_source_distribution( } /// Finds all path dependencies of the crate -fn find_path_deps(cargo_metadata: &Metadata) -> Result> { +pub fn find_path_deps(cargo_metadata: &Metadata) -> Result> { let root = cargo_metadata .root_package() .context("Expected the dependency graph to have a root package")?;