Skip to content

Commit 8b0561d

Browse files
committed
Auto merge of #6989 - da-x:custom-profile-pr-rfc, r=ehuss
Support for named profiles (RFC 2678) Tracking issue: #6988 Implementation according to the [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2678-named-custom-cargo-profiles.md).
2 parents 8ae8b5e + fad192d commit 8b0561d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1513
-457
lines changed

src/bin/cargo/commands/bench.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,18 @@ Compilation can be customized with the `bench` profile in the manifest.
7373

7474
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
7575
let ws = args.workspace(config)?;
76-
let mut compile_opts = args.compile_options(config, CompileMode::Bench, Some(&ws))?;
76+
let mut compile_opts = args.compile_options(
77+
config,
78+
CompileMode::Bench,
79+
Some(&ws),
80+
ProfileChecking::Checked,
81+
)?;
7782

78-
compile_opts.build_config.release = true;
83+
compile_opts.build_config.profile_kind = args.get_profile_kind(
84+
config,
85+
ProfileKind::Custom("bench".to_owned()),
86+
ProfileChecking::Checked,
87+
)?;
7988

8089
let ops = TestOptions {
8190
no_run: args.is_present("no-run"),

src/bin/cargo/commands/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn cli() -> App {
2727
"Build all targets",
2828
)
2929
.arg_release("Build artifacts in release mode, with optimizations")
30+
.arg_profile("Build artifacts with the specified profile")
3031
.arg_features()
3132
.arg_target_triple("Build for the target triple")
3233
.arg_target_dir()
@@ -55,7 +56,12 @@ the --release flag will use the `release` profile instead.
5556

5657
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5758
let ws = args.workspace(config)?;
58-
let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws))?;
59+
let mut compile_opts = args.compile_options(
60+
config,
61+
CompileMode::Build,
62+
Some(&ws),
63+
ProfileChecking::Checked,
64+
)?;
5965

6066
compile_opts.export_dir = args.value_of_path("out-dir", config);
6167
if compile_opts.export_dir.is_some() {

src/bin/cargo/commands/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn cli() -> App {
2727
"Check all targets",
2828
)
2929
.arg_release("Check artifacts in release mode, with optimizations")
30-
.arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE"))
30+
.arg_profile("Check artifacts with the specified profile")
3131
.arg_features()
3232
.arg_target_triple("Check for the target triple")
3333
.arg_target_dir()
@@ -69,7 +69,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6969
}
7070
};
7171
let mode = CompileMode::Check { test };
72-
let compile_opts = args.compile_options(config, mode, Some(&ws))?;
72+
let compile_opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Unchecked)?;
7373

7474
ops::compile(&ws, &compile_opts)?;
7575
Ok(())

