Stabilize named profiles.

This commit is contained in:
Eric Huss 2021-09-23 21:55:42 -07:00
parent 39ed55e3b9
commit 895f52714c
60 changed files with 650 additions and 1299 deletions

View file

@ -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<Option<Vec<String>>, 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))

View file

@ -20,6 +20,11 @@ pub struct Profiles {
dir_names: HashMap<InternedString, InternedString>,
/// The profile makers. Key is the profile name.
by_name: HashMap<InternedString, ProfileMaker>,
/// 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<InternedString, TomlProfile>,
/// 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<TomlProfile>,
}

View file

@ -353,7 +353,7 @@ pub trait ArgMatchesExt {
fn get_profile_name(
&self,
config: &Config,
_config: &Config,
default: &str,
profile_checking: ProfileChecking,
) -> CargoResult<InternedString> {
@ -369,10 +369,6 @@ pub trait ArgMatchesExt {
_ => {}
}
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\

View file

@ -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 }}

View file

@ -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 <https://github.com/rust-lang/cargo/issues/5579> for more information.
{{> options-jobs }}
{{/options}}
{{> section-profiles }}
{{> section-environment }}
{{> section-exit-status }}

View file

@ -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 }}

View file

@ -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 }}

View file

@ -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 }}

View file

@ -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 }}

View file

@ -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

View file

@ -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 }}

View file

@ -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 }}

View file

@ -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 }}

View file

@ -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 }}

View file

@ -41,6 +41,13 @@ DESCRIPTION
benchmarks on the stable channel, such as Criterion
<https://crates.io/crates/criterion>.
By default, cargo bench uses the bench profile
<https://doc.rust-lang.org/cargo/reference/profiles.html#bench>, 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
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
documentation for more details.
--profile name
Benchmark with the given profile. See the the reference
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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) 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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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
<https://doc.rust-lang.org/rustc/tests/index.html> for more detail.
See the the reference
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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

View file

@ -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
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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
<https://doc.rust-lang.org/rustc/tests/index.html> for more detail.
See the the reference
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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
<https://doc.rust-lang.org/cargo/reference/profiles.html> for more
details on profiles.
Manifest Options
--frozen, --locked

View file

@ -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
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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
<https://doc.rust-lang.org/rustc/tests/index.html> 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
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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
<https://doc.rust-lang.org/cargo/reference/profiles.html> 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
<https://doc.rust-lang.org/cargo/reference/config.html>. 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
<https://doc.rust-lang.org/cargo/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 | --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
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>

View file

@ -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}}

View file

@ -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}}

View file

@ -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}}

View file

@ -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.

View file

@ -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
<dt class="option-term" id="option-cargo-bench---profile"><a class="option-anchor" href="#option-cargo-bench---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Benchmark with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
<dt class="option-term" id="option-cargo-bench---ignore-rust-version"><a class="option-anchor" href="#option-cargo-bench---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Benchmark the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
@ -402,23 +416,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -182,9 +182,14 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-build---release"><a class="option-anchor" href="#option-cargo-build---release"></a><code>--release</code></dt>
<dd class="option-desc">Build optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Build optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-build---profile"><a class="option-anchor" href="#option-cargo-build---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Build with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
@ -351,24 +356,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -187,18 +187,18 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-check---release"><a class="option-anchor" href="#option-cargo-check---release"></a><code>--release</code></dt>
<dd class="option-desc">Check optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Check optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-check---profile"><a class="option-anchor" href="#option-cargo-check---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Changes check behavior. Currently only <code>test</code> is supported,
which will check with the <code>#[cfg(test)]</code> attribute enabled.
This is useful to have it check unit tests which are usually
excluded via the <code>cfg</code> attribute. This does not change the actual profile
used.</dd>
<dd class="option-desc">Check with the given profile.</p>
<p>As a special case, specifying the <code>test</code> profile will also enable checking in
test mode which will enable checking tests and enable the <code>test</code> cfg option.
See <a href="https://doc.rust-lang.org/rustc/tests/index.html">rustc tests</a> for more
detail.</p>
<p>See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
@ -347,24 +347,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -41,7 +41,11 @@ the target directory.</dd>
<dt class="option-term" id="option-cargo-clean---release"><a class="option-anchor" href="#option-cargo-clean---release"></a><code>--release</code></dt>
<dd class="option-desc">Clean all artifacts that were built with the <code>release</code> or <code>bench</code> profiles.</dd>
<dd class="option-desc">Remove all artifacts in the <code>release</code> directory.</dd>
<dt class="option-term" id="option-cargo-clean---profile"><a class="option-anchor" href="#option-cargo-clean---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Remove all artifacts in the directory with the given profile name.</dd>
<dt class="option-term" id="option-cargo-clean---target-dir"><a class="option-anchor" href="#option-cargo-clean---target-dir"></a><code>--target-dir</code> <em>directory</em></dt>

View file

