Skip to content

Commit ced10bd

Browse files
committed
custom-named-profiles: add documentation in unstable.md
1 parent ffc24e0 commit ced10bd

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/doc/src/reference/unstable.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,66 @@ opt-level = 2
9292
opt-level = 3
9393
```
9494

95-
Overrides can only be specified for dev and release profiles.
95+
Overrides can be specified for any profile, including custom named profiles.
96+
97+
98+
### Custom named profiles
99+
100+
* Tracking Issue: [rust-lang/cargo#6988](https://github.com/rust-lang/cargo/issues/6988)
101+
* RFC: [#2678](https://github.com/rust-lang/rfcs/pull/2678)
102+
103+
With this feature you can define custom profiles having new names. With the
104+
custom profile enabled, build artifacts can be emitted by default to
105+
directories other than `release` or `debug`, based on the custom profile's
106+
name.
107+
108+
For example:
109+
110+
```toml
111+
cargo-features = ["named-profiles"]
112+
113+
[profile.release-lto]
114+
inherits = "release"
115+
lto = true
116+
````
117+
118+
An `inherits` key is used in order to receive attributes from other profiles,
119+
so that a new custom profile can be based on the standard `dev` or `release`
120+
profile presets. Cargo emits errors in case `inherits` loops are detected. When
121+
considering inheritance hierarchy, all profiles directly or indirectly inherit
122+
from either from `release` or from `dev`.
123+
124+
Valid profile names are: must not be empty, use only alphanumeric characters or
125+
`-` or `_`.
126+
127+
Passing `--profile` with the profile's name to various Cargo commands, directs
128+
operations to use the profile's attributes. Overrides that are specified in the
129+
profiles from which the custom profile inherits are inherited too.
130+
131+
For example, using `cargo build` with `--profile` and the manifest from above:
132+
133+
```
134+
cargo +nightly build --profile release-lto -Z unstable-options
135+
```
136+
137+
When a custom profile is used, build artifcats go to a different target by
138+
default. In the example above, you can expect to see the outputs under
139+
`target/release-lto`.
140+
141+
142+
#### New `dir-name` attribute
143+
144+
Some of the paths generated under `target/` have resulted in a de-facto "build
145+
protocol", where `cargo` is invoked as a part of a larger project build. So, to
146+
preserve the existing behavior, there is also a new attribute `dir-name`, which
147+
when left unspecified, defaults to the name of the profile. For example:
148+
149+
```toml
150+
[profile.release-lto]
151+
inherits = "release"
152+
dir-name = "lto" # Emits to target/lto instead of target/release-lto
153+
lto = true
154+
```
96155

97156

98157
### Config Profiles

0 commit comments

Comments
 (0)