diff --git a/src/dependencies.rs b/src/dependencies.rs index 62d8950..4700b66 100644 --- a/src/dependencies.rs +++ b/src/dependencies.rs @@ -35,6 +35,7 @@ pub(crate) fn try_get_workspace_manifest(manifest_dir: &Path) -> Result, dir: &Path) { #[derive(Deserialize, Default, Debug)] pub struct WorkspaceManifest { + #[serde(default)] + pub workspace: Workspace, #[serde(default)] pub patch: Map, #[serde(default)] pub replace: Map, } +#[derive(Deserialize, Default, Debug)] +pub struct Workspace { + #[serde(default)] + pub package: WorkspacePackage, + #[serde(default)] + pub dependencies: Map, +} + +#[derive(Deserialize, Default, Debug)] +pub struct WorkspacePackage { + pub edition: Option, +} + #[derive(Deserialize, Default, Debug)] pub struct Manifest { #[serde(default, rename = "cargo-features")] @@ -107,6 +123,8 @@ pub struct Dependency { pub default_features: bool, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub features: Vec, + #[serde(default, skip_serializing_if = "is_false")] + pub workspace: bool, #[serde(flatten)] pub rest: Map, } @@ -136,6 +154,11 @@ fn is_true(boolean: &bool) -> bool { *boolean } +#[allow(clippy::trivially_copy_pass_by_ref)] +fn is_false(boolean: &bool) -> bool { + !*boolean +} + impl Serialize for Dependency { fn serialize(&self, serializer: S) -> Result where @@ -171,6 +194,7 @@ impl<'de> Deserialize<'de> for Dependency { path: None, default_features: true, features: Vec::new(), + workspace: false, rest: Map::new(), }) } diff --git a/src/expand.rs b/src/expand.rs index 3997a0f..df21652 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -268,7 +268,12 @@ fn make_manifest( features, dependencies: std::collections::BTreeMap::new(), bins: Vec::new(), - workspace: Some(Workspace {}), + workspace: Some(Workspace { + package: crate::manifest::WorkspacePackage { + edition: workspace_manifest.workspace.package.edition, + }, + dependencies: workspace_manifest.workspace.dependencies, + }), // Within a workspace, only the [patch] and [replace] sections in // the workspace root's Cargo.toml are applied by Cargo. patch: workspace_manifest.patch, @@ -286,6 +291,7 @@ fn make_manifest( path: Some(project.source_dir.clone()), default_features: false, features: Vec::new(), + workspace: false, rest: std::collections::BTreeMap::new(), }, ); diff --git a/src/manifest.rs b/src/manifest.rs index f160f51..c08ffef 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -1,5 +1,6 @@ use crate::dependencies::{Dependency, Patch, RegistryPatch}; use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; use std::collections::BTreeMap as Map; use std::ffi::OsStr; use std::path::PathBuf; @@ -27,13 +28,13 @@ pub struct Manifest { pub struct Package { pub name: String, pub version: String, - pub edition: Edition, pub publish: bool, + pub edition: Edition, } // Do not use enum for edition for future-compatibility. #[derive(Serialize, Deserialize, Debug)] -pub struct Edition(pub String); +pub struct Edition(pub Value); #[derive(Serialize, Debug)] pub struct Bin { @@ -55,7 +56,24 @@ pub struct Build { } #[derive(Serialize, Debug)] -pub struct Workspace {} +pub struct Workspace { + #[serde(skip_serializing_if = "WorkspacePackage::is_none")] + pub package: WorkspacePackage, + #[serde(skip_serializing_if = "Map::is_empty")] + pub dependencies: Map, +} + +#[derive(Serialize, Debug)] +pub struct WorkspacePackage { + #[serde(skip_serializing_if = "Option::is_none")] + pub edition: Option, +} + +impl WorkspacePackage { + fn is_none(&self) -> bool { + self.edition.is_none() + } +} impl Default for Edition { fn default() -> Self {