@ -165,9 +165,14 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-doc---release"><a class="option-anchor" href="#option-cargo-doc---release"></a><code>--release</code></dt>
<dd class="option-desc">Document optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Document optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-doc---profile"><a class="option-anchor" href="#option-cargo-doc---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Document with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
@ -316,24 +321,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -267,18 +267,18 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-fix---release"><a class="option-anchor" href="#option-cargo-fix---release"></a><code>--release</code></dt>
<dd class="option-desc">Fix optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Fix optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-fix---profile"><a class="option-anchor" href="#option-cargo-fix---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Changes fix behavior. Currently only <code>test</code> is supported,
which will fix with the <code>#[cfg(test)]</code> attribute enabled.
This is useful to have it fix unit tests which are usually
excluded via the <code>cfg</code> attribute. This does not change the actual profile
used.</dd>
<dd class="option-desc">Fix with the given profile.</p>
<p>As a special case, specifying the <code>test</code> profile will also enable checking in
test mode which will enable checking tests and enable the <code>test</code> cfg option.
See <a href="https://doc.rust-lang.org/rustc/tests/index.html">rustc tests</a> for more
detail.</p>
<p>See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
@ -427,24 +427,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -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.</dd>
<dt class="option-term" id="option-cargo-install---debug"><a class="option-anchor" href="#option-cargo-install---debug"></a><code>--debug</code></dt>
<dd class="option-desc">Build with the <code>dev</code> profile instead the <code>release</code> profile.</dd>
<dd class="option-desc">Build with the <code>dev</code> profile instead the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-install---profile"><a class="option-anchor" href="#option-cargo-install---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Install with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
</dl>

View file

@ -100,9 +100,14 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-run---release"><a class="option-anchor" href="#option-cargo-run---release"></a><code>--release</code></dt>
<dd class="option-desc">Run optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Run optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-run---profile"><a class="option-anchor" href="#option-cargo-run---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Run with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
@ -255,24 +260,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -169,12 +169,27 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-rustc---release"><a class="option-anchor" href="#option-cargo-rustc---release"></a><code>--release</code></dt>
<dd class="option-desc">Build optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Build optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-rustc---profile"><a class="option-anchor" href="#option-cargo-rustc---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Build with the given profile.</p>
<p>The <code>rustc</code> subcommand will treat the following named profiles with special behaviors:</p>
<ul>
<li><code>check</code> — Builds in the same way as the <a href="cargo-check.html">cargo-check(1)</a> command with
the <code>dev</code> profile.</li>
<li><code>test</code> — Builds in the same way as the <a href="cargo-test.html">cargo-test(1)</a> command,
enabling building in test mode which will enable tests and enable the <code>test</code>
cfg option. See <a href="https://doc.rust-lang.org/rustc/tests/index.html">rustc
tests</a> for more detail.</li>
<li><code>bench</code> — Builds in the same was as the <a href="cargo-bench.html">cargo-bench(1)</a> command,
similar to the <code>test</code> profile.</li>
</ul>
<p>See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
<dt class="option-term" id="option-cargo-rustc---ignore-rust-version"><a class="option-anchor" href="#option-cargo-rustc---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Build the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
@ -324,24 +339,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -184,9 +184,14 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-rustdoc---release"><a class="option-anchor" href="#option-cargo-rustdoc---release"></a><code>--release</code></dt>
<dd class="option-desc">Document optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Document optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-rustdoc---profile"><a class="option-anchor" href="#option-cargo-rustdoc---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Document with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
@ -335,24 +340,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -263,9 +263,14 @@ target artifacts are placed in a separate directory. See the
<dt class="option-term" id="option-cargo-test---release"><a class="option-anchor" href="#option-cargo-test---release"></a><code>--release</code></dt>
<dd class="option-desc">Test optimized artifacts with the <code>release</code> profile. See the
<a href="#profiles">PROFILES</a> section for details on how this affects profile
selection.</dd>
<dd class="option-desc">Test optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
<dt class="option-term" id="option-cargo-test---profile"><a class="option-anchor" href="#option-cargo-test---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Test with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
@ -432,32 +437,6 @@ the number of CPUs.</dd>
</dl>
## 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

View file

