Skip to content

Commit dbfde2e

Browse files
committed
feat(config): Add install.profile
1 parent 55ff0a6 commit dbfde2e

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

doc/book/src/reference/config.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ user-agent = "…" # the user-agent header
120120

121121
[install]
122122
root = "/some/path" # `cargo install` destination directory
123+
profile = "release" # build using the specified profile
123124

124125
[net]
125126
retry = 3 # network retries
@@ -936,6 +937,24 @@ your home directory).
936937

937938
Can be overridden with the `--root` command-line option.
938939

940+
#### `install.profile`
941+
* Type: string
942+
* Default: `"release"`
943+
* Environment: `CARGO_INSTALL_PROFILE`
944+
945+
The default [profile] to compile with.
946+
947+
Can be overridden with the `--debug` or `--profile` CLI options.
948+
949+
```toml
950+
[install]
951+
profile = "tool"
952+
953+
[profile.tool]
954+
inherits = "release"
955+
lto = true
956+
```
957+
939958
### `[net]`
940959

941960
The `[net]` table controls networking configuration.

src/bin/cargo/commands/install.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use cargo::util::IntoUrl;
99
use cargo::util::VersionExt;
1010
use cargo::workspace::{GitReference, SourceId, Workspace};
1111
use cargo_util_schemas::manifest::PackageName;
12+
use cargo_util_schemas::manifest::ProfileName;
1213
use itertools::Itertools;
1314
use semver::VersionReq;
1415

@@ -224,8 +225,13 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
224225
ProfileChecking::Custom,
225226
)?;
226227

228+
let default_profile = gctx.get::<Option<ProfileName>>("install.profile")?;
229+
let default_profile = default_profile
230+
.as_ref()
231+
.map(|p| p.as_ref())
232+
.unwrap_or_else(|| "release");
227233
compile_opts.build_config.requested_profile =
228-
args.get_profile_name("release", ProfileChecking::Custom)?;
234+
args.get_profile_name(default_profile, ProfileChecking::Custom)?;
229235
if args.dry_run() {
230236
gctx.cli_unstable().fail_if_stable_opt("--dry-run", 11123)?;
231237
}

tests/testsuite/profile_config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ fn check_ignores_install_profile() {
523523
.file("src/main.rs", "fn main() {}")
524524
.build();
525525
p.cargo("check")
526+
.env("CARGO_INSTALL_PROFILE", "release")
526527
.with_stderr_data(str![[r#"
527528
[CHECKING] foo v0.1.0 ([ROOT]/foo)
528529
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -571,6 +572,7 @@ fn test_ignores_install_profile() {
571572
.file("src/main.rs", "fn main() {}")
572573
.build();
573574
p.cargo("test --no-run")
575+
.env("CARGO_INSTALL_PROFILE", "release")
574576
.with_stderr_data(str![[r#"
575577
[COMPILING] foo v0.1.0 ([ROOT]/foo)
576578
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -594,7 +596,8 @@ fn install_uses_install_profile() {
594596
)
595597
.file("src/main.rs", "fn main() {}")
596598
.build();
597-
p.cargo("install --debug")
599+
p.cargo("install")
600+
.env("CARGO_INSTALL_PROFILE", "debug")
598601
.with_stderr_data(str![[r#"
599602
[WARNING] using `cargo install` to install the binaries from the package in current working directory is deprecated, use `cargo install --path .` instead. [NOTE] use `cargo build` if you want to simply build the package.
600603
[INSTALLING] foo v0.1.0 ([ROOT]/foo)

0 commit comments

Comments
 (0)