Skip to content

Commit 864951e

Browse files
committed
Fixes following @ehuss's review
1 parent 868d024 commit 864951e

File tree

1 file changed

+51
-27
lines changed

1 file changed

+51
-27
lines changed

text/0000-named-custom-cargo-profiles.md

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
The proposed change to Cargo is to add the ability to specify user-defined
1010
profiles in addition to the five predefined profiles, `dev`, `release`, `test`,
11-
`bench`, and the less talked-about `doc`. It is also desired in this scope to
12-
reduce confusion regarding where final outputs reside, and increase the
13-
flexibility to specify the user-defined profile attributes.
11+
`bench`. It is also desired in this scope to reduce confusion regarding where
12+
final outputs reside, and increase the flexibility to specify the user-defined
13+
profile attributes.
1414

1515
# Motivation
1616
[motivation]: #motivation
@@ -47,6 +47,9 @@ For example:
4747
inherits = "release"
4848
lto = true
4949

50+
Valid profile names are: must not be empty, use only alphanumeric characters or
51+
`-` or `_`.
52+
5053
Passing `--profile` with the profile's name to various Cargo commands will
5154
resolve to the custom profile. Overrides specified in the profiles from which
5255
the custom profile inherits will be inherited too, and all final outputs may
@@ -71,6 +74,18 @@ This also affects other Cargo commands:
7174
* `cargo doc` also receives `--profile`, but unless it is specified, uses
7275
the predefined `doc` profile which is described below.
7376

77+
## Effect over the use of profile in commands
78+
79+
The mixtures of profiles used for `--all-targets` is still in effect, as
80+
long as `--profile` is not specified.
81+
82+
## Combined specification with `--release`
83+
84+
For now, `--release` is supported for backward-compatibility.
85+
86+
Using `--profile` and `--release` together in the same invocation emits an
87+
error unless `--profile=release`. Using `--release` on its own is equivalent
88+
to specifying `--profile=release`
7489

7590
## New `dir-name` attribute
7691

@@ -88,8 +103,13 @@ when left unspecified, defaults to the name of the profile. For example:
88103
`test` to their respective directories: `target/release` and `target/debug`.
89104
This preserves existing behavior.
90105
* The `dir-name` attribute is the only attribute not passed by inheritance.
91-
* Path separators are not allowed in `dir-name`.
106+
* Valid directory names are: must not be empty, use only alphanumeric
107+
characters or `-` or `_`.
92108

109+
## Cross compilation
110+
111+
Under cross compilation with a profile, paths corresponding to
112+
`target/<platform-triple>/<dir-name>` will be created.
93113

94114
## Treatment to the pre-defined profiles
95115

@@ -125,29 +145,16 @@ inherits = "dev"
125145
dir-name = "debug"
126146
```
127147

128-
129148
* The (upcoming) `build` profile defaults to the following definition:
149+
130150
```
131151
[profile.build]
132152
inherits = "dev"
133153
dir-name = "build"
134154
debug = false
135155
```
136156

137-
138-
## Treatment to Cargo's 'Finished' print
139-
140-
For `cargo build`, the profile's name is emitted in the "Finished" line:
141-
142-
Finished release-lto [optimized + lto] target(s) in 3.83s
143-
144-
* As before, optimization mode is always printed, with `optimized` if
145-
`opt-level > 0` and `unoptimized` otherwise.
146-
* As before, information regarding debuginfo is printed, with `debuginfo` if
147-
`debug != false`, and nothing if `debug == false` (or `debug == 0`).
148-
* Other differences from the inherited root profile pre-defined defaults are
149-
printed in a concise manner.
150-
157+
(NOTE: the `build` profile is experimental and may be removed later)
151158

152159
# Reference-level explanation
153160
[reference-level-explanation]: #reference-level-explanation
@@ -175,13 +182,15 @@ Release, Custom(String))`.
175182
* We would need to compute the actual `build_override` for a profile based on
176183
resolution through the `inherits` key.
177184
* Custom build scripts: For compatibility, the `PROFILE` environment currently
178-
being passed to the `build.rs` script is going to bear the name of the output
179-
directory and not the name of the profile.
185+
being passed to the `build.rs` script is set to either `release` or `debug`,
186+
based on `inherits` relationship of the specified profile, in case it is not
187+
`release` or `dev` directly.
180188

181-
## Collision under the target directory
189+
## Profile name and directory name exclusion
182190

183-
To guard against the unlikely case that a target name is identical to a profile
184-
name, we should compare the lists for overlap.
191+
To prevent collisions under the target directory, predefined set of string
192+
excludes both the custom profile names and the dir-name. For example,
193+
`package`, `build`, `debug`, `doc`, and strings that start with `.`.
185194

186195
# Drawbacks
187196
[drawbacks]: #drawbacks
@@ -270,6 +279,21 @@ similar functionality in a different way.
270279
# Future possibilities
271280
[future-possibilities]: #future-possibilities
272281

273-
This RFC mentioned a global binary cache. A global binary cache can reside
274-
under `target/.cache` or in the user home directory under `.cargo`, to be
275-
shared by multiple workspaces.
282+
This RFC mentions a global binary cache. A global binary cache can reside under
283+
`target/.cache` or in the user home directory under `.cargo`, to be shared by
284+
multiple workspaces. This may further assist in reducing compilation times when
285+
switching between compilation flags.
286+
287+
## Treatment to Cargo's 'Finished' print
288+
289+
Currently, the `Finished` line being emitted when Cargo is done building, is
290+
confusing, and sometimes does not bear a relation to the specified profile. We
291+
may take this opportunity to revise the output of this line to include the name
292+
of the profile.
293+
294+
Some targets use more than one profile in their compilation process, so we may
295+
want to pick a different scheme than simply printing out the name of the main
296+
profile being used. One option is to print a line for each one of the built
297+
targets with concise description of profiles that used to build it, but there
298+
may be better options worth considering following the implementation of this
299+
RFC.

0 commit comments

Comments
 (0)