Skip to content

Commit ccb321a

Browse files
committed
-- Part 1 of RFC2906
1 parent cd46164 commit ccb321a

File tree

8 files changed

+1704
-153
lines changed

8 files changed

+1704
-153
lines changed

src/cargo/core/compiler/standard_lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub fn resolve_std<'cfg>(
6565
&Some(members),
6666
/*default_members*/ &None,
6767
/*exclude*/ &None,
68+
/*inheritable*/ &None,
6869
/*custom_metadata*/ &None,
6970
));
7071
let virtual_manifest = crate::core::VirtualManifest::new(

src/cargo/core/features.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ features! {
412412

413413
// Allow specifying rustflags directly in a profile
414414
(unstable, profile_rustflags, "", "reference/unstable.html#profile-rustflags-option"),
415+
416+
// Allow specifying rustflags directly in a profile
417+
(unstable, workspace_inheritance, "", "reference/unstable.html#workspace-inheritance"),
415418
}
416419

417420
pub struct Feature {

src/cargo/core/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ pub use self::resolver::{Resolve, ResolveVersion};
1010
pub use self::shell::{Shell, Verbosity};
1111
pub use self::source::{GitReference, Source, SourceId, SourceMap};
1212
pub use self::summary::{FeatureMap, FeatureValue, Summary};
13-
pub use self::workspace::{MaybePackage, Workspace, WorkspaceConfig, WorkspaceRootConfig};
13+
pub use self::workspace::{
14+
InheritableFields, MaybePackage, Workspace, WorkspaceConfig, WorkspaceRootConfig,
15+
};
1416

1517
pub mod compiler;
1618
pub mod dependency;

src/cargo/core/workspace.rs

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
2222
use crate::util::errors::{CargoResult, ManifestError};
2323
use crate::util::interning::InternedString;
2424
use crate::util::lev_distance;
25-
use crate::util::toml::{read_manifest, TomlDependency, TomlProfiles};
25+
use crate::util::toml::{
26+
read_manifest, StringOrBool, TomlDependency, TomlProfiles, VecStringOrBool,
27+
};
2628
use crate::util::{config::ConfigRelativePath, Config, Filesystem, IntoUrl};
2729
use cargo_util::paths;
2830

@@ -123,6 +125,15 @@ pub enum WorkspaceConfig {
123125
Member { root: Option<String> },
124126
}
125127

128+
impl WorkspaceConfig {
129+
pub fn inheritable(&self) -> Option<&InheritableFields> {
130+
match self {
131+
WorkspaceConfig::Root(root) => Some(&root.inheritable_fields),
132+
WorkspaceConfig::Member { .. } => None,
133+
}
134+
}
135+
}
136+
126137
/// Intermediate configuration of a workspace root in a manifest.
127138
///
128139
/// Knows the Workspace Root path, as well as `members` and `exclude` lists of path patterns, which
@@ -133,6 +144,7 @@ pub struct WorkspaceRootConfig {
133144
members: Option<Vec<String>>,
134145
default_members: Option<Vec<String>>,
135146
exclude: Vec<String>,
147+
inheritable_fields: InheritableFields,
136148
custom_metadata: Option<toml::Value>,
137149
}
138150

@@ -1567,17 +1579,18 @@ impl WorkspaceRootConfig {
15671579
members: &Option<Vec<String>>,
15681580
default_members: &Option<Vec<String>>,
15691581
exclude: &Option<Vec<String>>,
1582+
inheritable: &Option<InheritableFields>,
15701583
custom_metadata: &Option<toml::Value>,
15711584
) -> WorkspaceRootConfig {
15721585
WorkspaceRootConfig {
15731586
root_dir: root_dir.to_path_buf(),
15741587
members: members.clone(),
15751588
default_members: default_members.clone(),
15761589
exclude: exclude.clone().unwrap_or_default(),
1590+
inheritable_fields: inheritable.clone().unwrap_or_default(),
15771591
custom_metadata: custom_metadata.clone(),
15781592
}
15791593
}
1580-
15811594
/// Checks the path against the `excluded` list.
15821595
///
15831596
/// This method does **not** consider the `members` list.
@@ -1641,3 +1654,121 @@ impl WorkspaceRootConfig {
16411654
Ok(res)
16421655
}
16431656
}
1657+
1658+
/// A group of fields that are inheritable by members of the workspace
1659+
#[derive(Clone, Debug, Default)]
1660+
pub struct InheritableFields {
1661+
dependencies: Option<BTreeMap<String, TomlDependency>>,
1662+
version: Option<semver::Version>,
1663+
authors: Option<Vec<String>>,
1664+
description: Option<String>,
1665+
homepage: Option<String>,
1666+
documentation: Option<String>,
1667+
readme: Option<StringOrBool>,
1668+
keywords: Option<Vec<String>>,
1669+
categories: Option<Vec<String>>,
1670+
license: Option<String>,
1671+
license_file: Option<String>,
1672+
repository: Option<String>,
1673+
publish: Option<VecStringOrBool>,
1674+
edition: Option<String>,
1675+
badges: Option<BTreeMap<String, BTreeMap<String, String>>>,
1676+
}
1677+
1678+
impl InheritableFields {
1679+
pub fn new(
1680+
dependencies: Option<BTreeMap<String, TomlDependency>>,
1681+
version: Option<semver::Version>,
1682+
authors: Option<Vec<String>>,
1683+
description: Option<String>,
1684+
homepage: Option<String>,
1685+
documentation: Option<String>,
1686+
readme: Option<StringOrBool>,
1687+
keywords: Option<Vec<String>>,
1688+
categories: Option<Vec<String>>,
1689+
license: Option<String>,
1690+
license_file: Option<String>,
1691+
repository: Option<String>,
1692+
publish: Option<VecStringOrBool>,
1693+
edition: Option<String>,
1694+
badges: Option<BTreeMap<String, BTreeMap<String, String>>>,
1695+
) -> InheritableFields {
1696+
Self {
1697+
dependencies,
1698+
version,
1699+
authors,
1700+
description,
1701+
homepage,
1702+
documentation,
1703+
readme,
1704+
keywords,
1705+
categories,
1706+
license,
1707+
license_file,
1708+
repository,
1709+
publish,
1710+
edition,
1711+
badges,
1712+
}
1713+
}
1714+
1715+
pub fn dependencies(&self) -> Option<BTreeMap<String, TomlDependency>> {
1716+
self.dependencies.clone()
1717+
}
1718+
1719+
pub fn version(&self) -> Option<semver::Version> {
1720+
self.version.clone()
1721+
}
1722+
1723+
pub fn authors(&self) -> Option<Vec<String>> {
1724+
self.authors.clone()
1725+
}
1726+
1727+
pub fn description(&self) -> Option<String> {
1728+
self.description.clone()
1729+
}
1730+
1731+
pub fn homepage(&self) -> Option<String> {
1732+
self.homepage.clone()
1733+
}
1734+
1735+
pub fn documentation(&self) -> Option<String> {
1736+
self.documentation.clone()
1737+
}
1738+
1739+
pub fn readme(&self) -> Option<StringOrBool> {
1740+
self.readme.clone()
1741+
}
1742+
1743+
pub fn keywords(&self) -> Option<Vec<String>> {
1744+
self.keywords.clone()
1745+
}
1746+
1747+
pub fn categories(&self) -> Option<Vec<String>> {
1748+
self.categories.clone()
1749+
}
1750+
1751+
pub fn license(&self) -> Option<String> {
1752+
self.license.clone()
1753+
}
1754+
1755+
pub fn license_file(&self) -> Option<String> {
1756+
self.license_file.clone()
1757+
}
1758+
1759+
pub fn repository(&self) -> Option<String> {
1760+
self.repository.clone()
1761+
}
1762+
1763+
pub fn publish(&self) -> Option<VecStringOrBool> {
1764+
self.publish.clone()
1765+
}
1766+
1767+
pub fn edition(&self) -> Option<String> {
1768+
self.edition.clone()
1769+
}
1770+
1771+
pub fn badges(&self) -> Option<BTreeMap<String, BTreeMap<String, String>>> {
1772+
self.badges.clone()
1773+
}
1774+
}

0 commit comments

Comments
 (0)