Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions crates/cargo-util-schemas/src/restricted_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ pub(crate) fn validate_profile_name(name: &str) -> Result<()> {
}

let lower_name = name.to_lowercase();
if lower_name == "debug" {
return Err(ErrorKind::ProfileNameReservedKeyword {
name: name.into(),
help: "To configure the default development profile, \
use the name `dev` as in [profile.dev]",
}
.into());
}
if lower_name == "build-override" {
return Err(ErrorKind::ProfileNameReservedKeyword {
name: name.into(),
Expand Down
4 changes: 2 additions & 2 deletions doc/book/src/commands/cargo-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function to handle running benchmarks.

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
benchmark, you can use the `--profile=debug` command-line option to switch to
the debug profile. You can then run the debug-enabled benchmark within a
debugger.

[`bench` profile]: ../reference/profiles.html#bench
Expand Down
2 changes: 1 addition & 1 deletion doc/book/src/commands/cargo-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ is specified.</p>


<dt class="option-term" id="option-cargo-install---debug"><a class="option-anchor" href="#option-cargo-install---debug"><code>--debug</code></a></dt>
<dd class="option-desc"><p>Build with the <code>dev</code> profile instead of the <code>release</code> profile.
<dd class="option-desc"><p>Build with the <code>debug</code> profile instead of the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</p>
</dd>

Expand Down
5 changes: 4 additions & 1 deletion doc/book/src/commands/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ manifest settings, in which case your code will need to provide its own `main`
function to handle running tests.

By default, `cargo test` uses the [`test` profile], which enables
debugging.
some optimizations and disables debugging information for fast feedback. If you need to debug a
benchmark, you can use the `--profile=debug` command-line option to switch to
the debug profile. You can then run the debug-enabled test within a
debugger.

[`test` profile]: ../reference/profiles.html#test

Expand Down
15 changes: 13 additions & 2 deletions doc/book/src/reference/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ whether or not [`rpath`] is enabled.

### dev

The `dev` profile is used for normal development and debugging. It is the
default for build commands like [`cargo build`], and is used for `cargo install --debug`.
The `dev` profile is used for normal development. It is the
default for build commands like [`cargo build`], and is used for `cargo install --profile dev`.

The default settings for the `dev` profile are:

Expand All @@ -282,6 +282,17 @@ codegen-units = 256
rpath = false
```

### debug

The `debug` profile is used for creating binaries to run with a debugger. It is used with `cargo build --profile debug` and `cargo install --debug`.

The default settings for the `debug` profile are:

```toml
[profile.debug]
inherits = "dev"
```

### release

The `release` profile is intended for optimized artifacts used for releases
Expand Down
4 changes: 2 additions & 2 deletions doc/man/cargo-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function to handle running benchmarks.

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
benchmark, you can use the `--profile=debug` command-line option to switch to
the debug profile. You can then run the debug-enabled benchmark within a
debugger.

[`bench` profile]: ../reference/profiles.html#bench
Expand Down
2 changes: 1 addition & 1 deletion doc/man/cargo-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Directory to install packages into.
{{> options-target-dir }}

{{#option "`--debug`" }}
Build with the `dev` profile instead of the `release` profile.
Build with the `debug` profile instead of the `release` profile.
See also the `--profile` option for choosing a specific profile by name.
{{/option}}

Expand Down
5 changes: 4 additions & 1 deletion doc/man/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ manifest settings, in which case your code will need to provide its own `main`
function to handle running tests.

By default, `cargo test` uses the [`test` profile], which enables
debugging.
some optimizations and disables debugging information for fast feedback. If you need to debug a
benchmark, you can use the `--profile=debug` command-line option to switch to
the debug profile. You can then run the debug-enabled test within a
debugger.

[`test` profile]: ../reference/profiles.html#test

Expand Down
6 changes: 3 additions & 3 deletions doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ DESCRIPTION
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.
debug a benchmark, you can use the --profile=debug command-line option
to switch to the debug profile. You can then run the debug-enabled
benchmark within a debugger.

Working directory of benchmarks
The working directory of every benchmark is set to the root directory of
Expand Down
4 changes: 2 additions & 2 deletions doc/man/generated_txt/cargo-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ OPTIONS
workspace of the local crate unless --target-dir is specified.

--debug
Build with the dev profile instead of the release profile. See also
the --profile option for choosing a specific profile by name.
Build with the debug profile instead of the release profile. See
also the --profile option for choosing a specific profile by name.

--profile name
Install with the given profile. See the reference
Expand Down
5 changes: 4 additions & 1 deletion doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ DESCRIPTION

By default, cargo test uses the test profile
<https://doc.rust-lang.org/cargo/reference/profiles.html#test>, which
enables debugging.
enables some optimizations and disables debugging information for fast
feedback. If you need to debug a benchmark, you can use the
--profile=debug command-line option to switch to the debug profile. You
can then run the debug-enabled test within a debugger.

Documentation tests
Documentation tests are also run by default, which is handled by
Expand Down
4 changes: 2 additions & 2 deletions etc/man/cargo-bench.1
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ running benchmarks on the stable channel, such as
.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
benchmark, you can use the \fB\-\-profile=debug\fR command\-line option to switch to
the debug profile. You can then run the debug\-enabled benchmark within a
debugger.
.SS "Working directory of benchmarks"
The working directory of every benchmark is set to the root directory of the
Expand Down
2 changes: 1 addition & 1 deletion etc/man/cargo-install.1
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ is specified.
.sp
\fB\-\-debug\fR
.RS 4
Build with the \fBdev\fR profile instead of the \fBrelease\fR profile.
Build with the \fBdebug\fR profile instead of the \fBrelease\fR profile.
See also the \fB\-\-profile\fR option for choosing a specific profile by name.
.RE
.sp
Expand Down
5 changes: 4 additions & 1 deletion etc/man/cargo-test.1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ manifest settings, in which case your code will need to provide its own \fBmain\
function to handle running tests.
.sp
By default, \fBcargo test\fR uses the \fI\f(BItest\fI profile\fR <https://doc.rust\-lang.org/cargo/reference/profiles.html#test>, which enables
debugging.
some optimizations and disables debugging information for fast feedback. If you need to debug a
benchmark, you can use the \fB\-\-profile=debug\fR command\-line option to switch to
the debug profile. You can then run the debug\-enabled test within a
debugger.
.SS "Documentation tests"
Documentation tests are also run by default, which is handled by \fBrustdoc\fR\&. It
extracts code samples from documentation comments of the library target, and
Expand Down
2 changes: 1 addition & 1 deletion src/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ Run `{cmd}` to see possible targets."
) {
(false, false, None) => default,
(true, _, None) => "release",
(_, true, None) => "dev",
(_, true, None) => "debug",
// `doc` is separate from all the other reservations because
// [profile.doc] was historically allowed, but is deprecated and
// has no effect. To avoid potentially breaking projects, it is a
Expand Down
9 changes: 0 additions & 9 deletions src/workspace/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2564,15 +2564,6 @@ pub fn validate_profile(
);
}

// `inherits` validation
if matches!(root.inherits.as_deref(), Some("debug")) {
bail!(
"profile.{}.inherits=\"debug\" should be profile.{}.inherits=\"dev\"",
name,
name
);
}

match name {
"doc" => {
warnings.push("profile `doc` is deprecated and has no effect".to_string());
Expand Down
9 changes: 8 additions & 1 deletion src/workspace/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ impl Profiles {
/// "root" profiles).
fn predefined_profiles() -> Vec<(&'static str, TomlProfile)> {
vec![
(
"debug",
TomlProfile {
inherits: Some(String::from("dev")),
..TomlProfile::default()
},
),
(
"bench",
TomlProfile {
Expand Down Expand Up @@ -1298,7 +1305,7 @@ fn merge_config_profiles(
}
// Add the built-in profiles. This is important for things like `cargo
// test` which implicitly use the "dev" profile for dependencies.
for name in ["dev", "release", "test", "bench"] {
for name in ["dev", "release", "debug", "test", "bench"] {
check_to_add.insert(name.into());
}
// Add config-only profiles.
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2842,7 +2842,7 @@ fn install_with_debug_profile() {
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
[INSTALLING] foo v0.0.1
[COMPILING] foo v0.0.1
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[FINISHED] `debug` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
Expand Down
88 changes: 59 additions & 29 deletions tests/testsuite/profile_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,35 +599,6 @@ See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configur
))
.run();
}

p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
authors = []

[profile.debug]
debug = 1
inherits = "dev"
"#,
);

p.cargo("build")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] profile name `debug` is reserved
To configure the default development profile, use the name `dev` as in [profile.dev]
See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configuring profiles.
--> Cargo.toml:8:25
|
8 | [profile.debug]
| ^^^^^

"#]])
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -792,3 +763,62 @@ fn request_test_profile() {
"#]])
.run();
}

#[cargo_test]
fn debug_inherits_dev() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[profile.dev]
debug = 0

[profile.debug]
opt-level = 3
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check --profile=debug -v")
.with_stderr_data(str![[r#"
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]`
[FINISHED] `debug` profile [optimized] target(s) in [ELAPSED]s

"#]])
.with_stdout_does_not_contain("[..] -C debuginfo=0[..]")
.with_stdout_does_not_contain("[..] -C opt-level=0[..]")
.run();
}

#[cargo_test]
fn change_debug_inheritance() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[profile.debug]
inherits = "release"
debug = true
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check --profile=debug")
.with_stderr_data(str![[r#"
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `debug` profile [optimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();
}