@ -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
----------|------------
<code style="white-space: nowrap">target/debug/</code> | Contains debug build output.
<code style="white-space: nowrap">target/release/</code> | Contains release build output (with `--release` flag).
<code style="white-space: nowrap">target/debug/</code> | Contains output for the `dev` profile.
<code style="white-space: nowrap">target/release/</code> | Contains output for the `release` profile (with the `--release` option).
<code style="white-space: nowrap">target/foo/</code> | 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
----------|--------
<code style="white-space: nowrap">target/&lt;triple&gt;/debug/</code> | <code style="white-space: nowrap">target/thumbv7em-none-eabihf/debug/</code>
<code style="white-space: nowrap">target/&lt;triple&gt;/release/</code> | <code style="white-space: nowrap">target/thumbv7em-none-eabihf/release/</code>
<code style="white-space: nowrap">target/&lt;triple&gt;/debug/</code> | <code style="white-space: nowrap">target/thumbv7em-none-eabihf/debug/</code>
<code style="white-space: nowrap">target/&lt;triple&gt;/release/</code> | <code style="white-space: nowrap">target/thumbv7em-none-eabihf/release/</code>
> **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
----------|------------
<code style="white-space: nowrap">target/debug/</code> | Contains the output of the package being built (the `[[bin]]` executables and `[lib]` library targets).
<code style="white-space: nowrap">target/debug/examples/</code> | Contains examples (`[[example]]` targets).
<code style="white-space: nowrap">target/debug/</code> | Contains the output of the package being built (the [binary executables] and [library targets]).
<code style="white-space: nowrap">target/debug/examples/</code> | 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
----------|------------
<code style="white-space: nowrap">target/debug/deps/</code> |  Dependencies and other artifacts.
<code style="white-space: nowrap">target/debug/incremental/</code> |  `rustc` [incremental output], a cache used to speed up subsequent builds.
<code style="white-space: nowrap">target/debug/build/</code> |  Output from [build scripts].
<code style="white-space: nowrap">target/debug/deps/</code> | Dependencies and other artifacts.
<code style="white-space: nowrap">target/debug/incremental/</code> | `rustc` [incremental output], a cache used to speed up subsequent builds.
<code style="white-space: nowrap">target/debug/build/</code> | 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

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 11 KiB

View file

@ -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_<name>_<key>` — 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

View file

@ -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.
### 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` flag can then be used to choose this custom profile:
```console
cargo build --profile release-lto
```
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.
[`target` directory]: ../guide/build-cache.md
### Profile selection
The profile used depends on the command, the package, the Cargo target, and
command-line flags like `--release`.
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:
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.
The [`cargo install`] command defaults to the `release` profile, and may use
the `--debug` flag to switch to the `dev` profile.
Test targets are built with the `test` profile by default. The `--release`
flag switches tests to the `bench` profile.
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.
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.
![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

View file

@ -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.

View file

@ -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 <https://doc.rust\-lang.org/cargo/reference/profiles.html#bench>, 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 <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
.RE
.sp
\fB\-\-profile\fR \fIname\fR
.RS 4
Benchmark with the given profile.
See the \fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html>
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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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 <https://doc.rust\-lang.org/rustc/tests/index.html> for more
detail.
.sp
See the \fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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

View file

@ -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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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 <https://doc.rust\-lang.org/rustc/tests/index.html> for more
detail.
.sp
See the \fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> for more details on profiles.
.RE
.SS "Manifest Options"
.sp

View file

@ -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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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 <https://doc.rust\-lang.org/rustc/tests/index.html> 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/config.html>\&. 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 <https://doc.rust\-lang.org/cargo/reference/profiles.html> 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 <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
details on environment variables that Cargo reads.

View file

@ -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();

View file

@ -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] [..]
",
)

View file

@ -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 [..]
@ -411,8 +363,7 @@ fn conflicting_usage() {
.file("src/lib.rs", "")
.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(
"\
@ -423,8 +374,7 @@ Remove one flag or the other to continue.
)
.run();
p.cargo("install -Z unstable-options --profile=release --debug")
.masquerade_as_nightly_cargo()
p.cargo("install --profile=release --debug")
.with_status(101)
.with_stderr(
"\
@ -442,8 +392,6 @@ fn clean_custom_dirname() {
.file(
"Cargo.toml",
r#"
cargo-features = ["named-profiles"]
[package]
name = "foo"
version = "0.0.1"
@ -457,7 +405,6 @@ fn clean_custom_dirname() {
.build();
p.cargo("build --release")
.masquerade_as_nightly_cargo()
.with_stdout("")
.with_stderr(
"\
@ -470,7 +417,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 +425,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 +437,6 @@ fn clean_custom_dirname() {
.run();
p.cargo("build")
.masquerade_as_nightly_cargo()
.with_stdout("")
.with_stderr(
"\
@ -504,8 +446,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 +455,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 +464,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 +475,6 @@ fn unknown_profile() {
.file(
"Cargo.toml",
r#"
cargo-features = ["named-profiles"]
[package]
name = "foo"
version = "0.0.1"
@ -550,14 +483,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 +511,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 +534,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 +546,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 +564,6 @@ Caused by:
p.change_file(
"Cargo.toml",
r#"
cargo-features = ["named-profiles"]
[package]
name = "foo"
version = "0.1.0"
@ -652,7 +576,6 @@ Caused by:
);
p.cargo("build")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
@ -674,8 +597,6 @@ fn legacy_commands_support_custom() {
.file(
"Cargo.toml",
r#"
cargo-features = ["named-profiles"]
[package]
name = "foo"
version = "0.1.0"
@ -694,9 +615,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();

View file

@ -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}]
r#"
[package]
name = "foo"
version = "0.0.1"
[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 [..]