(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"),
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"),
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>,
"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))
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.
named_profiles_enabled: false,
dir_names: Self::predefined_dir_names(),
by_name: HashMap::new(),
+ original_profiles: profiles.clone(),
requested_profile,
rustc_host,
};
named_profiles_enabled: true,
dir_names: Self::predefined_dir_names(),
by_name: HashMap::new(),
+ original_profiles: profiles.clone(),
requested_profile,
rustc_host,
};
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
/// 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>,
}
fn get_profile_name(
&self,
- config: &Config,
+ _config: &Config,
default: &str,
profile_checking: ProfileChecking,
) -> CargoResult<InternedString> {
_ => {}
}
- 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\
> 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
{{> options-target-triple }}
+{{> options-profile }}
+
{{> options-ignore-rust-version }}
{{/options}}
{{> 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 }}
{{> options-release }}
+{{> options-profile }}
+
{{> options-ignore-rust-version }}
{{/options}}
{{> options-jobs }}
{{/options}}
-{{> section-profiles }}
-
{{> section-environment }}
{{> section-exit-status }}
{{> options-release }}
-{{> options-profile }}
+{{> options-profile-legacy-check }}
{{> options-ignore-rust-version }}
{{> options-jobs }}
{{/options}}
-{{> section-profiles }}
-
{{> section-environment }}
{{> section-exit-status }}
{{/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 }}
{{> options-release }}
+{{> options-profile }}
+
{{> options-ignore-rust-version }}
{{/options}}
{{> options-jobs }}
{{/options}}
-{{> section-profiles }}
-
{{> section-environment }}
{{> section-exit-status }}
{{> options-release }}
-{{> options-profile }}
+{{> options-profile-legacy-check }}
{{> options-ignore-rust-version }}
{{> options-jobs }}
{{/options}}
-{{> section-profiles }}
-
{{> section-environment }}
{{> section-exit-status }}
- 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
{{#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
{{> options-release }}
+{{> options-profile }}
+
{{> options-ignore-rust-version }}
{{/options}}
{{> options-jobs }}
{{/options}}
-{{> section-profiles }}
-
{{> section-environment }}
{{> section-exit-status }}
{{> 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}}
{{> options-jobs }}
{{/options}}
-{{> section-profiles }}
-
{{> section-environment }}
{{> section-exit-status }}
{{> options-release }}
+{{> options-profile }}
+
{{> options-ignore-rust-version }}
{{/options}}
{{> options-jobs }}
{{/options}}
-{{> section-profiles }}
-
{{> section-environment }}
{{> section-exit-status }}
{{> options-release }}
+{{> options-profile }}
+
{{> options-ignore-rust-version }}
{{/options}}
{{/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 }}
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
<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
<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>
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
<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>
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
<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>
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
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
<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>
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
<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>
o The chosen features.
- o The release mode (--debug).
+ o The profile (--profile).
o The target (--target).
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
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
<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>
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
<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>
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
<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>
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
<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>
--- /dev/null
+{{#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}}
{{#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}}
{{#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}}
+++ /dev/null
-## 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.
> 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
+<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>
</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
<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>
</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
<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>
</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
<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>
<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>
</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
<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>
</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
- 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
<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>
<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>
</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
<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>
</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
<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>
</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
<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>
</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
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/<triple>/debug/</code> |Â <code style="white-space: nowrap">target/thumbv7em-none-eabihf/debug/</code>
-<code style="white-space: nowrap">target/<triple>/release/</code> |Â <code style="white-space: nowrap">target/thumbv7em-none-eabihf/release/</code>
+<code style="white-space: nowrap">target/<triple>/debug/</code> | <code style="white-space: nowrap">target/thumbv7em-none-eabihf/debug/</code>
+<code style="white-space: nowrap">target/<triple>/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`]
> 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:
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
[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
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" style="background-color: rgb(255, 255, 255);" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="445px" height="277px" viewBox="-0.5 -0.5 445 277"><defs/><g><rect x="170" y="91" width="100" height="40" rx="6" ry="6" fill="#ffffff" stroke="#000000" pointer-events="all"/><g transform="translate(190.5,97.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="59" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 60px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;">lib<br />profile: dev</div></div></foreignObject><text x="30" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">lib<br>profile: dev</text></switch></g><rect x="330" y="191" width="100" height="40" rx="6" ry="6" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><g transform="translate(347.5,197.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="65" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 66px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;">lib (unit test)<br />profile: test</div></div></foreignObject><text x="33" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><rect x="10" y="41" width="100" height="40" rx="6" ry="6" fill="#ffffff" stroke="#000000" pointer-events="all"/><g transform="translate(23.5,47.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="72" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 73px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;"><div>dependency1<br /></div>profile: dev</div></div></foreignObject><text x="36" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><rect x="330" y="91" width="100" height="40" rx="6" ry="6" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><g transform="translate(340.5,97.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="79" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 80px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;">integration test<br />profile: test</div></div></foreignObject><text x="40" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><rect x="330" y="141" width="100" height="40" rx="6" ry="6" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><g transform="translate(345.5,147.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="69" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 70px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;">bin (unit test)<br />profile: test</div></div></foreignObject><text x="35" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><rect x="330" y="41" width="100" height="40" rx="6" ry="6" fill="#ffffff" stroke="#000000" pointer-events="all"/><g transform="translate(337.5,47.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="85" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 86px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;">bin (executable)<br />profile: dev</div></div></foreignObject><text x="43" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">bin (executable)<br>profile: dev</text></switch></g><rect x="10" y="91" width="100" height="40" rx="6" ry="6" fill="#ffffff" stroke="#000000" pointer-events="all"/><g transform="translate(23.5,97.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="72" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 73px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;"><div>dependency2<br /></div>profile: dev</div></div></foreignObject><text x="36" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><rect x="10" y="141" width="100" height="40" rx="6" ry="6" fill="#ffffff" stroke="#000000" pointer-events="all"/><g transform="translate(23.5,147.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="72" height="27" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 73px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;"><div>dependency3<br /></div>profile: dev</div></div></foreignObject><text x="36" y="20" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">[Not supported by viewer]</text></switch></g><path d="M 110 61 L 120 61 Q 130 61 130 71 L 130 101 Q 130 111 140 111 L 163.63 111" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 168.88 111 L 161.88 114.5 L 163.63 111 L 161.88 107.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><path d="M 110 111 L 163.63 111" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 168.88 111 L 161.88 114.5 L 163.63 111 L 161.88 107.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><path d="M 110 161 L 120 161 Q 130 161 130 151 L 130 121 Q 130 111 140 111 L 163.63 111" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 168.88 111 L 161.88 114.5 L 163.63 111 L 161.88 107.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><path d="M 270 111 L 290 111 Q 300 111 300 101 L 300 71 Q 300 61 310 61 L 323.63 61" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 328.88 61 L 321.88 64.5 L 323.63 61 L 321.88 57.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><path d="M 270 111 L 323.63 111" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 328.88 111 L 321.88 114.5 L 323.63 111 L 321.88 107.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><path d="M 270 111 L 290 111 Q 300 111 300 121 L 300 151 Q 300 161 310 161 L 323.63 161" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 328.88 161 L 321.88 164.5 L 323.63 161 L 321.88 157.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="360" y="11" width="40" height="20" fill="none" stroke="none" pointer-events="all"/><g transform="translate(325.5,9.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="109" height="22" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 20px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 110px; white-space: nowrap; overflow-wrap: normal; text-decoration: underline; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;"><div style="font-size: 20px">Executables</div></div></div></foreignObject><text x="55" y="21" fill="#000000" text-anchor="middle" font-size="20px" font-family="Helvetica" text-decoration="underline">[Not supported by viewer]</text></switch></g><rect x="22.5" y="241" width="395" height="25.48" fill="none" stroke="none" pointer-events="all"/><g transform="translate(71.5,242.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="296" height="22" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 20px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 297px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;">Profile selection for <font face="Courier New">cargo test</font></div></div></foreignObject><text x="148" y="21" fill="#000000" text-anchor="middle" font-size="20px" font-family="Helvetica">Profile selection for <font face="Courier New">cargo test</font></text></switch></g><path d="M 150 114 L 150 201 Q 150 211 160 211 L 323.63 211" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><ellipse cx="150" cy="111" rx="3" ry="3" fill="#000000" stroke="#000000" pointer-events="all"/><path d="M 328.88 211 L 321.88 214.5 L 323.63 211 L 321.88 207.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/></g></svg>
\ No newline at end of file
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
[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
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
#### 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
Build dependencies otherwise inherit settings from the active profile in use, as
described below.
-### Profile selection
+### Custom profiles
+
+In addition to the built-in profiles, additional custom profiles can be
+defined. These may be useful for setting up multiple workflows and build
+modes. When defining a custom profile, you must specify the `inherits` key to
+specify which profile the custom profile inherits settings from when the
+setting is not specified.
+
+For example, let's say you want to compare a normal release build with a
+release build with [LTO](#lto) optimizations, you can specify something like
+the following in `Cargo.toml`:
+
+```toml
+[profile.release-lto]
+inherits = "release"
+lto = true
+```
-The profile used depends on the command, the package, the Cargo target, and
-command-line flags like `--release`.
+The `--profile` flag can then be used to choose this custom profile:
-Build commands like [`cargo build`], [`cargo rustc`], [`cargo check`], and
-[`cargo run`] default to using the `dev` profile. The `--release` flag may be
-used to switch to the `release` profile.
+```console
+cargo build --profile release-lto
+```
-The [`cargo install`] command defaults to the `release` profile, and may use
-the `--debug` flag to switch to the `dev` profile.
+The output for each profile will be placed in a directory of the same name
+as the profile in the [`target` directory]. As in the example above, the
+output would go into the `target/release-lto` directory.
-Test targets are built with the `test` profile by default. The `--release`
-flag switches tests to the `bench` profile.
+[`target` directory]: ../guide/build-cache.md
-Bench targets are built with the `bench` profile by default. The [`cargo
-build`] command can be used to build a bench target with the `test` profile to
-enable debugging.
+### Profile selection
-Note that when using the [`cargo test`] and [`cargo bench`] commands, the
-`test`/`bench` profiles only apply to the final test executable. Dependencies
-will continue to use the `dev`/`release` profiles. Also note that when a
-library is built for unit tests, then the library is built with the `test`
-profile. However, when building an integration test target, the library target
-is built with the `dev` profile and linked into the integration test
-executable.
+The profile used depends on the command, the command-line flags like
+`--release` or `--profile`, and the package (in the case of
+[overrides](#overrides)). The default profile if none is specified is:
-![Profile selection for cargo test](../images/profile-selection.svg)
+* Build commands like [`cargo build`], [`cargo rustc`], [`cargo check`], and
+[`cargo run`]: [`dev` profile](#dev)
+* [`cargo test`]: [`test` profile](#test)
+* [`cargo bench`]: [`bench` profile](#bench)
+* [`cargo install`]: [`release` profile](#release)
+The profile for specific packages can be specified with
+[overrides](#overrides), described below.
[`cargo bench`]: ../commands/cargo-bench.md
[`cargo build`]: ../commands/cargo-build.md
* [`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
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
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.
.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
\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
\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.
.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
\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.
.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
\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.
.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
.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
\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.
.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
\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.
.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
\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
.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
\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.
.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
\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.
.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
\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.
.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
\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.
.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"); }"#)
.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| {
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",
[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] [..]
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();
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(
"\
[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(
"\
",
)
.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] [..]
.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()
.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();
}
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();
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()
fs::write(
paths::root().join("Cargo.toml"),
r#"
- cargo-features = ['named-profiles']
-
[workspace]
[profile.middle]
"#,
)
.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();
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
[package]
name = "foo"
version = "0.1.0"
.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 [..]")
#[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(
[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] [..]
",
)
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"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.1.0"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"error: profile `release-lto` inherits from `.release`, \
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
// 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 [..]
.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 [..]
.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(
"\
)
.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(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.build();
p.cargo("build --release")
- .masquerade_as_nightly_cargo()
.with_stdout("")
.with_stderr(
"\
p.cargo("clean -p foo").masquerade_as_nightly_cargo().run();
p.cargo("build --release")
- .masquerade_as_nightly_cargo()
.with_stdout("")
.with_stderr(
"\
)
.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 ([..])
.run();
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_stdout("")
.with_stderr(
"\
)
.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 ([..])
)
.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());
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());
}
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.0.1"
.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();
.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!(
"\
"Cargo.toml",
&format!(
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.1.0"
);
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(&format!(
"\
p.change_file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.1.0"
);
p.cargo("build")
- .masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
.file(
"Cargo.toml",
r#"
- cargo-features = ["named-profiles"]
-
[package]
name = "foo"
version = "0.1.0"
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();
//! 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
project()
.file(
"Cargo.toml",
- &format!(
- r#"
- cargo-features = [{named_profiles}]
-
- [package]
- name = "foo"
- version = "0.0.1"
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
- [dependencies]
- bar = {{ path = "bar" }}
+ [dependencies]
+ bar = { path = "bar" }
- [build-dependencies]
- bdep = {{ path = "bdep" }}
+ [build-dependencies]
+ bdep = { path = "bdep" }
- [profile.dev]
- codegen-units = 1
- panic = "abort"
- [profile.release]
- codegen-units = 2
- panic = "abort"
- [profile.test]
- codegen-units = 3
- [profile.bench]
- codegen-units = 4
- [profile.dev.build-override]
- codegen-units = 5
- [profile.release.build-override]
- codegen-units = 6
- "#,
- named_profiles = if is_nightly() {
- "\"named-profiles\", "
- } else {
- ""
- }
- ),
+ [profile.dev]
+ codegen-units = 1
+ panic = "abort"
+ [profile.release]
+ codegen-units = 2
+ panic = "abort"
+ [profile.test]
+ codegen-units = 3
+ [profile.bench]
+ codegen-units = 4
+ [profile.dev.build-override]
+ codegen-units = 5
+ [profile.release.build-override]
+ codegen-units = 6
+ "#,
)
.file("src/lib.rs", "extern crate bar;")
.file("src/main.rs", "extern crate foo; fn main() {}")
// 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 [..]
[FINISHED] dev [unoptimized + debuginfo] [..]
").run();
p.cargo("build -vv")
- .masquerade_as_nightly_cargo()
.with_stderr_unordered(
"\
[FRESH] bar [..]
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 [..]
[FINISHED] release [optimized] [..]
").run();
p.cargo("build --release -vv")
- .masquerade_as_nightly_cargo()
.with_stderr_unordered(
"\
[FRESH] bar [..]
#[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.
// 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 [..]
[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 [..]
#[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.
// 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 [..]
[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 [..]
#[cargo_test]
fn profile_selection_test() {
let p = all_target_project();
- let affected = if is_nightly() { 3 } else { 1 };
// `test`
// NOTES:
// - Dependency profiles:
// 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 [..]
#[cargo_test]
fn profile_selection_test_release() {
let p = all_target_project();
- let affected = if is_nightly() { 2 } else { 4 };
// `test --release`
// NOTES:
// 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 [..]
[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] [..]
[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 [..]
#[cargo_test]
fn profile_selection_bench() {
let p = all_target_project();
- let affected = if is_nightly() { 4 } else { 2 };
// `bench`
// NOTES:
// 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 [..]
[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 [..]
// 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 [..]
// 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 [..]
// 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 [..]
").run();
p.cargo("check --all-targets --release -vv")
- .masquerade_as_nightly_cargo()
.with_stderr_unordered(
"\
[FRESH] bar [..]
#[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:
// 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 [..]
// 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 [..]