mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 11:50:23 +00:00
Auto merge of #10434 - weihanglo:stop-gating-stable-features, r=alexcrichton
Stop gating stable features
This commit is contained in:
commit
489b66f2e4
|
@ -169,7 +169,6 @@ pub fn generate_std_roots(
|
|||
/*is_member*/ false,
|
||||
/*is_local*/ false,
|
||||
unit_for,
|
||||
mode,
|
||||
*kind,
|
||||
);
|
||||
list.push(interner.intern(
|
||||
|
|
|
@ -861,7 +861,6 @@ fn new_unit_dep(
|
|||
state.ws.is_member(pkg),
|
||||
is_local,
|
||||
unit_for,
|
||||
mode,
|
||||
kind,
|
||||
);
|
||||
new_unit_dep_with_profile(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::core::compiler::{CompileKind, CompileMode, CompileTarget, Unit};
|
||||
use crate::core::compiler::{CompileKind, CompileTarget, Unit};
|
||||
use crate::core::dependency::Artifact;
|
||||
use crate::core::resolver::features::FeaturesFor;
|
||||
use crate::core::{Feature, PackageId, PackageIdSpec, Resolve, Shell, Target, Workspace};
|
||||
use crate::core::{PackageId, PackageIdSpec, Resolve, Shell, Target, Workspace};
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::toml::{ProfilePackageSpec, StringOrBool, TomlProfile, TomlProfiles, U32OrBool};
|
||||
use crate::util::{closest_msg, config, CargoResult, Config};
|
||||
|
@ -26,8 +26,6 @@ pub struct Profiles {
|
|||
/// This is here to assist with error reporting, as the `ProfileMaker`
|
||||
/// values have the inherits chains all merged together.
|
||||
original_profiles: BTreeMap<InternedString, TomlProfile>,
|
||||
/// Whether or not unstable "named" profiles are enabled.
|
||||
named_profiles_enabled: bool,
|
||||
/// The profile the user requested to use.
|
||||
requested_profile: InternedString,
|
||||
/// The host target for rustc being used by this `Profiles`.
|
||||
|
@ -44,64 +42,8 @@ impl Profiles {
|
|||
let mut profiles = merge_config_profiles(ws, requested_profile)?;
|
||||
let rustc_host = ws.config().load_global_rustc(Some(ws))?.host;
|
||||
|
||||
if !ws.unstable_features().is_enabled(Feature::named_profiles()) {
|
||||
let mut profile_makers = Profiles {
|
||||
incremental,
|
||||
named_profiles_enabled: false,
|
||||
dir_names: Self::predefined_dir_names(),
|
||||
by_name: HashMap::new(),
|
||||
original_profiles: profiles.clone(),
|
||||
requested_profile,
|
||||
rustc_host,
|
||||
};
|
||||
|
||||
profile_makers.by_name.insert(
|
||||
InternedString::new("dev"),
|
||||
ProfileMaker::new(Profile::default_dev(), profiles.remove("dev")),
|
||||
);
|
||||
profile_makers
|
||||
.dir_names
|
||||
.insert(InternedString::new("dev"), InternedString::new("debug"));
|
||||
|
||||
profile_makers.by_name.insert(
|
||||
InternedString::new("release"),
|
||||
ProfileMaker::new(Profile::default_release(), profiles.remove("release")),
|
||||
);
|
||||
profile_makers.dir_names.insert(
|
||||
InternedString::new("release"),
|
||||
InternedString::new("release"),
|
||||
);
|
||||
|
||||
profile_makers.by_name.insert(
|
||||
InternedString::new("test"),
|
||||
ProfileMaker::new(Profile::default_test(), profiles.remove("test")),
|
||||
);
|
||||
profile_makers
|
||||
.dir_names
|
||||
.insert(InternedString::new("test"), InternedString::new("debug"));
|
||||
|
||||
profile_makers.by_name.insert(
|
||||
InternedString::new("bench"),
|
||||
ProfileMaker::new(Profile::default_bench(), profiles.remove("bench")),
|
||||
);
|
||||
profile_makers
|
||||
.dir_names
|
||||
.insert(InternedString::new("bench"), InternedString::new("release"));
|
||||
|
||||
profile_makers.by_name.insert(
|
||||
InternedString::new("doc"),
|
||||
ProfileMaker::new(Profile::default_doc(), profiles.remove("doc")),
|
||||
);
|
||||
profile_makers
|
||||
.dir_names
|
||||
.insert(InternedString::new("doc"), InternedString::new("debug"));
|
||||
|
||||
return Ok(profile_makers);
|
||||
}
|
||||
|
||||
let mut profile_makers = Profiles {
|
||||
incremental,
|
||||
named_profiles_enabled: true,
|
||||
dir_names: Self::predefined_dir_names(),
|
||||
by_name: HashMap::new(),
|
||||
original_profiles: profiles.clone(),
|
||||
|
@ -290,48 +232,9 @@ impl Profiles {
|
|||
is_member: bool,
|
||||
is_local: bool,
|
||||
unit_for: UnitFor,
|
||||
mode: CompileMode,
|
||||
kind: CompileKind,
|
||||
) -> Profile {
|
||||
let (profile_name, inherits) = if !self.named_profiles_enabled {
|
||||
// With the feature disabled, we degrade `--profile` back to the
|
||||
// `--release` and `--debug` predicates, and convert back from
|
||||
// ProfileKind::Custom instantiation.
|
||||
|
||||
let release = matches!(self.requested_profile.as_str(), "release" | "bench");
|
||||
|
||||
match mode {
|
||||
CompileMode::Test | CompileMode::Bench | CompileMode::Doctest => {
|
||||
if release {
|
||||
(
|
||||
InternedString::new("bench"),
|
||||
Some(InternedString::new("release")),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
InternedString::new("test"),
|
||||
Some(InternedString::new("dev")),
|
||||
)
|
||||
}
|
||||
}
|
||||
CompileMode::Build | CompileMode::Check { .. } | CompileMode::RunCustomBuild => {
|
||||
// Note: `RunCustomBuild` doesn't normally use this code path.
|
||||
// `build_unit_profiles` normally ensures that it selects the
|
||||
// ancestor's profile. However, `cargo clean -p` can hit this
|
||||
// path.
|
||||
if release {
|
||||
(InternedString::new("release"), None)
|
||||
} else {
|
||||
(InternedString::new("dev"), None)
|
||||
}
|
||||
}
|
||||
CompileMode::Doc { .. } | CompileMode::Docscrape => {
|
||||
(InternedString::new("doc"), None)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(self.requested_profile, None)
|
||||
};
|
||||
let (profile_name, inherits) = (self.requested_profile, None);
|
||||
let maker = self.get_profile_maker(profile_name).unwrap();
|
||||
let mut profile = maker.get_profile(Some(pkg_id), is_member, unit_for.is_for_host());
|
||||
|
||||
|
@ -404,15 +307,7 @@ impl Profiles {
|
|||
/// `[Finished]` line. It is not entirely accurate, since it doesn't
|
||||
/// select for the package that was actually built.
|
||||
pub fn base_profile(&self) -> Profile {
|
||||
let profile_name = if !self.named_profiles_enabled {
|
||||
match self.requested_profile.as_str() {
|
||||
"release" | "bench" => self.requested_profile,
|
||||
_ => InternedString::new("dev"),
|
||||
}
|
||||
} else {
|
||||
self.requested_profile
|
||||
};
|
||||
|
||||
let profile_name = self.requested_profile;
|
||||
let maker = self.get_profile_maker(profile_name).unwrap();
|
||||
maker.get_profile(None, /*is_member*/ true, /*is_for_host*/ false)
|
||||
}
|
||||
|
@ -772,29 +667,6 @@ impl Profile {
|
|||
}
|
||||
}
|
||||
|
||||
// NOTE: Remove the following three once `named_profiles` is default:
|
||||
|
||||
fn default_test() -> Profile {
|
||||
Profile {
|
||||
name: InternedString::new("test"),
|
||||
..Profile::default_dev()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_bench() -> Profile {
|
||||
Profile {
|
||||
name: InternedString::new("bench"),
|
||||
..Profile::default_release()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_doc() -> Profile {
|
||||
Profile {
|
||||
name: InternedString::new("doc"),
|
||||
..Profile::default_dev()
|
||||
}
|
||||
}
|
||||
|
||||
/// Compares all fields except `name`, which doesn't affect compilation.
|
||||
/// This is necessary for `Unit` deduplication for things like "test" and
|
||||
/// "dev" which are essentially the same.
|
||||
|
|
|
@ -1068,7 +1068,6 @@ fn generate_targets(
|
|||
ws.is_member(pkg),
|
||||
is_local,
|
||||
unit_for,
|
||||
target_mode,
|
||||
*kind,
|
||||
);
|
||||
let unit = interner.intern(
|
||||
|
|
|
@ -496,34 +496,19 @@ impl TomlProfile {
|
|||
) -> CargoResult<()> {
|
||||
self.validate_profile(name, features)?;
|
||||
if let Some(ref profile) = self.build_override {
|
||||
features.require(Feature::profile_overrides())?;
|
||||
profile.validate_override("build-override")?;
|
||||
profile.validate_profile(&format!("{name}.build-override"), features)?;
|
||||
}
|
||||
if let Some(ref packages) = self.package {
|
||||
features.require(Feature::profile_overrides())?;
|
||||
for (override_name, profile) in packages {
|
||||
profile.validate_override("package")?;
|
||||
profile.validate_profile(&format!("{name}.package.{override_name}"), features)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Feature gate definition of named profiles
|
||||
match name {
|
||||
"dev" | "release" | "bench" | "test" | "doc" => {}
|
||||
_ => {
|
||||
features.require(Feature::named_profiles())?;
|
||||
}
|
||||
}
|
||||
|
||||
// Profile name validation
|
||||
Self::validate_name(name)?;
|
||||
|
||||
// Feature gate on uses of keys related to named profiles
|
||||
if self.inherits.is_some() {
|
||||
features.require(Feature::named_profiles())?;
|
||||
}
|
||||
|
||||
if let Some(dir_name) = self.dir_name {
|
||||
// This is disabled for now, as we would like to stabilize named
|
||||
// profiles without this, and then decide in the future if it is
|
||||
|
@ -1146,18 +1131,19 @@ impl TomlManifest {
|
|||
let pkgid = project.to_package_id(source_id)?;
|
||||
|
||||
let edition = if let Some(ref edition) = project.edition {
|
||||
features
|
||||
.require(Feature::edition())
|
||||
.with_context(|| "editions are unstable")?;
|
||||
edition
|
||||
.parse()
|
||||
.with_context(|| "failed to parse the `edition` key")?
|
||||
} else {
|
||||
Edition::Edition2015
|
||||
};
|
||||
if edition == Edition::Edition2021 {
|
||||
features.require(Feature::edition2021())?;
|
||||
} else if !edition.is_stable() {
|
||||
// Add these lines if start a new unstable edition.
|
||||
// ```
|
||||
// if edition == Edition::Edition20xx {
|
||||
// features.require(Feature::edition20xx))?;
|
||||
// }
|
||||
// ```
|
||||
if !edition.is_stable() {
|
||||
// Guard in case someone forgets to add .require()
|
||||
return Err(util::errors::internal(format!(
|
||||
"edition {} should be gated",
|
||||
|
@ -1193,14 +1179,6 @@ impl TomlManifest {
|
|||
features.require(Feature::metabuild())?;
|
||||
}
|
||||
|
||||
if project.resolver.is_some()
|
||||
|| me
|
||||
.workspace
|
||||
.as_ref()
|
||||
.map_or(false, |ws| ws.resolver.is_some())
|
||||
{
|
||||
features.require(Feature::resolver())?;
|
||||
}
|
||||
let resolve_behavior = match (
|
||||
project.resolver.as_ref(),
|
||||
me.workspace.as_ref().and_then(|ws| ws.resolver.as_ref()),
|
||||
|
@ -1540,13 +1518,6 @@ impl TomlManifest {
|
|||
if let Some(profiles) = &profiles {
|
||||
profiles.validate(&features, &mut warnings)?;
|
||||
}
|
||||
if me
|
||||
.workspace
|
||||
.as_ref()
|
||||
.map_or(false, |ws| ws.resolver.is_some())
|
||||
{
|
||||
features.require(Feature::resolver())?;
|
||||
}
|
||||
let resolve_behavior = me
|
||||
.workspace
|
||||
.as_ref()
|
||||
|
@ -1959,7 +1930,6 @@ impl<P: ResolveToPath> DetailedTomlDependency<P> {
|
|||
dep.set_kind(kind);
|
||||
}
|
||||
if let Some(name_in_toml) = explicit_name_in_toml {
|
||||
cx.features.require(Feature::rename_dependency())?;
|
||||
dep.set_explicit_name_in_toml(name_in_toml);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ pub fn targets(
|
|||
let has_lib;
|
||||
|
||||
if let Some(target) = clean_lib(
|
||||
features,
|
||||
manifest.lib.as_ref(),
|
||||
package_root,
|
||||
package_name,
|
||||
|
@ -78,7 +77,6 @@ pub fn targets(
|
|||
)?);
|
||||
|
||||
targets.extend(clean_examples(
|
||||
features,
|
||||
manifest.example.as_ref(),
|
||||
package_root,
|
||||
edition,
|
||||
|
@ -88,7 +86,6 @@ pub fn targets(
|
|||
)?);
|
||||
|
||||
targets.extend(clean_tests(
|
||||
features,
|
||||
manifest.test.as_ref(),
|
||||
package_root,
|
||||
edition,
|
||||
|
@ -98,7 +95,6 @@ pub fn targets(
|
|||
)?);
|
||||
|
||||
targets.extend(clean_benches(
|
||||
features,
|
||||
manifest.bench.as_ref(),
|
||||
package_root,
|
||||
edition,
|
||||
|
@ -147,7 +143,6 @@ pub fn targets(
|
|||
}
|
||||
|
||||
fn clean_lib(
|
||||
features: &Features,
|
||||
toml_lib: Option<&TomlLibTarget>,
|
||||
package_root: &Path,
|
||||
package_name: &str,
|
||||
|
@ -251,7 +246,7 @@ fn clean_lib(
|
|||
};
|
||||
|
||||
let mut target = Target::lib_target(&lib.name(), crate_types, path, edition);
|
||||
configure(features, lib, &mut target)?;
|
||||
configure(lib, &mut target)?;
|
||||
Ok(Some(target))
|
||||
}
|
||||
|
||||
|
@ -350,7 +345,7 @@ fn clean_bins(
|
|||
edition,
|
||||
);
|
||||
|
||||
configure(features, bin, &mut target)?;
|
||||
configure(bin, &mut target)?;
|
||||
result.push(target);
|
||||
}
|
||||
return Ok(result);
|
||||
|
@ -379,7 +374,6 @@ fn clean_bins(
|
|||
}
|
||||
|
||||
fn clean_examples(
|
||||
features: &Features,
|
||||
toml_examples: Option<&Vec<TomlExampleTarget>>,
|
||||
package_root: &Path,
|
||||
edition: Edition,
|
||||
|
@ -416,7 +410,7 @@ fn clean_examples(
|
|||
toml.required_features.clone(),
|
||||
edition,
|
||||
);
|
||||
configure(features, &toml, &mut target)?;
|
||||
configure(&toml, &mut target)?;
|
||||
result.push(target);
|
||||
}
|
||||
|
||||
|
@ -424,7 +418,6 @@ fn clean_examples(
|
|||
}
|
||||
|
||||
fn clean_tests(
|
||||
features: &Features,
|
||||
toml_tests: Option<&Vec<TomlTestTarget>>,
|
||||
package_root: &Path,
|
||||
edition: Edition,
|
||||
|
@ -451,14 +444,13 @@ fn clean_tests(
|
|||
for (path, toml) in targets {
|
||||
let mut target =
|
||||
Target::test_target(&toml.name(), path, toml.required_features.clone(), edition);
|
||||
configure(features, &toml, &mut target)?;
|
||||
configure(&toml, &mut target)?;
|
||||
result.push(target);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn clean_benches(
|
||||
features: &Features,
|
||||
toml_benches: Option<&Vec<TomlBenchTarget>>,
|
||||
package_root: &Path,
|
||||
edition: Edition,
|
||||
|
@ -506,7 +498,7 @@ fn clean_benches(
|
|||
for (path, toml) in targets {
|
||||
let mut target =
|
||||
Target::bench_target(&toml.name(), path, toml.required_features.clone(), edition);
|
||||
configure(features, &toml, &mut target)?;
|
||||
configure(&toml, &mut target)?;
|
||||
result.push(target);
|
||||
}
|
||||
|
||||
|
@ -804,7 +796,7 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(features: &Features, toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
|
||||
fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
|
||||
let t2 = target.clone();
|
||||
target
|
||||
.set_tested(toml.test.unwrap_or_else(|| t2.tested()))
|
||||
|
@ -819,9 +811,6 @@ fn configure(features: &Features, toml: &TomlTarget, target: &mut Target) -> Car
|
|||
(Some(false), _) | (_, Some(false)) => false,
|
||||
});
|
||||
if let Some(edition) = toml.edition.clone() {
|
||||
features
|
||||
.require(Feature::edition())
|
||||
.with_context(|| "editions are unstable")?;
|
||||
target.set_edition(
|
||||
edition
|
||||
.parse()
|
||||
|
|
|
@ -312,7 +312,7 @@ fn named_config_profile() {
|
|||
// foo -> middle -> bar -> dev
|
||||
// middle exists in Cargo.toml, the others in .cargo/config
|
||||
use super::config::ConfigBuilder;
|
||||
use cargo::core::compiler::{CompileKind, CompileMode};
|
||||
use cargo::core::compiler::CompileKind;
|
||||
use cargo::core::profiles::{Profiles, UnitFor};
|
||||
use cargo::core::{PackageId, Workspace};
|
||||
use cargo::util::interning::InternedString;
|
||||
|
@ -370,9 +370,8 @@ fn named_config_profile() {
|
|||
let dep_pkg = PackageId::new("dep", "0.1.0", crates_io).unwrap();
|
||||
|
||||
// normal package
|
||||
let mode = CompileMode::Build;
|
||||
let kind = CompileKind::Host;
|
||||
let p = profiles.get_profile(a_pkg, true, true, UnitFor::new_normal(kind), mode, kind);
|
||||
let p = profiles.get_profile(a_pkg, true, true, UnitFor::new_normal(kind), kind);
|
||||
assert_eq!(p.name, "foo");
|
||||
assert_eq!(p.codegen_units, Some(2)); // "foo" from config
|
||||
assert_eq!(p.opt_level, "1"); // "middle" from manifest
|
||||
|
@ -381,14 +380,7 @@ fn named_config_profile() {
|
|||
assert_eq!(p.overflow_checks, true); // "dev" built-in (ignore package override)
|
||||
|
||||
// build-override
|
||||
let bo = profiles.get_profile(
|
||||
a_pkg,
|
||||
true,
|
||||
true,
|
||||
UnitFor::new_host(false, kind),
|
||||
mode,
|
||||
kind,
|
||||
);
|
||||
let bo = profiles.get_profile(a_pkg, true, true, UnitFor::new_host(false, kind), kind);
|
||||
assert_eq!(bo.name, "foo");
|
||||
assert_eq!(bo.codegen_units, Some(6)); // "foo" build override from config
|
||||
assert_eq!(bo.opt_level, "0"); // default to zero
|
||||
|
@ -397,7 +389,7 @@ fn named_config_profile() {
|
|||
assert_eq!(bo.overflow_checks, true); // SAME as normal
|
||||
|
||||
// package overrides
|
||||
let po = profiles.get_profile(dep_pkg, false, true, UnitFor::new_normal(kind), mode, kind);
|
||||
let po = profiles.get_profile(dep_pkg, false, true, UnitFor::new_normal(kind), kind);
|
||||
assert_eq!(po.name, "foo");
|
||||
assert_eq!(po.codegen_units, Some(7)); // "foo" package override from config
|
||||
assert_eq!(po.opt_level, "1"); // SAME as normal
|
||||
|
|
Loading…
Reference in a new issue