diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 524985dcaa3..d944ba833d1 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -387,7 +387,7 @@ features! { (unstable, public_dependency, "", "reference/unstable.html#public-dependency"), // Allow to specify profiles other than 'dev', 'release', 'test', etc. - (unstable, named_profiles, "", "reference/unstable.html#custom-named-profiles"), + (stable, named_profiles, "1.57", "reference/profiles.html#custom-profiles"), // Opt-in new-resolver behavior. (stable, resolver, "1.51", "reference/resolver.html#resolver-versions"), @@ -643,7 +643,6 @@ unstable_cli_options!( minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"), mtime_on_use: bool = ("Configure Cargo to update the mtime of used files"), multitarget: bool = ("Allow passing multiple `--target` flags to the cargo subcommand selected"), - named_profiles: bool = ("Allow defining custom profiles"), namespaced_features: bool = ("Allow features with `dep:` prefix"), no_index_update: bool = ("Do not update the registry index even if the cache is outdated"), panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"), @@ -699,6 +698,10 @@ const STABILIZED_CONFIGURABLE_ENV: &str = "The [env] section is now always enabl const STABILIZED_PATCH_IN_CONFIG: &str = "The patch-in-config feature is now always enabled."; +const STABILIZED_NAMED_PROFILES: &str = "The named-profiles feature is now always enabled.\n\ + See https://doc.rust-lang.org/nightly/cargo/reference/profiles.html#custom-profiles \ + for more information"; + fn deserialize_build_std<'de, D>(deserializer: D) -> Result>, D::Error> where D: serde::Deserializer<'de>, @@ -830,7 +833,7 @@ impl CliUnstable { "dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?, // can also be set in .cargo/config or with and ENV "mtime-on-use" => self.mtime_on_use = parse_empty(k, v)?, - "named-profiles" => self.named_profiles = parse_empty(k, v)?, + "named-profiles" => stabilized_warn(k, "1.57", STABILIZED_NAMED_PROFILES), "binary-dep-depinfo" => self.binary_dep_depinfo = parse_empty(k, v)?, "build-std" => { self.build_std = Some(crate::core::compiler::standard_lib::parse_unstable_flag(v)) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index ac167f17363..a028ca571fc 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -20,6 +20,11 @@ pub struct Profiles { dir_names: HashMap, /// The profile makers. Key is the profile name. by_name: HashMap, + /// The original profiles written by the user in the manifest and config. + /// + /// This is here to assist with error reporting, as the `ProfileMaker` + /// values have the inherits chains all merged together. + original_profiles: BTreeMap, /// Whether or not unstable "named" profiles are enabled. named_profiles_enabled: bool, /// The profile the user requested to use. @@ -44,6 +49,7 @@ impl Profiles { named_profiles_enabled: false, dir_names: Self::predefined_dir_names(), by_name: HashMap::new(), + original_profiles: profiles.clone(), requested_profile, rustc_host, }; @@ -97,6 +103,7 @@ impl Profiles { named_profiles_enabled: true, dir_names: Self::predefined_dir_names(), by_name: HashMap::new(), + original_profiles: profiles.clone(), requested_profile, rustc_host, }; @@ -420,6 +427,19 @@ impl Profiles { resolve: &Resolve, ) -> CargoResult<()> { for (name, profile) in &self.by_name { + // If the user did not specify an override, skip this. This is here + // to avoid generating errors for inherited profiles which don't + // specify package overrides. The `by_name` profile has had the inherits + // chain merged, so we need to look at the original source to check + // if an override was specified. + if self + .original_profiles + .get(name) + .and_then(|orig| orig.package.as_ref()) + .is_none() + { + continue; + } let found = validate_packages_unique(resolve, name, &profile.toml)?; // We intentionally do not validate unmatched packages for config // profiles, in case they are defined in a central location. This @@ -456,6 +476,10 @@ struct ProfileMaker { /// The starting, hard-coded defaults for the profile. default: Profile, /// The TOML profile defined in `Cargo.toml` or config. + /// + /// This is None if the user did not specify one, in which case the + /// `default` is used. Note that the built-in defaults for test/bench/doc + /// always set this since they need to declare the `inherits` value. toml: Option, } diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index bab36a9a94d..d0cf17824b1 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -363,16 +363,22 @@ pub trait ArgMatchesExt { // This is an early exit, since it allows combination with `--release`. match (specified_profile, profile_checking) { // `cargo rustc` has legacy handling of these names - (Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc) | + (Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc) // `cargo fix` and `cargo check` has legacy handling of this profile name - (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => return Ok(InternedString::new(name)), + | (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => { + if self._is_present("release") { + config.shell().warn( + "the `--release` flag should not be specified with the `--profile` flag\n\ + The `--release` flag will be ignored.\n\ + This was historically accepted, but will become an error \ + in a future release." + )?; + } + return Ok(InternedString::new(name)); + } _ => {} } - if specified_profile.is_some() && !config.cli_unstable().unstable_options { - bail!("usage of `--profile` requires `-Z unstable-options`"); - } - let conflict = |flag: &str, equiv: &str, specified: &str| -> anyhow::Error { anyhow::format_err!( "conflicting usage of --profile={} and --{flag}\n\ diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 997a2099d0c..aa26d0897e8 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -602,6 +602,7 @@ impl TomlProfile { | "rust" | "rustc" | "rustdoc" + | "target" | "tmp" | "uninstall" ) || lower_name.starts_with("cargo") diff --git a/src/doc/man/cargo-bench.md b/src/doc/man/cargo-bench.md index 9c62c2d1e83..ded8e2b361f 100644 --- a/src/doc/man/cargo-bench.md +++ b/src/doc/man/cargo-bench.md @@ -46,6 +46,14 @@ function to handle running benchmarks. > running benchmarks on the stable channel, such as > [Criterion](https://crates.io/crates/criterion). +By default, `cargo bench` uses the [`bench` profile], which enables +optimizations and disables debugging information. If you need to debug a +benchmark, you can use the `--profile=dev` command-line option to switch to +the dev profile. You can then run the debug-enabled benchmark within a +debugger. + +[`bench` profile]: ../reference/profiles.html#bench + ## OPTIONS ### Benchmark Options @@ -83,6 +91,8 @@ target. {{> options-target-triple }} +{{> options-profile }} + {{> options-ignore-rust-version }} {{/options}} @@ -129,23 +139,6 @@ Rust test harness runs benchmarks serially in a single thread. {{> options-jobs }} {{/options}} -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See -[the reference](../reference/profiles.html) -for more details. - -Benchmarks are always built with the `bench` profile. Binary and lib targets -are built separately as benchmarks with the `bench` profile. Library targets -are built with the `release` profiles when linked to binaries and benchmarks. -Dependencies use the `release` profile. - -If you need a debug build of a benchmark, try building it with -{{man "cargo-build" 1}} which will use the `test` profile which is by default -unoptimized and includes debug information. You can then run the debug-enabled -benchmark manually. - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-build.md b/src/doc/man/cargo-build.md index ceca80d2929..8b5aa471791 100644 --- a/src/doc/man/cargo-build.md +++ b/src/doc/man/cargo-build.md @@ -35,6 +35,8 @@ they have `required-features` that are missing. {{> options-release }} +{{> options-profile }} + {{> options-ignore-rust-version }} {{/options}} @@ -89,8 +91,6 @@ See for more information. {{> options-jobs }} {{/options}} -{{> section-profiles }} - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-check.md b/src/doc/man/cargo-check.md index c31411a9183..5264043f938 100644 --- a/src/doc/man/cargo-check.md +++ b/src/doc/man/cargo-check.md @@ -40,7 +40,7 @@ they have `required-features` that are missing. {{> options-release }} -{{> options-profile }} +{{> options-profile-legacy-check }} {{> options-ignore-rust-version }} @@ -76,8 +76,6 @@ they have `required-features` that are missing. {{> options-jobs }} {{/options}} -{{> section-profiles }} - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-clean.md b/src/doc/man/cargo-clean.md index d7d50840a9c..aa631563248 100644 --- a/src/doc/man/cargo-clean.md +++ b/src/doc/man/cargo-clean.md @@ -40,7 +40,11 @@ the target directory. {{/option}} {{#option "`--release`" }} -Clean all artifacts that were built with the `release` or `bench` profiles. +Remove all artifacts in the `release` directory. +{{/option}} + +{{#option "`--profile` _name_" }} +Remove all artifacts in the directory with the given profile name. {{/option}} {{> options-target-dir }} diff --git a/src/doc/man/cargo-doc.md b/src/doc/man/cargo-doc.md index b0289a8368f..551adfcf951 100644 --- a/src/doc/man/cargo-doc.md +++ b/src/doc/man/cargo-doc.md @@ -74,6 +74,8 @@ and supports common Unix glob patterns. {{> options-release }} +{{> options-profile }} + {{> options-ignore-rust-version }} {{/options}} @@ -108,8 +110,6 @@ and supports common Unix glob patterns. {{> options-jobs }} {{/options}} -{{> section-profiles }} - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-fix.md b/src/doc/man/cargo-fix.md index de8a39a5d0d..2d96efd4217 100644 --- a/src/doc/man/cargo-fix.md +++ b/src/doc/man/cargo-fix.md @@ -120,7 +120,7 @@ When no target selection options are given, `cargo fix` will fix all targets {{> options-release }} -{{> options-profile }} +{{> options-profile-legacy-check }} {{> options-ignore-rust-version }} @@ -156,8 +156,6 @@ When no target selection options are given, `cargo fix` will fix all targets {{> options-jobs }} {{/options}} -{{> section-profiles }} - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-install.md b/src/doc/man/cargo-install.md index 95f55002134..bea6ec37c4f 100644 --- a/src/doc/man/cargo-install.md +++ b/src/doc/man/cargo-install.md @@ -42,7 +42,7 @@ change, then Cargo will reinstall the package: - The package version and source. - The set of binary names installed. - The chosen features. -- The release mode (`--debug`). +- The profile (`--profile`). - The target (`--target`). Installing with `--path` will always build and install, unless there are @@ -162,8 +162,11 @@ Directory to install packages into. {{#option "`--debug`" }} Build with the `dev` profile instead the `release` profile. +See also the `--profile` option for choosing a specific profile by name. {{/option}} +{{> options-profile }} + {{/options}} ### Manifest Options diff --git a/src/doc/man/cargo-run.md b/src/doc/man/cargo-run.md index 7ba63c91eaf..b4e1d06695f 100644 --- a/src/doc/man/cargo-run.md +++ b/src/doc/man/cargo-run.md @@ -50,6 +50,8 @@ Run the specified example. {{> options-release }} +{{> options-profile }} + {{> options-ignore-rust-version }} {{/options}} @@ -88,8 +90,6 @@ Run the specified example. {{> options-jobs }} {{/options}} -{{> section-profiles }} - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-rustc.md b/src/doc/man/cargo-rustc.md index 178580a2edb..de0159e54d3 100644 --- a/src/doc/man/cargo-rustc.md +++ b/src/doc/man/cargo-rustc.md @@ -47,6 +47,23 @@ binary and library targets of the selected package. {{> options-release }} +{{#option "`--profile` _name_" }} +Build with the given profile. + +The `rustc` subcommand will treat the following named profiles with special behaviors: + +* `check` — Builds in the same way as the {{man "cargo-check" 1}} command with + the `dev` profile. +* `test` — Builds in the same way as the {{man "cargo-test" 1}} command, + enabling building in test mode which will enable tests and enable the `test` + cfg option. See [rustc + tests](https://doc.rust-lang.org/rustc/tests/index.html) for more detail. +* `bench` — Builds in the same was as the {{man "cargo-bench" 1}} command, + similar to the `test` profile. + +See the [the reference](../reference/profiles.html) for more details on profiles. +{{/option}} + {{> options-ignore-rust-version }} {{/options}} @@ -85,8 +102,6 @@ binary and library targets of the selected package. {{> options-jobs }} {{/options}} -{{> section-profiles }} - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-rustdoc.md b/src/doc/man/cargo-rustdoc.md index 40aaff20018..278c569646c 100644 --- a/src/doc/man/cargo-rustdoc.md +++ b/src/doc/man/cargo-rustdoc.md @@ -62,6 +62,8 @@ if its name is the same as the lib target. Binaries are skipped if they have {{> options-release }} +{{> options-profile }} + {{> options-ignore-rust-version }} {{/options}} @@ -96,8 +98,6 @@ if its name is the same as the lib target. Binaries are skipped if they have {{> options-jobs }} {{/options}} -{{> section-profiles }} - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/cargo-test.md b/src/doc/man/cargo-test.md index eb352e46e7b..2381a9e6ff7 100644 --- a/src/doc/man/cargo-test.md +++ b/src/doc/man/cargo-test.md @@ -102,6 +102,8 @@ target options. {{> options-release }} +{{> options-profile }} + {{> options-ignore-rust-version }} {{/options}} @@ -154,16 +156,6 @@ includes an option to control the number of threads used: {{/options}} -{{> section-profiles }} - -Unit tests are separate executable artifacts which use the `test`/`bench` -profiles. Example targets are built the same as with `cargo build` (using the -`dev`/`release` profiles) unless you are building them with the test harness -(by setting `test = true` in the manifest or using the `--example` flag) in -which case they use the `test`/`bench` profiles. Library targets are built -with the `dev`/`release` profiles when linked to an integration test, binary, -or doctest. - {{> section-environment }} {{> section-exit-status }} diff --git a/src/doc/man/generated_txt/cargo-bench.txt b/src/doc/man/generated_txt/cargo-bench.txt index 5a933063709..fcb476b8f55 100644 --- a/src/doc/man/generated_txt/cargo-bench.txt +++ b/src/doc/man/generated_txt/cargo-bench.txt @@ -41,6 +41,13 @@ DESCRIPTION benchmarks on the stable channel, such as Criterion . + By default, cargo bench uses the bench profile + , which + enables optimizations and disables debugging information. If you need to + debug a benchmark, you can use the --profile=dev command-line option to + switch to the dev profile. You can then run the debug-enabled benchmark + within a debugger. + OPTIONS Benchmark Options --no-run @@ -202,6 +209,11 @@ OPTIONS documentation for more details. + --profile name + Benchmark with the given profile. See the the reference + for more + details on profiles. + --ignore-rust-version Benchmark the target even if the selected Rust compiler is older than the required Rust version as configured in the project's @@ -329,22 +341,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Benchmarks are always built with the bench profile. Binary and lib - targets are built separately as benchmarks with the bench profile. - Library targets are built with the release profiles when linked to - binaries and benchmarks. Dependencies use the release profile. - - If you need a debug build of a benchmark, try building it with - cargo-build(1) which will use the test profile which is by default - unoptimized and includes debug information. You can then run the - debug-enabled benchmark manually. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-build.txt b/src/doc/man/generated_txt/cargo-build.txt index 4b321d9f7cb..4eb1e072a8c 100644 --- a/src/doc/man/generated_txt/cargo-build.txt +++ b/src/doc/man/generated_txt/cargo-build.txt @@ -143,8 +143,13 @@ OPTIONS documentation for more details. --release - Build optimized artifacts with the release profile. See the PROFILES - section for details on how this affects profile selection. + Build optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. + + --profile name + Build with the given profile. See the the reference + for more + details on profiles. --ignore-rust-version Build the target even if the selected Rust compiler is older than @@ -282,28 +287,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-check.txt b/src/doc/man/generated_txt/cargo-check.txt index ce8281c6a27..2ca78e6e9ac 100644 --- a/src/doc/man/generated_txt/cargo-check.txt +++ b/src/doc/man/generated_txt/cargo-check.txt @@ -149,14 +149,20 @@ OPTIONS documentation for more details. --release - Check optimized artifacts with the release profile. See the PROFILES - section for details on how this affects profile selection. + Check optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. --profile name - Changes check behavior. Currently only test is supported, which will - check with the #[cfg(test)] attribute enabled. This is useful to - have it check unit tests which are usually excluded via the cfg - attribute. This does not change the actual profile used. + Check with the given profile. + + As a special case, specifying the test profile will also enable + checking in test mode which will enable checking tests and enable + the test cfg option. See rustc tests + for more detail. + + See the the reference + for more + details on profiles. --ignore-rust-version Check the target even if the selected Rust compiler is older than @@ -275,28 +281,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-clean.txt b/src/doc/man/generated_txt/cargo-clean.txt index 192217e8b8e..9f4530a7ea8 100644 --- a/src/doc/man/generated_txt/cargo-clean.txt +++ b/src/doc/man/generated_txt/cargo-clean.txt @@ -27,8 +27,10 @@ OPTIONS in the target directory. --release - Clean all artifacts that were built with the release or bench - profiles. + Remove all artifacts in the release directory. + + --profile name + Remove all artifacts in the directory with the given profile name. --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-doc.txt b/src/doc/man/generated_txt/cargo-doc.txt index de1589d6304..648c55e2017 100644 --- a/src/doc/man/generated_txt/cargo-doc.txt +++ b/src/doc/man/generated_txt/cargo-doc.txt @@ -127,8 +127,13 @@ OPTIONS documentation for more details. --release - Document optimized artifacts with the release profile. See the - PROFILES section for details on how this affects profile selection. + Document optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. + + --profile name + Document with the given profile. See the the reference + for more + details on profiles. --ignore-rust-version Document the target even if the selected Rust compiler is older than @@ -247,28 +252,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-fix.txt b/src/doc/man/generated_txt/cargo-fix.txt index 450023a7241..60aec632e00 100644 --- a/src/doc/man/generated_txt/cargo-fix.txt +++ b/src/doc/man/generated_txt/cargo-fix.txt @@ -222,14 +222,20 @@ OPTIONS documentation for more details. --release - Fix optimized artifacts with the release profile. See the PROFILES - section for details on how this affects profile selection. + Fix optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. --profile name - Changes fix behavior. Currently only test is supported, which will - fix with the #[cfg(test)] attribute enabled. This is useful to have - it fix unit tests which are usually excluded via the cfg attribute. - This does not change the actual profile used. + Fix with the given profile. + + As a special case, specifying the test profile will also enable + checking in test mode which will enable checking tests and enable + the test cfg option. See rustc tests + for more detail. + + See the the reference + for more + details on profiles. --ignore-rust-version Fix the target even if the selected Rust compiler is older than the @@ -348,28 +354,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-install.txt b/src/doc/man/generated_txt/cargo-install.txt index ce009c0cb68..09a20942376 100644 --- a/src/doc/man/generated_txt/cargo-install.txt +++ b/src/doc/man/generated_txt/cargo-install.txt @@ -51,7 +51,7 @@ DESCRIPTION o The chosen features. - o The release mode (--debug). + o The profile (--profile). o The target (--target). @@ -197,7 +197,13 @@ OPTIONS workspace of the local crate unless --target-dir is specified. --debug - Build with the dev profile instead the release profile. + Build with the dev profile instead the release profile. See also the + --profile option for choosing a specific profile by name. + + --profile name + Install with the given profile. See the the reference + for more + details on profiles. Manifest Options --frozen, --locked diff --git a/src/doc/man/generated_txt/cargo-run.txt b/src/doc/man/generated_txt/cargo-run.txt index 918f161b5d2..7afb34ae04e 100644 --- a/src/doc/man/generated_txt/cargo-run.txt +++ b/src/doc/man/generated_txt/cargo-run.txt @@ -72,8 +72,13 @@ OPTIONS documentation for more details. --release - Run optimized artifacts with the release profile. See the PROFILES - section for details on how this affects profile selection. + Run optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. + + --profile name + Run with the given profile. See the the reference + for more + details on profiles. --ignore-rust-version Run the target even if the selected Rust compiler is older than the @@ -192,28 +197,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-rustc.txt b/src/doc/man/generated_txt/cargo-rustc.txt index d8d18ccaedf..1a02a7e05c8 100644 --- a/src/doc/man/generated_txt/cargo-rustc.txt +++ b/src/doc/man/generated_txt/cargo-rustc.txt @@ -134,8 +134,30 @@ OPTIONS documentation for more details. --release - Build optimized artifacts with the release profile. See the PROFILES - section for details on how this affects profile selection. + Build optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. + + --profile name + Build with the given profile. + + The rustc subcommand will treat the following named profiles with + special behaviors: + + o check — Builds in the same way as the cargo-check(1) command + with the dev profile. + + o test — Builds in the same way as the cargo-test(1) command, + enabling building in test mode which will enable tests and enable + the test cfg option. See rustc tests + for more + detail. + + o bench — Builds in the same was as the cargo-bench(1) command, + similar to the test profile. + + See the the reference + for more + details on profiles. --ignore-rust-version Build the target even if the selected Rust compiler is older than @@ -254,28 +276,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-rustdoc.txt b/src/doc/man/generated_txt/cargo-rustdoc.txt index 628bbcfe595..4d47a2318aa 100644 --- a/src/doc/man/generated_txt/cargo-rustdoc.txt +++ b/src/doc/man/generated_txt/cargo-rustdoc.txt @@ -143,8 +143,13 @@ OPTIONS documentation for more details. --release - Document optimized artifacts with the release profile. See the - PROFILES section for details on how this affects profile selection. + Document optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. + + --profile name + Document with the given profile. See the the reference + for more + details on profiles. --ignore-rust-version Document the target even if the selected Rust compiler is older than @@ -263,28 +268,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - ENVIRONMENT See the reference diff --git a/src/doc/man/generated_txt/cargo-test.txt b/src/doc/man/generated_txt/cargo-test.txt index e554e938c38..e0a4c1d94cc 100644 --- a/src/doc/man/generated_txt/cargo-test.txt +++ b/src/doc/man/generated_txt/cargo-test.txt @@ -220,8 +220,13 @@ OPTIONS documentation for more details. --release - Test optimized artifacts with the release profile. See the PROFILES - section for details on how this affects profile selection. + Test optimized artifacts with the release profile. See also the + --profile option for choosing a specific profile by name. + + --profile name + Test with the given profile. See the the reference + for more + details on profiles. --ignore-rust-version Test the target even if the selected Rust compiler is older than the @@ -352,36 +357,6 @@ OPTIONS . Defaults to the number of CPUs. -PROFILES - Profiles may be used to configure compiler options such as optimization - levels and debug settings. See the reference - for more - details. - - Profile selection depends on the target and crate being built. By - default the dev or test profiles are used. If the --release flag is - given, then the release or bench profiles are used. - - +----------------------------------------+-------------+--------------+ - | Target | Default | --release | - | | Profile | Profile | - +----------------------------------------+-------------+--------------+ - | lib, bin, example | dev | release | - +----------------------------------------+-------------+--------------+ - | test, bench, or any target in "test" | test | bench | - | or "bench" mode | | | - +----------------------------------------+-------------+--------------+ - - Dependencies use the dev/release profiles. - - Unit tests are separate executable artifacts which use the test/bench - profiles. Example targets are built the same as with cargo build (using - the dev/release profiles) unless you are building them with the test - harness (by setting test = true in the manifest or using the --example - flag) in which case they use the test/bench profiles. Library targets - are built with the dev/release profiles when linked to an integration - test, binary, or doctest. - ENVIRONMENT See the reference diff --git a/src/doc/man/includes/options-profile-legacy-check.md b/src/doc/man/includes/options-profile-legacy-check.md new file mode 100644 index 00000000000..0ec82e69399 --- /dev/null +++ b/src/doc/man/includes/options-profile-legacy-check.md @@ -0,0 +1,10 @@ +{{#option "`--profile` _name_" }} +{{actionverb}} with the given profile. + +As a special case, specifying the `test` profile will also enable checking in +test mode which will enable checking tests and enable the `test` cfg option. +See [rustc tests](https://doc.rust-lang.org/rustc/tests/index.html) for more +detail. + +See the [the reference](../reference/profiles.html) for more details on profiles. +{{/option}} diff --git a/src/doc/man/includes/options-profile.md b/src/doc/man/includes/options-profile.md index 275bbef7bb2..2452e7b1441 100644 --- a/src/doc/man/includes/options-profile.md +++ b/src/doc/man/includes/options-profile.md @@ -1,7 +1,4 @@ {{#option "`--profile` _name_" }} -Changes {{lower actionverb}} behavior. Currently only `test` is supported, -which will {{lower actionverb}} with the `#[cfg(test)]` attribute enabled. -This is useful to have it {{lower actionverb}} unit tests which are usually -excluded via the `cfg` attribute. This does not change the actual profile -used. +{{actionverb}} with the given profile. +See the [the reference](../reference/profiles.html) for more details on profiles. {{/option}} diff --git a/src/doc/man/includes/options-release.md b/src/doc/man/includes/options-release.md index 4ee0fe6d628..ad77c274e4a 100644 --- a/src/doc/man/includes/options-release.md +++ b/src/doc/man/includes/options-release.md @@ -1,5 +1,4 @@ {{#option "`--release`"}} -{{actionverb}} optimized artifacts with the `release` profile. See the -[PROFILES](#profiles) section for details on how this affects profile -selection. +{{actionverb}} optimized artifacts with the `release` profile. +See also the `--profile` option for choosing a specific profile by name. {{/option}} diff --git a/src/doc/man/includes/section-profiles.md b/src/doc/man/includes/section-profiles.md deleted file mode 100644 index d0a407213cd..00000000000 --- a/src/doc/man/includes/section-profiles.md +++ /dev/null @@ -1,16 +0,0 @@ -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. diff --git a/src/doc/src/commands/cargo-bench.md b/src/doc/src/commands/cargo-bench.md index ce58f230758..3352230b5f7 100644 --- a/src/doc/src/commands/cargo-bench.md +++ b/src/doc/src/commands/cargo-bench.md @@ -46,6 +46,14 @@ function to handle running benchmarks. > running benchmarks on the stable channel, such as > [Criterion](https://crates.io/crates/criterion). +By default, `cargo bench` uses the [`bench` profile], which enables +optimizations and disables debugging information. If you need to debug a +benchmark, you can use the `--profile=dev` command-line option to switch to +the dev profile. You can then run the debug-enabled benchmark within a +debugger. + +[`bench` profile]: ../reference/profiles.html#bench + ## OPTIONS ### Benchmark Options @@ -245,6 +253,12 @@ target artifacts are placed in a separate directory. See the +
--profile name
+
Benchmark with the given profile. +See the the reference for more details on profiles.
+ + +
--ignore-rust-version
Benchmark the target even if the selected Rust compiler is older than the required Rust version as configured in the project's rust-version field.
@@ -402,23 +416,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See -[the reference](../reference/profiles.html) -for more details. - -Benchmarks are always built with the `bench` profile. Binary and lib targets -are built separately as benchmarks with the `bench` profile. Library targets -are built with the `release` profiles when linked to binaries and benchmarks. -Dependencies use the `release` profile. - -If you need a debug build of a benchmark, try building it with -[cargo-build(1)](cargo-build.html) which will use the `test` profile which is by default -unoptimized and includes debug information. You can then run the debug-enabled -benchmark manually. - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-build.md b/src/doc/src/commands/cargo-build.md index fb372dc0007..c7f5d6290f9 100644 --- a/src/doc/src/commands/cargo-build.md +++ b/src/doc/src/commands/cargo-build.md @@ -182,9 +182,14 @@ target artifacts are placed in a separate directory. See the
--release
-
Build optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Build optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
+ + + +
--profile name
+
Build with the given profile. +See the the reference for more details on profiles.
@@ -351,24 +356,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-check.md b/src/doc/src/commands/cargo-check.md index 28340b26ac9..a1f319a2bc6 100644 --- a/src/doc/src/commands/cargo-check.md +++ b/src/doc/src/commands/cargo-check.md @@ -187,18 +187,18 @@ target artifacts are placed in a separate directory. See the
--release
-
Check optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Check optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
--profile name
-
Changes check behavior. Currently only test is supported, -which will check with the #[cfg(test)] attribute enabled. -This is useful to have it check unit tests which are usually -excluded via the cfg attribute. This does not change the actual profile -used.
+
Check with the given profile.

+

As a special case, specifying the test profile will also enable checking in +test mode which will enable checking tests and enable the test cfg option. +See rustc tests for more +detail.

+

See the the reference for more details on profiles.

@@ -347,24 +347,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-clean.md b/src/doc/src/commands/cargo-clean.md index 33d6dc0e936..ba32e8bfdfa 100644 --- a/src/doc/src/commands/cargo-clean.md +++ b/src/doc/src/commands/cargo-clean.md @@ -41,7 +41,11 @@ the target directory.
--release
-
Clean all artifacts that were built with the release or bench profiles.
+
Remove all artifacts in the release directory.
+ + +
--profile name
+
Remove all artifacts in the directory with the given profile name.
--target-dir directory
diff --git a/src/doc/src/commands/cargo-doc.md b/src/doc/src/commands/cargo-doc.md index 774169816c9..51f37dedd74 100644 --- a/src/doc/src/commands/cargo-doc.md +++ b/src/doc/src/commands/cargo-doc.md @@ -165,9 +165,14 @@ target artifacts are placed in a separate directory. See the
--release
-
Document optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Document optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
+ + + +
--profile name
+
Document with the given profile. +See the the reference for more details on profiles.
@@ -316,24 +321,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-fix.md b/src/doc/src/commands/cargo-fix.md index 534520188d3..100da109e7e 100644 --- a/src/doc/src/commands/cargo-fix.md +++ b/src/doc/src/commands/cargo-fix.md @@ -267,18 +267,18 @@ target artifacts are placed in a separate directory. See the
--release
-
Fix optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Fix optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
--profile name
-
Changes fix behavior. Currently only test is supported, -which will fix with the #[cfg(test)] attribute enabled. -This is useful to have it fix unit tests which are usually -excluded via the cfg attribute. This does not change the actual profile -used.
+
Fix with the given profile.

+

As a special case, specifying the test profile will also enable checking in +test mode which will enable checking tests and enable the test cfg option. +See rustc tests for more +detail.

+

See the the reference for more details on profiles.

@@ -427,24 +427,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-install.md b/src/doc/src/commands/cargo-install.md index 1639b28cb6e..acb98dbb79c 100644 --- a/src/doc/src/commands/cargo-install.md +++ b/src/doc/src/commands/cargo-install.md @@ -49,7 +49,7 @@ change, then Cargo will reinstall the package: - The package version and source. - The set of binary names installed. - The chosen features. -- The release mode (`--debug`). +- The profile (`--profile`). - The target (`--target`). Installing with `--path` will always build and install, unless there are @@ -226,7 +226,14 @@ is specified.
--debug
-
Build with the dev profile instead the release profile.
+
Build with the dev profile instead the release profile. +See also the --profile option for choosing a specific profile by name.
+ + +
--profile name
+
Install with the given profile. +See the the reference for more details on profiles.
+ diff --git a/src/doc/src/commands/cargo-run.md b/src/doc/src/commands/cargo-run.md index d7cf9ec5fb9..79c51ab19c2 100644 --- a/src/doc/src/commands/cargo-run.md +++ b/src/doc/src/commands/cargo-run.md @@ -100,9 +100,14 @@ target artifacts are placed in a separate directory. See the
--release
-
Run optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Run optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
+ + + +
--profile name
+
Run with the given profile. +See the the reference for more details on profiles.
@@ -255,24 +260,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-rustc.md b/src/doc/src/commands/cargo-rustc.md index 65dbeee3fff..99b780d14af 100644 --- a/src/doc/src/commands/cargo-rustc.md +++ b/src/doc/src/commands/cargo-rustc.md @@ -169,12 +169,27 @@ target artifacts are placed in a separate directory. See the
--release
-
Build optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Build optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
+
--profile name
+
Build with the given profile.

+

The rustc subcommand will treat the following named profiles with special behaviors:

+
    +
  • check — Builds in the same way as the cargo-check(1) command with +the dev profile.
  • +
  • test — Builds in the same way as the cargo-test(1) command, +enabling building in test mode which will enable tests and enable the test +cfg option. See rustc +tests for more detail.
  • +
  • bench — Builds in the same was as the cargo-bench(1) command, +similar to the test profile.
  • +
+

See the the reference for more details on profiles.

+ +
--ignore-rust-version
Build the target even if the selected Rust compiler is older than the required Rust version as configured in the project's rust-version field.
@@ -324,24 +339,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-rustdoc.md b/src/doc/src/commands/cargo-rustdoc.md index 96de095f821..a7847f1ed7c 100644 --- a/src/doc/src/commands/cargo-rustdoc.md +++ b/src/doc/src/commands/cargo-rustdoc.md @@ -184,9 +184,14 @@ target artifacts are placed in a separate directory. See the
--release
-
Document optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Document optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
+ + + +
--profile name
+
Document with the given profile. +See the the reference for more details on profiles.
@@ -335,24 +340,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/commands/cargo-test.md b/src/doc/src/commands/cargo-test.md index e2daf71f681..1eef72fc2d0 100644 --- a/src/doc/src/commands/cargo-test.md +++ b/src/doc/src/commands/cargo-test.md @@ -263,9 +263,14 @@ target artifacts are placed in a separate directory. See the
--release
-
Test optimized artifacts with the release profile. See the -PROFILES section for details on how this affects profile -selection.
+
Test optimized artifacts with the release profile. +See also the --profile option for choosing a specific profile by name.
+ + + +
--profile name
+
Test with the given profile. +See the the reference for more details on profiles.
@@ -432,32 +437,6 @@ the number of CPUs. -## PROFILES - -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See [the reference](../reference/profiles.html) for more -details. - -Profile selection depends on the target and crate being built. By default the -`dev` or `test` profiles are used. If the `--release` flag is given, then the -`release` or `bench` profiles are used. - -Target | Default Profile | `--release` Profile --------|-----------------|--------------------- -lib, bin, example | `dev` | `release` -test, bench, or any target in "test" or "bench" mode | `test` | `bench` - -Dependencies use the `dev`/`release` profiles. - - -Unit tests are separate executable artifacts which use the `test`/`bench` -profiles. Example targets are built the same as with `cargo build` (using the -`dev`/`release` profiles) unless you are building them with the test harness -(by setting `test = true` in the manifest or using the `--example` flag) in -which case they use the `test`/`bench` profiles. Library targets are built -with the `dev`/`release` profiles when linked to an integration test, binary, -or doctest. - ## ENVIRONMENT See [the reference](../reference/environment-variables.html) for diff --git a/src/doc/src/guide/build-cache.md b/src/doc/src/guide/build-cache.md index 18bb2df0b7a..a8453f615fb 100644 --- a/src/doc/src/guide/build-cache.md +++ b/src/doc/src/guide/build-cache.md @@ -9,21 +9,27 @@ value, or the `--target-dir` command-line flag. The directory layout depends on whether or not you are using the `--target` flag to build for a specific platform. If `--target` is not specified, Cargo runs in a mode where it builds for the host architecture. The output goes into -the root of the target directory, separated based on whether or not it is a -release build: +the root of the target directory, with each [profile] stored in a separate +subdirectory: Directory | Description ----------|------------ -target/debug/ | Contains debug build output. -target/release/ | Contains release build output (with `--release` flag). +target/debug/ | Contains output for the `dev` profile. +target/release/ | Contains output for the `release` profile (with the `--release` option). +target/foo/ | Contains build output for the `foo` profile (with the `--profile=foo` option). + +For historical reasons, the `dev` and `test` profiles are stored in the +`debug` directory, and the `release` and `bench` profiles are stored in the +`release` directory. User-defined profiles are stored in a directory with the +same name as the profile. When building for another target with `--target`, the output is placed in a directory with the name of the target: Directory | Example ----------|-------- -target/<triple>/debug/target/thumbv7em-none-eabihf/debug/ -target/<triple>/release/target/thumbv7em-none-eabihf/release/ +target/<triple>/debug/ | target/thumbv7em-none-eabihf/debug/ +target/<triple>/release/ | target/thumbv7em-none-eabihf/release/ > **Note**: When not using `--target`, this has a consequence that Cargo will > share your dependencies with build scripts and proc macros. [`RUSTFLAGS`] @@ -31,13 +37,13 @@ Directory | Example > build scripts and proc macros are built separately (for the host > architecture), and do not share `RUSTFLAGS`. -Within the profile directory (`debug` or `release`), artifacts are placed into -the following directories: +Within the profile directory (such as `debug` or `release`), artifacts are +placed into the following directories: Directory | Description ----------|------------ -target/debug/ | Contains the output of the package being built (the `[[bin]]` executables and `[lib]` library targets). -target/debug/examples/ | Contains examples (`[[example]]` targets). +target/debug/ | Contains the output of the package being built (the [binary executables] and [library targets]). +target/debug/examples/ | Contains [example targets]. Some commands place their output in dedicated directories in the top level of the `target` directory: @@ -53,9 +59,9 @@ change. Some of these directories are: Directory | Description ----------|------------ -target/debug/deps/ |  Dependencies and other artifacts. -target/debug/incremental/ |  `rustc` [incremental output], a cache used to speed up subsequent builds. -target/debug/build/ |  Output from [build scripts]. +target/debug/deps/ | Dependencies and other artifacts. +target/debug/incremental/ | `rustc` [incremental output], a cache used to speed up subsequent builds. +target/debug/build/ | Output from [build scripts]. ### Dep-info files @@ -95,3 +101,7 @@ configuration][config]. Refer to sccache documentation for more details. [environment variable]: ../reference/environment-variables.md [incremental output]: ../reference/profiles.md#incremental [sccache]: https://github.com/mozilla/sccache +[profile]: ../reference/profiles.md +[binary executables]: ../reference/cargo-targets.md#binaries +[library targets]: ../reference/cargo-targets.md#library +[example targets]: ../reference/cargo-targets.md#examples diff --git a/src/doc/src/images/profile-selection.svg b/src/doc/src/images/profile-selection.svg deleted file mode 100644 index 4975383bf76..00000000000 --- a/src/doc/src/images/profile-selection.svg +++ /dev/null @@ -1,3 +0,0 @@ - - -
lib
profile: dev
lib<br>profile: dev
lib (unit test)
profile: test
[Not supported by viewer]
dependency1
profile: dev
[Not supported by viewer]
integration test
profile: test
[Not supported by viewer]
bin (unit test)
profile: test
[Not supported by viewer]
bin (executable)
profile: dev
bin (executable)<br>profile: dev
dependency2
profile: dev
[Not supported by viewer]
dependency3
profile: dev
[Not supported by viewer]
Executables
[Not supported by viewer]
Profile selection for cargo test
Profile selection for <font face="Courier New">cargo test</font>
\ No newline at end of file diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 72f035d68e0..b0a2bb34d63 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -333,7 +333,11 @@ let out_dir = env::var("OUT_DIR").unwrap(); compatible [jobserver] for sub-make invocations. * `OPT_LEVEL`, `DEBUG` — values of the corresponding variables for the profile currently being built. -* `PROFILE` — `release` for release builds, `debug` for other builds. +* `PROFILE` — `release` for release builds, `debug` for other builds. This is + determined based on if the [profile] inherits from the [`dev`] or + [`release`] profile. Using this environment variable is not recommended. + Using other environment variables like `OPT_LEVEL` provide a more correct + view of the actual settings being used. * `DEP__` — For more information about this set of environment variables, see build script documentation about [`links`][links]. * `RUSTC`, `RUSTDOC` — the compiler and documentation generator that Cargo has @@ -371,6 +375,9 @@ let out_dir = env::var("OUT_DIR").unwrap(); [cargo-config]: config.md [Target Triple]: ../appendix/glossary.md#target [variables set for crates]: #environment-variables-cargo-sets-for-crates +[profile]: profiles.md +[`dev`]: profiles.md#dev +[`release`]: profiles.md#release ### Environment variables Cargo sets for 3rd party subcommands diff --git a/src/doc/src/reference/profiles.md b/src/doc/src/reference/profiles.md index 1f4248a1533..1732c491e72 100644 --- a/src/doc/src/reference/profiles.md +++ b/src/doc/src/reference/profiles.md @@ -3,10 +3,10 @@ Profiles provide a way to alter the compiler settings, influencing things like optimizations and debugging symbols. -Cargo has 4 built-in profiles: `dev`, `release`, `test`, and `bench`. It -automatically chooses the profile based on which command is being run, the -package and target that is being built, and command-line flags like -`--release`. The selection process is [described below](#profile-selection). +Cargo has 4 built-in profiles: `dev`, `release`, `test`, and `bench`. The +profile is automatically chosen based on which command is being run if a +profile is not specified on the command-line. In addition to the built-in +profiles, custom user-defined profiles can also be specified. Profile settings can be changed in [`Cargo.toml`](manifest.md) with the `[profile]` table. Within each named profile, individual settings can be changed @@ -267,44 +267,14 @@ rpath = false #### test The `test` profile is used for building tests, or when benchmarks are built in -debug mode with `cargo build`. - -The default settings for the `test` profile are: - -```toml -[profile.test] -opt-level = 0 -debug = 2 -split-debuginfo = '...' # Platform-specific. -debug-assertions = true -overflow-checks = true -lto = false -panic = 'unwind' # This setting is always ignored. -incremental = true -codegen-units = 256 -rpath = false -``` +debug mode with `cargo build`. By default, the `test` profile inherits the +settings from the [`dev`](#dev) profile. #### bench The `bench` profile is used for building benchmarks, or when tests are built -with the `--release` flag. - -The default settings for the `bench` profile are: - -```toml -[profile.bench] -opt-level = 3 -debug = false -split-debuginfo = '...' # Platform-specific. -debug-assertions = false -overflow-checks = false -lto = false -panic = 'unwind' # This setting is always ignored. -incremental = false -codegen-units = 16 -rpath = false -``` +with the `--release` flag. By default, the `bench` profile inherits the +settings from the [`release`](#release) profile. #### Build Dependencies @@ -325,35 +295,50 @@ codegen-units = 256 Build dependencies otherwise inherit settings from the active profile in use, as described below. -### Profile selection +### Custom profiles + +In addition to the built-in profiles, additional custom profiles can be +defined. These may be useful for setting up multiple workflows and build +modes. When defining a custom profile, you must specify the `inherits` key to +specify which profile the custom profile inherits settings from when the +setting is not specified. + +For example, let's say you want to compare a normal release build with a +release build with [LTO](#lto) optimizations, you can specify something like +the following in `Cargo.toml`: + +```toml +[profile.release-lto] +inherits = "release" +lto = true +``` -The profile used depends on the command, the package, the Cargo target, and -command-line flags like `--release`. +The `--profile` flag can then be used to choose this custom profile: -Build commands like [`cargo build`], [`cargo rustc`], [`cargo check`], and -[`cargo run`] default to using the `dev` profile. The `--release` flag may be -used to switch to the `release` profile. +```console +cargo build --profile release-lto +``` -The [`cargo install`] command defaults to the `release` profile, and may use -the `--debug` flag to switch to the `dev` profile. +The output for each profile will be placed in a directory of the same name +as the profile in the [`target` directory]. As in the example above, the +output would go into the `target/release-lto` directory. -Test targets are built with the `test` profile by default. The `--release` -flag switches tests to the `bench` profile. +[`target` directory]: ../guide/build-cache.md -Bench targets are built with the `bench` profile by default. The [`cargo -build`] command can be used to build a bench target with the `test` profile to -enable debugging. +### Profile selection -Note that when using the [`cargo test`] and [`cargo bench`] commands, the -`test`/`bench` profiles only apply to the final test executable. Dependencies -will continue to use the `dev`/`release` profiles. Also note that when a -library is built for unit tests, then the library is built with the `test` -profile. However, when building an integration test target, the library target -is built with the `dev` profile and linked into the integration test -executable. +The profile used depends on the command, the command-line flags like +`--release` or `--profile`, and the package (in the case of +[overrides](#overrides)). The default profile if none is specified is: -![Profile selection for cargo test](../images/profile-selection.svg) +* Build commands like [`cargo build`], [`cargo rustc`], [`cargo check`], and +[`cargo run`]: [`dev` profile](#dev) +* [`cargo test`]: [`test` profile](#test) +* [`cargo bench`]: [`bench` profile](#bench) +* [`cargo install`]: [`release` profile](#release) +The profile for specific packages can be specified with +[overrides](#overrides), described below. [`cargo bench`]: ../commands/cargo-bench.md [`cargo build`]: ../commands/cargo-build.md diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index c27b0085582..ae550d7e5c2 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -87,7 +87,6 @@ Each new feature described below should explain how to use it. * [`doctest-in-workspace`](#doctest-in-workspace) — Fixes workspace-relative paths when running doctests. * [rustdoc-map](#rustdoc-map) — Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/). * `Cargo.toml` extensions - * [Custom named profiles](#custom-named-profiles) — Adds custom named profiles in addition to the standard names. * [Profile `strip` option](#profile-strip-option) — Forces the removal of debug information and symbols from executables. * [per-package-target](#per-package-target) — Sets the `--target` to use for each individual package. * Information and metadata @@ -238,49 +237,6 @@ or running tests for both targets: cargo test --target x86_64-unknown-linux-gnu --target i686-unknown-linux-gnu ``` -### Custom named profiles - -* Tracking Issue: [rust-lang/cargo#6988](https://github.com/rust-lang/cargo/issues/6988) -* RFC: [#2678](https://github.com/rust-lang/rfcs/pull/2678) - -With this feature you can define custom profiles having new names. With the -custom profile enabled, build artifacts can be emitted by default to -directories other than `release` or `debug`, based on the custom profile's -name. - -For example: - -```toml -cargo-features = ["named-profiles"] - -[profile.release-lto] -inherits = "release" -lto = true -```` - -An `inherits` key is used in order to receive attributes from other profiles, -so that a new custom profile can be based on the standard `dev` or `release` -profile presets. Cargo emits errors in case `inherits` loops are detected. When -considering inheritance hierarchy, all profiles directly or indirectly inherit -from either from `release` or from `dev`. - -Valid profile names are: must not be empty, use only alphanumeric characters or -`-` or `_`. - -Passing `--profile` with the profile's name to various Cargo commands, directs -operations to use the profile's attributes. Overrides that are specified in the -profiles from which the custom profile inherits are inherited too. - -For example, using `cargo build` with `--profile` and the manifest from above: - -```sh -cargo +nightly build --profile release-lto -Z unstable-options -``` - -When a custom profile is used, build artifacts go to a different target by -default. In the example above, you can expect to see the outputs under -`target/release-lto`. - #### New `dir-name` attribute @@ -1421,3 +1377,8 @@ information. The 2021 edition has been stabilized in the 1.56 release. See the [`edition` field](manifest.md#the-edition-field) for more information on setting the edition. See [`cargo fix --edition`](../commands/cargo-fix.md) and [The Edition Guide](../../edition-guide/index.html) for more information on migrating existing projects. + +### Custom named profiles + +Custom named profiles have been stabilized in the 1.57 release. See the +[profiles chapter](profiles.md#custom-profiles) for more information. diff --git a/src/etc/man/cargo-bench.1 b/src/etc/man/cargo-bench.1 index a8239d002d9..5d8df036bfb 100644 --- a/src/etc/man/cargo-bench.1 +++ b/src/etc/man/cargo-bench.1 @@ -50,6 +50,12 @@ running benchmarks on the stable channel, such as .br .RE .ll +.sp +By default, \fBcargo bench\fR uses the \fI\f(BIbench\fI profile\fR , which enables +optimizations and disables debugging information. If you need to debug a +benchmark, you can use the \fB\-\-profile=dev\fR command\-line option to switch to +the dev profile. You can then run the debug\-enabled benchmark within a +debugger. .SH "OPTIONS" .SS "Benchmark Options" .sp @@ -251,6 +257,12 @@ target artifacts are placed in a separate directory. See the \fIbuild cache\fR documentation for more details. .RE .sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Benchmark with the given profile. +See the \fIthe reference\fR for more details on profiles. +.RE +.sp \fB\-\-ignore\-rust\-version\fR .RS 4 Benchmark the target even if the selected Rust compiler is older than the @@ -420,21 +432,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See -\fIthe reference\fR -for more details. -.sp -Benchmarks are always built with the \fBbench\fR profile. Binary and lib targets -are built separately as benchmarks with the \fBbench\fR profile. Library targets -are built with the \fBrelease\fR profiles when linked to binaries and benchmarks. -Dependencies use the \fBrelease\fR profile. -.sp -If you need a debug build of a benchmark, try building it with -\fBcargo\-build\fR(1) which will use the \fBtest\fR profile which is by default -unoptimized and includes debug information. You can then run the debug\-enabled -benchmark manually. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1 index 4eaea1bc5a7..bdee1436b94 100644 --- a/src/etc/man/cargo-build.1 +++ b/src/etc/man/cargo-build.1 @@ -171,9 +171,14 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Build optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Build optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Build with the given profile. +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -354,43 +359,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-check.1 b/src/etc/man/cargo-check.1 index 7c6b2ea17d2..a1456e9832e 100644 --- a/src/etc/man/cargo-check.1 +++ b/src/etc/man/cargo-check.1 @@ -176,18 +176,20 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Check optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Check optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. .RE .sp \fB\-\-profile\fR \fIname\fR .RS 4 -Changes check behavior. Currently only \fBtest\fR is supported, -which will check with the \fB#[cfg(test)]\fR attribute enabled. -This is useful to have it check unit tests which are usually -excluded via the \fBcfg\fR attribute. This does not change the actual profile -used. +Check with the given profile. +.sp +As a special case, specifying the \fBtest\fR profile will also enable checking in +test mode which will enable checking tests and enable the \fBtest\fR cfg option. +See \fIrustc tests\fR for more +detail. +.sp +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -347,43 +349,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-clean.1 b/src/etc/man/cargo-clean.1 index 0836166e677..01823d991d8 100644 --- a/src/etc/man/cargo-clean.1 +++ b/src/etc/man/cargo-clean.1 @@ -33,7 +33,12 @@ the target directory. .sp \fB\-\-release\fR .RS 4 -Clean all artifacts that were built with the \fBrelease\fR or \fBbench\fR profiles. +Remove all artifacts in the \fBrelease\fR directory. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Remove all artifacts in the directory with the given profile name. .RE .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1 index 045795bb3ac..32ac9feaf11 100644 --- a/src/etc/man/cargo-doc.1 +++ b/src/etc/man/cargo-doc.1 @@ -149,9 +149,14 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Document optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Document optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Document with the given profile. +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -311,43 +316,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1 index 57eb1da015f..97c34bb0139 100644 --- a/src/etc/man/cargo-fix.1 +++ b/src/etc/man/cargo-fix.1 @@ -271,18 +271,20 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Fix optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Fix optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. .RE .sp \fB\-\-profile\fR \fIname\fR .RS 4 -Changes fix behavior. Currently only \fBtest\fR is supported, -which will fix with the \fB#[cfg(test)]\fR attribute enabled. -This is useful to have it fix unit tests which are usually -excluded via the \fBcfg\fR attribute. This does not change the actual profile -used. +Fix with the given profile. +.sp +As a special case, specifying the \fBtest\fR profile will also enable checking in +test mode which will enable checking tests and enable the \fBtest\fR cfg option. +See \fIrustc tests\fR for more +detail. +.sp +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -442,43 +444,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-install.1 b/src/etc/man/cargo-install.1 index 1840182a258..139140279cb 100644 --- a/src/etc/man/cargo-install.1 +++ b/src/etc/man/cargo-install.1 @@ -71,7 +71,7 @@ change, then Cargo will reinstall the package: .RE .sp .RS 4 -\h'-04'\(bu\h'+02'The release mode (\fB\-\-debug\fR). +\h'-04'\(bu\h'+02'The profile (\fB\-\-profile\fR). .RE .sp .RS 4 @@ -258,6 +258,13 @@ is specified. \fB\-\-debug\fR .RS 4 Build with the \fBdev\fR profile instead the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Install with the given profile. +See the \fIthe reference\fR for more details on profiles. .RE .SS "Manifest Options" .sp diff --git a/src/etc/man/cargo-run.1 b/src/etc/man/cargo-run.1 index c4ff6e444bf..c332d94bda4 100644 --- a/src/etc/man/cargo-run.1 +++ b/src/etc/man/cargo-run.1 @@ -82,9 +82,14 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Run optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Run optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Run with the given profile. +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -244,43 +249,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-rustc.1 b/src/etc/man/cargo-rustc.1 index 5a69821c6e1..6daf5a3f37e 100644 --- a/src/etc/man/cargo-rustc.1 +++ b/src/etc/man/cargo-rustc.1 @@ -157,9 +157,34 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Build optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Build optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Build with the given profile. +.sp +The \fBrustc\fR subcommand will treat the following named profiles with special behaviors: +.sp +.RS 4 +\h'-04'\(bu\h'+02'\fBcheck\fR \[em] Builds in the same way as the \fBcargo\-check\fR(1) command with +the \fBdev\fR profile. +.RE +.sp +.RS 4 +\h'-04'\(bu\h'+02'\fBtest\fR \[em] Builds in the same way as the \fBcargo\-test\fR(1) command, +enabling building in test mode which will enable tests and enable the \fBtest\fR +cfg option. See \fIrustc +tests\fR for more detail. +.RE +.sp +.RS 4 +\h'-04'\(bu\h'+02'\fBbench\fR \[em] Builds in the same was as the \fBcargo\-bench\fR(1) command, +similar to the \fBtest\fR profile. +.RE +.sp +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -319,43 +344,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-rustdoc.1 b/src/etc/man/cargo-rustdoc.1 index 2a9af8cf6b1..ad5cfbb187e 100644 --- a/src/etc/man/cargo-rustdoc.1 +++ b/src/etc/man/cargo-rustdoc.1 @@ -168,9 +168,14 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Document optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Document optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Document with the given profile. +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -330,43 +335,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/src/etc/man/cargo-test.1 b/src/etc/man/cargo-test.1 index bafeb08662e..ee0d3cf3929 100644 --- a/src/etc/man/cargo-test.1 +++ b/src/etc/man/cargo-test.1 @@ -268,9 +268,14 @@ target artifacts are placed in a separate directory. See the .sp \fB\-\-release\fR .RS 4 -Test optimized artifacts with the \fBrelease\fR profile. See the -PROFILES section for details on how this affects profile -selection. +Test optimized artifacts with the \fBrelease\fR profile. +See also the \fB\-\-profile\fR option for choosing a specific profile by name. +.RE +.sp +\fB\-\-profile\fR \fIname\fR +.RS 4 +Test with the given profile. +See the \fIthe reference\fR for more details on profiles. .RE .sp \fB\-\-ignore\-rust\-version\fR @@ -448,51 +453,6 @@ Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to the number of CPUs. .RE -.SH "PROFILES" -Profiles may be used to configure compiler options such as optimization levels -and debug settings. See \fIthe reference\fR for more -details. -.sp -Profile selection depends on the target and crate being built. By default the -\fBdev\fR or \fBtest\fR profiles are used. If the \fB\-\-release\fR flag is given, then the -\fBrelease\fR or \fBbench\fR profiles are used. - -.TS -allbox tab(:); -lt lt lt. -T{ -Target -T}:T{ -Default Profile -T}:T{ -\fB\-\-release\fR Profile -T} -T{ -lib, bin, example -T}:T{ -\fBdev\fR -T}:T{ -\fBrelease\fR -T} -T{ -test, bench, or any target in "test" or "bench" mode -T}:T{ -\fBtest\fR -T}:T{ -\fBbench\fR -T} -.TE -.sp -.sp -Dependencies use the \fBdev\fR/\fBrelease\fR profiles. -.sp -Unit tests are separate executable artifacts which use the \fBtest\fR/\fBbench\fR -profiles. Example targets are built the same as with \fBcargo build\fR (using the -\fBdev\fR/\fBrelease\fR profiles) unless you are building them with the test harness -(by setting \fBtest = true\fR in the manifest or using the \fB\-\-example\fR flag) in -which case they use the \fBtest\fR/\fBbench\fR profiles. Library targets are built -with the \fBdev\fR/\fBrelease\fR profiles when linked to an integration test, binary, -or doctest. .SH "ENVIRONMENT" See \fIthe reference\fR for details on environment variables that Cargo reads. diff --git a/tests/testsuite/lto.rs b/tests/testsuite/lto.rs index 5b431fdb298..a7d92934d04 100644 --- a/tests/testsuite/lto.rs +++ b/tests/testsuite/lto.rs @@ -351,6 +351,15 @@ fn test_all_and_bench() { .run(); } +/// Basic setup: +/// +/// foo v0.0.0 +/// ├── bar v0.0.0 +/// │ ├── registry v0.0.1 +/// │ └── registry-shared v0.0.1 +/// └── registry-shared v0.0.1 +/// +/// Where `bar` will have the given crate types. fn project_with_dep(crate_types: &str) -> Project { Package::new("registry", "0.0.1") .file("src/lib.rs", r#"pub fn foo() { println!("registry"); }"#) @@ -419,6 +428,10 @@ fn project_with_dep(crate_types: &str) -> Project { .build() } +/// Helper for checking which LTO behavior is used for a specific crate. +/// +/// `krate_info` is extra compiler flags used to distinguish this if the same +/// crate name is being built multiple times. fn verify_lto(output: &Output, krate: &str, krate_info: &str, expected_lto: Lto) { let stderr = std::str::from_utf8(&output.stderr).unwrap(); let mut matches = stderr.lines().filter(|line| { @@ -467,18 +480,22 @@ fn verify_lto(output: &Output, krate: &str, krate_info: &str, expected_lto: Lto) fn cdylib_and_rlib() { let p = project_with_dep("'cdylib', 'rlib'"); let output = p.cargo("build --release -v").exec_with_output().unwrap(); + // `registry` is ObjectAndBitcode because because it needs Object for the + // rlib, and Bitcode for the cdylib (which doesn't support LTO). verify_lto( &output, "registry", "--crate-type lib", Lto::ObjectAndBitcode, ); + // Same as `registry` verify_lto( &output, "registry_shared", "--crate-type lib", Lto::ObjectAndBitcode, ); + // Same as `registry` verify_lto( &output, "bar", @@ -493,8 +510,8 @@ fn cdylib_and_rlib() { [FRESH] registry-shared v0.0.1 [FRESH] bar v0.0.0 [..] [COMPILING] foo [..] -[RUNNING] `rustc --crate-name foo [..]-C embed-bitcode=no [..]--test[..] -[RUNNING] `rustc --crate-name a [..]-C embed-bitcode=no [..]--test[..] +[RUNNING] `rustc --crate-name foo [..]-C lto [..]--test[..] +[RUNNING] `rustc --crate-name a [..]-C lto [..]--test[..] [FINISHED] [..] [RUNNING] [..] [RUNNING] [..] @@ -514,19 +531,16 @@ fn cdylib_and_rlib() { p.cargo("test --release -v --manifest-path bar/Cargo.toml") .with_stderr_unordered( "\ -[COMPILING] registry v0.0.1 -[COMPILING] registry-shared v0.0.1 -[RUNNING] `rustc --crate-name registry [..]-C embed-bitcode=no[..] -[RUNNING] `rustc --crate-name registry_shared [..]-C embed-bitcode=no[..] +[FRESH] registry-shared v0.0.1 +[FRESH] registry v0.0.1 [COMPILING] bar [..] -[RUNNING] `rustc --crate-name bar [..]--crate-type cdylib --crate-type rlib [..]-C embed-bitcode=no[..] -[RUNNING] `rustc --crate-name bar [..]-C embed-bitcode=no [..]--test[..] -[RUNNING] `rustc --crate-name b [..]-C embed-bitcode=no [..]--test[..] +[RUNNING] `rustc --crate-name bar [..]-C lto[..]--test[..] +[RUNNING] `rustc --crate-name b [..]-C lto[..]--test[..] [FINISHED] [..] [RUNNING] [..]target/release/deps/bar-[..] [RUNNING] [..]target/release/deps/b-[..] [DOCTEST] bar -[RUNNING] `rustdoc --crate-type cdylib --crate-type rlib --crate-name bar --test [..]-C embed-bitcode=no[..] +[RUNNING] `rustdoc --crate-type cdylib --crate-type rlib --crate-name bar --test [..]-C lto[..] ", ) .run(); @@ -536,15 +550,23 @@ fn cdylib_and_rlib() { fn dylib() { let p = project_with_dep("'dylib'"); let output = p.cargo("build --release -v").exec_with_output().unwrap(); + // `registry` is OnlyObject because rustc doesn't support LTO with dylibs. verify_lto(&output, "registry", "--crate-type lib", Lto::OnlyObject); + // `registry_shared` is both because it is needed by both bar (Object) and + // foo (Bitcode for LTO). verify_lto( &output, "registry_shared", "--crate-type lib", Lto::ObjectAndBitcode, ); + // `bar` is OnlyObject because rustc doesn't support LTO with dylibs. verify_lto(&output, "bar", "--crate-type dylib", Lto::OnlyObject); + // `foo` is LTO because it is a binary, and the profile specifies `lto=true`. verify_lto(&output, "foo", "--crate-type bin", Lto::Run(None)); + // `cargo test` should not rebuild dependencies. It builds the test + // executables with `lto=true` because the tests are built with the + // `--release` flag. p.cargo("test --release -v") .with_stderr_unordered( "\ @@ -552,14 +574,19 @@ fn dylib() { [FRESH] registry-shared v0.0.1 [FRESH] bar v0.0.0 [..] [COMPILING] foo [..] -[RUNNING] `rustc --crate-name foo [..]-C embed-bitcode=no [..]--test[..] -[RUNNING] `rustc --crate-name a [..]-C embed-bitcode=no [..]--test[..] +[RUNNING] `rustc --crate-name foo [..]-C lto [..]--test[..] +[RUNNING] `rustc --crate-name a [..]-C lto [..]--test[..] [FINISHED] [..] [RUNNING] [..] [RUNNING] [..] ", ) .run(); + // Building just `bar` causes `registry-shared` to get rebuilt because it + // switches to OnlyObject because it is now only being used with a dylib + // which does not support LTO. + // + // `bar` gets rebuilt because `registry_shared` got rebuilt. p.cargo("build --release -v --manifest-path bar/Cargo.toml") .with_stderr_unordered( "\ @@ -572,14 +599,21 @@ fn dylib() { ", ) .run(); + // Testing just `bar` causes `registry` to get rebuilt because it switches + // to needing both Object (for the `bar` dylib) and Bitcode (for the test + // built with LTO). + // + // `bar` the dylib gets rebuilt because `registry` got rebuilt. p.cargo("test --release -v --manifest-path bar/Cargo.toml") .with_stderr_unordered( "\ [FRESH] registry-shared v0.0.1 -[FRESH] registry v0.0.1 +[COMPILING] registry v0.0.1 +[RUNNING] `rustc --crate-name registry [..] [COMPILING] bar [..] -[RUNNING] `rustc --crate-name bar [..]-C embed-bitcode=no [..]--test[..] -[RUNNING] `rustc --crate-name b [..]-C embed-bitcode=no [..]--test[..] +[RUNNING] `rustc --crate-name bar [..]--crate-type dylib [..]-C embed-bitcode=no[..] +[RUNNING] `rustc --crate-name bar [..]-C lto [..]--test[..] +[RUNNING] `rustc --crate-name b [..]-C lto [..]--test[..] [FINISHED] [..] [RUNNING] [..] [RUNNING] [..] @@ -640,59 +674,6 @@ fn test_profile() { .run(); } -#[cargo_test] -fn dev_profile() { - // Mixing dev=LTO with test=not-LTO - Package::new("bar", "0.0.1") - .file("src/lib.rs", "pub fn foo() -> i32 { 123 } ") - .publish(); - - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2018" - - [profile.dev] - lto = 'thin' - - [dependencies] - bar = "*" - "#, - ) - .file( - "src/lib.rs", - r#" - #[test] - fn t1() { - assert_eq!(123, bar::foo()); - } - "#, - ) - .build(); - - p.cargo("test -v") - // unordered because the two `foo` builds start in parallel - .with_stderr_unordered("\ -[UPDATING] [..] -[DOWNLOADING] [..] -[DOWNLOADED] [..] -[COMPILING] bar v0.0.1 -[RUNNING] `rustc --crate-name bar [..]crate-type lib[..] -[COMPILING] foo [..] -[RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no [..] -[RUNNING] `rustc --crate-name foo [..]--emit=dep-info,link -C embed-bitcode=no [..]--test[..] -[FINISHED] [..] -[RUNNING] [..] -[DOCTEST] foo -[RUNNING] `rustdoc [..] -") - .run(); -} - #[cargo_test] fn doctest() { let p = project() @@ -732,18 +713,24 @@ fn doctest() { .build(); p.cargo("test --doc --release -v") - .with_stderr_contains("[..]`rustc --crate-name bar[..]-C embed-bitcode=no[..]") - .with_stderr_contains("[..]`rustc --crate-name foo[..]-C embed-bitcode=no[..]") + .with_stderr_contains("[..]`rustc --crate-name bar[..]-C linker-plugin-lto[..]") + .with_stderr_contains("[..]`rustc --crate-name foo[..]-C linker-plugin-lto[..]") // embed-bitcode should be harmless here - .with_stderr_contains("[..]`rustdoc [..]-C embed-bitcode=no[..]") + .with_stderr_contains("[..]`rustdoc [..]-C lto[..]") .run(); // Try with bench profile. p.cargo("test --doc --release -v") .env("CARGO_PROFILE_BENCH_LTO", "true") - .with_stderr_contains("[..]`rustc --crate-name bar[..]-C linker-plugin-lto[..]") - .with_stderr_contains("[..]`rustc --crate-name foo[..]-C linker-plugin-lto[..]") - .with_stderr_contains("[..]`rustdoc [..]-C lto[..]") + .with_stderr_unordered( + "\ +[FRESH] bar v0.1.0 [..] +[FRESH] foo v0.1.0 [..] +[FINISHED] release [..] +[DOCTEST] foo +[RUNNING] `rustdoc [..]-C lto[..] +", + ) .run(); } @@ -821,15 +808,13 @@ fn fresh_swapping_commands() { p.cargo("test --release -v") .with_stderr_unordered( "\ -[COMPILING] bar v1.0.0 -[RUNNING] `rustc --crate-name bar [..]-C embed-bitcode=no[..] +[FRESH] bar v1.0.0 [COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib[..]-C embed-bitcode=no[..] -[RUNNING] `rustc --crate-name foo src/lib.rs [..]-C embed-bitcode=no[..]--test[..] +[RUNNING] `rustc --crate-name foo src/lib.rs [..]-C lto[..]--test[..] [FINISHED] [..] [RUNNING] `[..]/foo[..]` [DOCTEST] foo -[RUNNING] `rustdoc [..]-C embed-bitcode=no[..] +[RUNNING] `rustdoc [..]-C lto[..] ", ) .run(); diff --git a/tests/testsuite/profile_config.rs b/tests/testsuite/profile_config.rs index f7e98add1f7..1678a57917a 100644 --- a/tests/testsuite/profile_config.rs +++ b/tests/testsuite/profile_config.rs @@ -4,41 +4,6 @@ use cargo_test_support::paths::CargoPathExt; use cargo_test_support::registry::Package; use cargo_test_support::{basic_lib_manifest, paths, project}; -#[cargo_test] -fn named_profile_gated() { - // Named profile in config requires enabling in Cargo.toml. - let p = project() - .file("src/lib.rs", "") - .file( - ".cargo/config", - r#" - [profile.foo] - inherits = 'dev' - opt-level = 1 - "#, - ) - .build(); - p.cargo("build --profile foo -Zunstable-options") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[ERROR] config profile `foo` is not valid (defined in `[..]/foo/.cargo/config`) - -Caused by: - feature `named-profiles` is required - - The package requires the Cargo feature called `named-profiles`, \ - but that feature is not stabilized in this version of Cargo (1.[..]). - Consider adding `cargo-features = [\"named-profiles\"]` to the top of Cargo.toml \ - (above the [package] table) to tell Cargo you are opting in to use this unstable feature. - See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#custom-named-profiles \ - for more information about the status of this feature. -", - ) - .with_status(101) - .run(); -} - #[cargo_test] fn profile_config_validate_warnings() { let p = project() @@ -378,8 +343,6 @@ fn named_config_profile() { fs::write( paths::root().join("Cargo.toml"), r#" - cargo-features = ['named-profiles'] - [workspace] [profile.middle] @@ -397,7 +360,7 @@ fn named_config_profile() { "#, ) .unwrap(); - let config = ConfigBuilder::new().nightly_features_allowed(true).build(); + let config = ConfigBuilder::new().build(); let profile_name = InternedString::new("foo"); let ws = Workspace::new(&paths::root().join("Cargo.toml"), &config).unwrap(); let profiles = Profiles::new(&ws, profile_name).unwrap(); @@ -443,7 +406,6 @@ fn named_env_profile() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] [package] name = "foo" version = "0.1.0" @@ -452,8 +414,7 @@ fn named_env_profile() { .file("src/lib.rs", "") .build(); - p.cargo("build -v -Zunstable-options --profile=other") - .masquerade_as_nightly_cargo() + p.cargo("build -v --profile=other") .env("CARGO_PROFILE_OTHER_CODEGEN_UNITS", "1") .env("CARGO_PROFILE_OTHER_INHERITS", "dev") .with_stderr_contains("[..]-C codegen-units=1 [..]") @@ -462,7 +423,8 @@ fn named_env_profile() { #[cargo_test] fn test_with_dev_profile() { - // `cargo test` uses "dev" profile for dependencies. + // The `test` profile inherits from `dev` for both local crates and + // dependencies. Package::new("somedep", "1.0.0").publish(); let p = project() .file( @@ -488,7 +450,7 @@ fn test_with_dev_profile() { [COMPILING] somedep v1.0.0 [RUNNING] `rustc --crate-name somedep [..]-C debuginfo=0[..] [COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo [..]-C debuginfo=2[..] +[RUNNING] `rustc --crate-name foo [..]-C debuginfo=0[..] [FINISHED] [..] ", ) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 1307b4e071b..889665baf87 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -3,31 +3,12 @@ use cargo_test_support::paths::CargoPathExt; use cargo_test_support::{basic_lib_manifest, project}; -#[cargo_test] -fn gated() { - let p = project().file("src/lib.rs", "").build(); - // `rustc`, `fix`, and `check` have had `--profile` before custom named profiles. - // Without unstable, these shouldn't be allowed to access non-legacy names. - for command in [ - "rustc", "fix", "check", "bench", "clean", "install", "test", "build", "doc", "run", - "rustdoc", - ] { - p.cargo(command) - .arg("--profile=release") - .with_status(101) - .with_stderr("error: usage of `--profile` requires `-Z unstable-options`") - .run(); - } -} - #[cargo_test] fn inherits_on_release() { let p = project() .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -41,7 +22,6 @@ fn inherits_on_release() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -57,8 +37,6 @@ fn missing_inherits() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -72,7 +50,6 @@ fn missing_inherits() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -89,8 +66,6 @@ fn invalid_profile_name() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -105,7 +80,6 @@ fn invalid_profile_name() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -126,8 +100,6 @@ fn invalid_dir_name() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -143,7 +115,6 @@ fn invalid_dir_name() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -161,8 +132,6 @@ fn dir_name_disabled() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.1.0" @@ -177,7 +146,6 @@ fn dir_name_disabled() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -197,8 +165,6 @@ fn invalid_inherits() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -213,7 +179,6 @@ fn invalid_inherits() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "error: profile `release-lto` inherits from `.release`, \ @@ -228,8 +193,6 @@ fn non_existent_inherits() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -244,7 +207,6 @@ fn non_existent_inherits() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -260,8 +222,6 @@ fn self_inherits() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -276,7 +236,6 @@ fn self_inherits() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -292,8 +251,6 @@ fn inherits_loop() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -312,7 +269,6 @@ fn inherits_loop() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -328,8 +284,6 @@ fn overrides_with_custom() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -365,7 +319,6 @@ fn overrides_with_custom() { // profile overrides are inherited between profiles using inherits and have a // higher priority than profile options provided by custom profiles p.cargo("build -v") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [COMPILING] xxx [..] @@ -380,8 +333,7 @@ fn overrides_with_custom() { .run(); // This also verifies that the custom profile names appears in the finished line. - p.cargo("build --profile=other -Z unstable-options -v") - .masquerade_as_nightly_cargo() + p.cargo("build --profile=other -v") .with_stderr_unordered( "\ [COMPILING] xxx [..] @@ -408,11 +360,44 @@ fn conflicting_usage() { authors = [] "#, ) - .file("src/lib.rs", "") + .file("src/main.rs", "fn main() {}") .build(); - p.cargo("build -Z unstable-options --profile=dev --release") - .masquerade_as_nightly_cargo() + p.cargo("build --profile=dev --release") + .with_status(101) + .with_stderr( + "\ +error: conflicting usage of --profile=dev and --release +The `--release` flag is the same as `--profile=release`. +Remove one flag or the other to continue. +", + ) + .run(); + + p.cargo("install --profile=release --debug") + .with_status(101) + .with_stderr( + "\ +error: conflicting usage of --profile=release and --debug +The `--debug` flag is the same as `--profile=dev`. +Remove one flag or the other to continue. +", + ) + .run(); + + p.cargo("rustc --profile=dev --release") + .with_stderr( + "\ +warning: the `--release` flag should not be specified with the `--profile` flag +The `--release` flag will be ignored. +This was historically accepted, but will become an error in a future release. +[COMPILING] foo [..] +[FINISHED] dev [..] +", + ) + .run(); + + p.cargo("check --profile=dev --release") .with_status(101) .with_stderr( "\ @@ -423,8 +408,49 @@ Remove one flag or the other to continue. ) .run(); - p.cargo("install -Z unstable-options --profile=release --debug") - .masquerade_as_nightly_cargo() + p.cargo("check --profile=test --release") + .with_stderr( + "\ +warning: the `--release` flag should not be specified with the `--profile` flag +The `--release` flag will be ignored. +This was historically accepted, but will become an error in a future release. +[CHECKING] foo [..] +[FINISHED] test [..] +", + ) + .run(); + + // This is OK since the two are the same. + p.cargo("rustc --profile=release --release") + .with_stderr( + "\ +[COMPILING] foo [..] +[FINISHED] release [..] +", + ) + .run(); + + p.cargo("build --profile=release --release") + .with_stderr( + "\ +[FINISHED] release [..] +", + ) + .run(); + + p.cargo("install --path . --profile=dev --debug") + .with_stderr( + "\ +[INSTALLING] foo [..] +[FINISHED] dev [..] +[INSTALLING] [..] +[INSTALLED] [..] +[WARNING] be sure to add [..] +", + ) + .run(); + + p.cargo("install --path . --profile=release --debug") .with_status(101) .with_stderr( "\ @@ -442,8 +468,6 @@ fn clean_custom_dirname() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -457,7 +481,6 @@ fn clean_custom_dirname() { .build(); p.cargo("build --release") - .masquerade_as_nightly_cargo() .with_stdout("") .with_stderr( "\ @@ -470,7 +493,6 @@ fn clean_custom_dirname() { p.cargo("clean -p foo").masquerade_as_nightly_cargo().run(); p.cargo("build --release") - .masquerade_as_nightly_cargo() .with_stdout("") .with_stderr( "\ @@ -479,12 +501,9 @@ fn clean_custom_dirname() { ) .run(); - p.cargo("clean -p foo --release") - .masquerade_as_nightly_cargo() - .run(); + p.cargo("clean -p foo --release").run(); p.cargo("build --release") - .masquerade_as_nightly_cargo() .with_stderr( "\ [COMPILING] foo v0.0.1 ([..]) @@ -494,7 +513,6 @@ fn clean_custom_dirname() { .run(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_stdout("") .with_stderr( "\ @@ -504,8 +522,7 @@ fn clean_custom_dirname() { ) .run(); - p.cargo("build -Z unstable-options --profile=other") - .masquerade_as_nightly_cargo() + p.cargo("build --profile=other") .with_stderr( "\ [COMPILING] foo v0.0.1 ([..]) @@ -514,10 +531,7 @@ fn clean_custom_dirname() { ) .run(); - p.cargo("clean") - .arg("--release") - .masquerade_as_nightly_cargo() - .run(); + p.cargo("clean").arg("--release").run(); // Make sure that 'other' was not cleaned assert!(p.build_dir().is_dir()); @@ -526,10 +540,7 @@ fn clean_custom_dirname() { assert!(!p.build_dir().join("release").is_dir()); // This should clean 'other' - p.cargo("clean -Z unstable-options --profile=other") - .masquerade_as_nightly_cargo() - .with_stderr("") - .run(); + p.cargo("clean --profile=other").with_stderr("").run(); assert!(p.build_dir().join("debug").is_dir()); assert!(!p.build_dir().join("other").is_dir()); } @@ -540,8 +551,6 @@ fn unknown_profile() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.0.1" @@ -550,14 +559,12 @@ fn unknown_profile() { .file("src/lib.rs", "") .build(); - p.cargo("build --profile alpha -Zunstable-options") - .masquerade_as_nightly_cargo() + p.cargo("build --profile alpha") .with_stderr("[ERROR] profile `alpha` is not defined") .with_status(101) .run(); // Clean has a separate code path, need to check it too. - p.cargo("clean --profile alpha -Zunstable-options") - .masquerade_as_nightly_cargo() + p.cargo("clean --profile alpha") .with_stderr("[ERROR] profile `alpha` is not defined") .with_status(101) .run(); @@ -580,15 +587,13 @@ fn reserved_profile_names() { .file("src/lib.rs", "") .build(); - p.cargo("build --profile=doc -Zunstable-options") - .masquerade_as_nightly_cargo() + p.cargo("build --profile=doc") .with_status(101) .with_stderr("error: profile `doc` is reserved and not allowed to be explicitly specified") .run(); // Not an exhaustive list, just a sample. for name in ["build", "cargo", "check", "rustc", "CaRgO_startswith"] { - p.cargo(&format!("build --profile={} -Zunstable-options", name)) - .masquerade_as_nightly_cargo() + p.cargo(&format!("build --profile={}", name)) .with_status(101) .with_stderr(&format!( "\ @@ -605,8 +610,6 @@ See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configur "Cargo.toml", &format!( r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.1.0" @@ -619,7 +622,6 @@ See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configur ); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr(&format!( "\ @@ -638,8 +640,6 @@ Caused by: p.change_file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.1.0" @@ -652,7 +652,6 @@ Caused by: ); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "\ @@ -674,8 +673,6 @@ fn legacy_commands_support_custom() { .file( "Cargo.toml", r#" - cargo-features = ["named-profiles"] - [package] name = "foo" version = "0.1.0" @@ -694,9 +691,7 @@ fn legacy_commands_support_custom() { pb.arg("--allow-no-vcs"); } pb.arg("--profile=super-dev") - .arg("-Zunstable-options") .arg("-v") - .masquerade_as_nightly_cargo() .with_stderr_contains("[RUNNING] [..]codegen-units=3[..]") .run(); p.build_dir().rm_rf(); diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 045f2a3e065..74d54385ff1 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -2,7 +2,7 @@ //! example, the `test` profile applying to test targets, but not other //! targets, etc. -use cargo_test_support::{basic_manifest, is_nightly, project, Project}; +use cargo_test_support::{basic_manifest, project, Project}; fn all_target_project() -> Project { // This abuses the `codegen-units` setting so that we can verify exactly @@ -10,41 +10,32 @@ fn all_target_project() -> Project { project() .file( "Cargo.toml", - &format!( - r#" - cargo-features = [{named_profiles}] - - [package] - name = "foo" - version = "0.0.1" + r#" + [package] + name = "foo" + version = "0.0.1" - [dependencies] - bar = {{ path = "bar" }} + [dependencies] + bar = { path = "bar" } - [build-dependencies] - bdep = {{ path = "bdep" }} + [build-dependencies] + bdep = { path = "bdep" } - [profile.dev] - codegen-units = 1 - panic = "abort" - [profile.release] - codegen-units = 2 - panic = "abort" - [profile.test] - codegen-units = 3 - [profile.bench] - codegen-units = 4 - [profile.dev.build-override] - codegen-units = 5 - [profile.release.build-override] - codegen-units = 6 - "#, - named_profiles = if is_nightly() { - "\"named-profiles\", " - } else { - "" - } - ), + [profile.dev] + codegen-units = 1 + panic = "abort" + [profile.release] + codegen-units = 2 + panic = "abort" + [profile.test] + codegen-units = 3 + [profile.bench] + codegen-units = 4 + [profile.dev.build-override] + codegen-units = 5 + [profile.release.build-override] + codegen-units = 6 + "#, ) .file("src/lib.rs", "extern crate bar;") .file("src/main.rs", "extern crate foo; fn main() {}") @@ -91,7 +82,7 @@ fn profile_selection_build() { // NOTES: // - bdep `panic` is not set because it thinks `build.rs` is a plugin. // - build_script_build is built without panic because it thinks `build.rs` is a plugin. - p.cargo("build -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ + p.cargo("build -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] @@ -106,7 +97,6 @@ fn profile_selection_build() { [FINISHED] dev [unoptimized + debuginfo] [..] ").run(); p.cargo("build -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -123,7 +113,7 @@ fn profile_selection_build_release() { let p = all_target_project(); // `build --release` - p.cargo("build --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ + p.cargo("build --release -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=6 [..] @@ -138,7 +128,6 @@ fn profile_selection_build_release() { [FINISHED] release [optimized] [..] ").run(); p.cargo("build --release -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -153,7 +142,6 @@ fn profile_selection_build_release() { #[cargo_test] fn profile_selection_build_all_targets() { let p = all_target_project(); - let affected = if is_nightly() { 1 } else { 3 }; // `build` // NOTES: // - bdep `panic` is not set because it thinks `build.rs` is a plugin. @@ -181,7 +169,7 @@ fn profile_selection_build_all_targets() { // bin dev dev // bin dev build // example dev build - p.cargo("build --all-targets -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ + p.cargo("build --all-targets -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..] @@ -193,17 +181,16 @@ fn profile_selection_build_all_targets() { [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link[..]-C codegen-units={affected} -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]-C codegen-units={affected} -C debuginfo=2 --test [..]` -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link[..]-C codegen-units={affected} -C debuginfo=2 --test [..]` -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link[..]-C codegen-units={affected} -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]` [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]` [FINISHED] dev [unoptimized + debuginfo] [..] -", affected=affected)).run(); +").run(); p.cargo("build -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -218,7 +205,6 @@ fn profile_selection_build_all_targets() { #[cargo_test] fn profile_selection_build_all_targets_release() { let p = all_target_project(); - let affected = if is_nightly() { 2 } else { 4 }; // `build --all-targets --release` // NOTES: // - bdep `panic` is not set because it thinks `build.rs` is a plugin. @@ -249,7 +235,7 @@ fn profile_selection_build_all_targets_release() { // bin release test (bench/test de-duped) // bin release build // example release build - p.cargo("build --all-targets --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ + p.cargo("build --all-targets --release -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..]-C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..] @@ -261,17 +247,16 @@ fn profile_selection_build_all_targets_release() { [RUNNING] `[..]/target/release/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units={affected} --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..]-C codegen-units=2 [..]` -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units={affected} --test [..]` -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units={affected} --test [..]` -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units={affected} --test [..]` +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=2 --test [..]` +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..]` [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..]` [FINISHED] release [optimized] [..] -", affected=affected)).run(); +").run(); p.cargo("build --all-targets --release -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -286,7 +271,6 @@ fn profile_selection_build_all_targets_release() { #[cargo_test] fn profile_selection_test() { let p = all_target_project(); - let affected = if is_nightly() { 3 } else { 1 }; // `test` // NOTES: // - Dependency profiles: @@ -308,33 +292,32 @@ fn profile_selection_test() { // bin test test // bin test build // - p.cargo("test -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ + p.cargo("test -vv").with_stderr_unordered("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=3 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=3 -C debuginfo=2 [..] [COMPILING] bdep [..] [RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] [COMPILING] foo [..] [RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units={affected} -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=3 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link[..]-C codegen-units=3 -C debuginfo=2 --test [..] [RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link[..]-C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=3 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]-C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort[..]-C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort[..]-C codegen-units=3 -C debuginfo=2 [..] [FINISHED] test [unoptimized + debuginfo] [..] [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo [RUNNING] `rustdoc [..]--test [..] -", affected=affected)).run(); +").run(); p.cargo("test -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -354,7 +337,6 @@ fn profile_selection_test() { #[cargo_test] fn profile_selection_test_release() { let p = all_target_project(); - let affected = if is_nightly() { 2 } else { 4 }; // `test --release` // NOTES: @@ -377,7 +359,7 @@ fn profile_selection_test_release() { // bin release test // bin release build // - p.cargo("test --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ + p.cargo("test --release -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=6 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..] @@ -390,9 +372,9 @@ fn profile_selection_test_release() { [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..]-C codegen-units=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units={affected} --test [..] -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units={affected} --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units={affected} --test [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=2 --test [..] +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=2 --test [..] [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C opt-level=3[..]-C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=2 [..] [FINISHED] release [optimized] [..] @@ -401,9 +383,8 @@ fn profile_selection_test_release() { [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo [RUNNING] `rustdoc [..]--test [..]` -", affected=affected)).run(); +").run(); p.cargo("test --release -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -423,7 +404,6 @@ fn profile_selection_test_release() { #[cargo_test] fn profile_selection_bench() { let p = all_target_project(); - let affected = if is_nightly() { 4 } else { 2 }; // `bench` // NOTES: @@ -445,10 +425,10 @@ fn profile_selection_bench() { // bin bench test(bench) // bin bench build // - p.cargo("bench -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ + p.cargo("bench -vv").with_stderr_unordered("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..]-C codegen-units={affected} [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units={affected} [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..]-C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=4 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=6 [..] [COMPILING] bdep [..] [RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=6 [..] @@ -456,19 +436,18 @@ fn profile_selection_bench() { [RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=6 [..] [RUNNING] `[..]target/release/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units={affected} [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..]-C codegen-units={affected} [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..]-C codegen-units=4 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=4 --test [..] [RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=4 --test [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3[..]-C codegen-units=4 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units={affected} [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort[..]-C codegen-units=4 [..] [FINISHED] bench [optimized] [..] [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/bench1-[..] --bench` -", affected=affected)).run(); +").run(); p.cargo("bench -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -511,7 +490,7 @@ fn profile_selection_check_all_targets() { // bin dev check // bin dev-panic check-test (checking bin as a unittest) // - p.cargo("check --all-targets -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ + p.cargo("check --all-targets -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata[..]-C codegen-units=1 -C debuginfo=2 [..] @@ -537,7 +516,6 @@ fn profile_selection_check_all_targets() { // rechecked. // See PR rust-lang/rust#49289 and issue rust-lang/cargo#3624. p.cargo("check --all-targets -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -557,7 +535,7 @@ fn profile_selection_check_all_targets_release() { // This is a pretty straightforward variant of // `profile_selection_check_all_targets` that uses `release` instead of // `dev` for all targets. - p.cargo("check --all-targets --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ + p.cargo("check --all-targets --release -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=6 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C opt-level=3[..]-C codegen-units=2 [..] @@ -580,7 +558,6 @@ fn profile_selection_check_all_targets_release() { ").run(); p.cargo("check --all-targets --release -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -595,7 +572,6 @@ fn profile_selection_check_all_targets_release() { #[cargo_test] fn profile_selection_check_all_targets_test() { let p = all_target_project(); - let affected = if is_nightly() { 3 } else { 1 }; // `check --profile=test` // - Dependency profiles: @@ -618,27 +594,26 @@ fn profile_selection_check_all_targets_test() { // bench test-panic check-test // bin test-panic check-test // - p.cargo("check --all-targets --profile=test -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ + p.cargo("check --all-targets --profile=test -vv").with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata[..]-C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata[..]-C codegen-units=3 -C debuginfo=2 [..] [COMPILING] bdep[..] [RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] [COMPILING] foo [..] [RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..] [RUNNING] `[..]target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]metadata[..]-C codegen-units={affected} -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]metadata[..]-C codegen-units={affected} -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]metadata[..]-C codegen-units={affected} -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]metadata[..]-C codegen-units={affected} -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]metadata[..]-C codegen-units={affected} -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--emit=[..]metadata[..]-C codegen-units={affected} -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]metadata[..]-C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]metadata[..]-C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]metadata[..]-C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]metadata[..]-C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]metadata[..]-C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--emit=[..]metadata[..]-C codegen-units=3 -C debuginfo=2 --test [..] [FINISHED] test [unoptimized + debuginfo] [..] -", affected=affected)).run(); +").run(); p.cargo("check --all-targets --profile=test -vv") - .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -664,7 +639,7 @@ fn profile_selection_doc() { // foo custom dev* link For build.rs // // `*` = wants panic, but it is cleared when args are built. - p.cargo("doc -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ + p.cargo("doc -vv").with_stderr_unordered("\ [COMPILING] bar [..] [DOCUMENTING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=2 [..]