src/bin/cargo/commands/clean.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub fn cli() -> App {
1111
.arg_target_triple("Target triple to clean output for")
1212
.arg_target_dir()
1313
.arg_release("Whether or not to clean release artifacts")
14+
.arg_profile("Clean artifacts of the specified profile")
1415
.arg_doc("Whether or not to clean just the documentation directory")
1516
.after_help(
1617
"\
@@ -28,7 +29,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
2829
config,
2930
spec: values(args, "package"),
3031
target: args.target(),
31-
release: args.is_present("release"),
32+
profile_kind: args.get_profile_kind(config, ProfileKind::Dev, ProfileChecking::Checked)?,
33+
profile_specified: args.is_present("profile") || args.is_present("release"),
3234
doc: args.is_present("doc"),
3335
};
3436
ops::clean(&ws, &opts)?;

src/bin/cargo/commands/clippy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn cli() -> App {
2626
"Check all targets",
2727
)
2828
.arg_release("Check artifacts in release mode, with optimizations")
29+
.arg_profile("Check artifacts with the specified profile")
2930
.arg_features()
3031
.arg_target_triple("Check for the target triple")
3132
.arg_target_dir()
@@ -61,7 +62,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6162
let ws = args.workspace(config)?;
6263

6364
let mode = CompileMode::Check { test: false };
64-
let mut compile_opts = args.compile_options(config, mode, Some(&ws))?;
65+
let mut compile_opts =
66+
args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?;
6567

6668
if !config.cli_unstable().unstable_options {
6769
return Err(failure::format_err!(

src/bin/cargo/commands/doc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn cli() -> App {
2424
"Document all binaries",
2525
)
2626
.arg_release("Build artifacts in release mode, with optimizations")
27+
.arg_profile("Build artifacts with the specified profile")
2728
.arg_features()
2829
.arg_target_triple("Build for the target triple")
2930
.arg_target_dir()
@@ -52,7 +53,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5253
let mode = CompileMode::Doc {
5354
deps: !args.is_present("no-deps"),
5455
};
55-
let mut compile_opts = args.compile_options(config, mode, Some(&ws))?;
56+
let mut compile_opts =
57+
args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?;
5658
compile_opts.local_rustdoc_args = if args.is_present("document-private-items") {
5759
Some(vec!["--document-private-items".to_string()])
5860
} else {

src/bin/cargo/commands/fix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn cli() -> App {
2525
"Fix all targets (default)",
2626
)
2727
.arg_release("Fix artifacts in release mode, with optimizations")
28-
.arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE"))
28+
.arg_profile("Build artifacts with the specified profile")
2929
.arg_features()
3030
.arg_target_triple("Fix for the target triple")
3131
.arg_target_dir()
@@ -132,7 +132,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
132132

133133
// Unlike other commands default `cargo fix` to all targets to fix as much
134134
// code as we can.
135-
let mut opts = args.compile_options(config, mode, Some(&ws))?;
135+
let mut opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Unchecked)?;
136136

137137
let use_clippy = args.is_present("clippy");
138138

src/bin/cargo/commands/install.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub fn cli() -> App {
5151
"Do not save tracking information (unstable)",
5252
))
5353
.arg_features()
54+
.arg_profile("Install artifacts with from the specified profile")
5455
.arg(opt("debug", "Build in debug mode instead of release mode"))
5556
.arg_targets_bins_examples(
5657
"Install only the specified binary",
@@ -115,9 +116,15 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
115116
}
116117

117118
let workspace = args.workspace(config).ok();
118-
let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?;
119-
120-
compile_opts.build_config.release = !args.is_present("debug");
119+
let mut compile_opts = args.compile_options(
120+
config,
121+
CompileMode::Build,
122+
workspace.as_ref(),
123+
ProfileChecking::Checked,
124+
)?;
125+
126+
compile_opts.build_config.profile_kind =
127+
args.get_profile_kind(config, ProfileKind::Release, ProfileChecking::Checked)?;
121128

122129
let krates = args
123130
.values_of("crate")

src/bin/cargo/commands/run.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn cli() -> App {
1818
.arg_package("Package with the target to run")
1919
.arg_jobs()
2020
.arg_release("Build artifacts in release mode, with optimizations")
21+
.arg_profile("Build artifacts with the specified profile")
2122
.arg_features()
2223
.arg_target_triple("Build for the target triple")
2324
.arg_target_dir()
@@ -40,7 +41,12 @@ run. If you're passing arguments to both Cargo and the binary, the ones after
4041
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
4142
let ws = args.workspace(config)?;
4243

43-
let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws))?;
44+
let mut compile_opts = args.compile_options(
45+
config,
46+
CompileMode::Build,
47+
Some(&ws),
48+
ProfileChecking::Checked,
49+
)?;
4450

4551
if !args.is_present("example") && !args.is_present("bin") {
4652
let default_runs: Vec<_> = compile_opts

src/bin/cargo/commands/rustc.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn cli() -> App {
2323
"Build all targets",
2424
)
2525
.arg_release("Build artifacts in release mode, with optimizations")
26-
.arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE"))
26+
.arg_profile("Build artifacts with the specified profile")
2727
.arg_features()
2828
.arg_target_triple("Target triple which compiles will be for")
2929
.arg_target_dir()
@@ -63,7 +63,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6363
return Err(CliError::new(err, 101));
6464
}
6565
};
66-
let mut compile_opts = args.compile_options_for_single_package(config, mode, Some(&ws))?;
66+
let mut compile_opts = args.compile_options_for_single_package(
67+
config,
68+
mode,
69+
Some(&ws),
70+
ProfileChecking::Unchecked,
71+
)?;
6772
let target_args = values(args, "args");
6873
compile_opts.target_rustc_args = if target_args.is_empty() {
6974
None

0 commit comments

Comments
 (0)