Skip to content

Commit 3959f87

Browse files
committed
Auto merge of #10838 - weihanglo:stabilize-crate-type, r=ehuss
Stabilize `--crate-type` flag for `cargo rustc`
2 parents 8ba2cb6 + cde8f6f commit 3959f87

File tree

7 files changed

+89
-53
lines changed

7 files changed

+89
-53
lines changed

src/bin/cargo/commands/rustc.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn cli() -> App {
3939
.arg(multi_opt(
4040
CRATE_TYPE_ARG_NAME,
4141
"CRATE-TYPE",
42-
"Comma separated list of types of crates for the compiler to emit (unstable)",
42+
"Comma separated list of types of crates for the compiler to emit",
4343
))
4444
.arg_target_dir()
4545
.arg_manifest_path()
@@ -88,9 +88,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
8888
compile_opts.target_rustc_crate_types = if crate_types.is_empty() {
8989
None
9090
} else {
91-
config
92-
.cli_unstable()
93-
.fail_if_stable_opt(CRATE_TYPE_ARG_NAME, 10083)?;
9491
Some(crate_types)
9592
};
9693
ops::compile(&ws, &compile_opts)?;

src/doc/man/cargo-rustc.md

+17
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ See the [the reference](../reference/profiles.html) for more details on profiles
7171

7272
{{> options-timings }}
7373

74+
{{#option "`--crate-type` _crate-type_"}}
75+
Build for the given crate type. This flag accepts a comma-separated list of
76+
1 or more crate types, of which the allowed values are the same as `crate-type`
77+
field in the manifest for configurating a Cargo target. See
78+
[`crate-type` field](../reference/cargo-targets.html#the-crate-type-field)
79+
for possible values.
80+
81+
If the manifest contains a list, and `--crate-type` is provided,
82+
the command-line argument value will override what is in the manifest.
83+
84+
This flag only works when building a `lib` or `example` library target.
85+
{{/option}}
86+
7487
{{/options}}
7588

7689
### Output Options
@@ -124,5 +137,9 @@ See the [the reference](../reference/profiles.html) for more details on profiles
124137

125138
cargo rustc --lib -- -Z print-type-sizes
126139

140+
3. Override `crate-type` field in Cargo.toml with command-line option:
141+
142+
cargo rustc --lib --crate-type lib,cdylib
143+
127144
## SEE ALSO
128145
{{man "cargo" 1}}, {{man "cargo-build" 1}}, {{man "rustc" 1}}

src/doc/man/generated_txt/cargo-rustc.txt

+17
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,19 @@ OPTIONS
192192
o json (unstable, requires -Zunstable-options): Emit
193193
machine-readable JSON information about timing information.
194194

195+
--crate-type crate-type
196+
Build for the given crate type. This flag accepts a comma-separated
197+
list of 1 or more crate types, of which the allowed values are the
198+
same as crate-type field in the manifest for configurating a Cargo
199+
target. See crate-type field
200+
<https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-crate-type-field>
201+
for possible values.
202+
203+
If the manifest contains a list, and --crate-type is provided, the
204+
command-line argument value will override what is in the manifest.
205+
206+
This flag only works when building a lib or example library target.
207+
195208
Output Options
196209
--target-dir directory
197210
Directory for all generated artifacts and intermediate files. May
@@ -340,6 +353,10 @@ EXAMPLES
340353

341354
cargo rustc --lib -- -Z print-type-sizes
342355

356+
3. Override crate-type field in Cargo.toml with command-line option:
357+
358+
cargo rustc --lib --crate-type lib,cdylib
359+
343360
SEE ALSO
344361
cargo(1), cargo-build(1), rustc(1)
345362

src/doc/src/commands/cargo-rustc.md

+15
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ information about timing information.</li>
227227

228228

229229

230+
<dt class="option-term" id="option-cargo-rustc---crate-type"><a class="option-anchor" href="#option-cargo-rustc---crate-type"></a><code>--crate-type</code> <em>crate-type</em></dt>
231+
<dd class="option-desc">Build for the given crate type. This flag accepts a comma-separated list of
232+
1 or more crate types, of which the allowed values are the same as <code>crate-type</code>
233+
field in the manifest for configurating a Cargo target. See
234+
<a href="../reference/cargo-targets.html#the-crate-type-field"><code>crate-type</code> field</a>
235+
for possible values.</p>
236+
<p>If the manifest contains a list, and <code>--crate-type</code> is provided,
237+
the command-line argument value will override what is in the manifest.</p>
238+
<p>This flag only works when building a <code>lib</code> or <code>example</code> library target.</dd>
239+
240+
230241
</dl>
231242

232243
### Output Options
@@ -411,5 +422,9 @@ details on environment variables that Cargo reads.
411422

412423
cargo rustc --lib -- -Z print-type-sizes
413424

425+
3. Override `crate-type` field in Cargo.toml with command-line option:
426+
427+
cargo rustc --lib --crate-type lib,cdylib
428+
414429
## SEE ALSO
415430
[cargo(1)](cargo.html), [cargo-build(1)](cargo-build.html), [rustc(1)](https://doc.rust-lang.org/rustc/index.html)

src/doc/src/reference/unstable.md

+6-17
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,6 @@ like to stabilize it somehow!
409409

410410
[rust-lang/rust#64158]: https://github.com/rust-lang/rust/pull/64158
411411

412-
### crate-type
413-
* Tracking Issue: [#10083](https://github.com/rust-lang/cargo/issues/10083)
414-
* RFC: [#3180](https://github.com/rust-lang/rfcs/pull/3180)
415-
* Original Pull Request: [#10093](https://github.com/rust-lang/cargo/pull/10093)
416-
417-
`cargo rustc --crate-type=lib,cdylib` forwards the `--crate-type` flag to `rustc`.
418-
This runs `rustc` with the corresponding
419-
[`--crate-type`](https://doc.rust-lang.org/rustc/command-line-arguments.html#--crate-type-a-list-of-types-of-crates-for-the-compiler-to-emit)
420-
flag, and compiling.
421-
422-
When using it, it requires the `-Z unstable-options`
423-
command-line option:
424-
425-
```console
426-
cargo rustc --crate-type lib,cdylib -Z unstable-options
427-
```
428-
429412
### keep-going
430413
* Tracking Issue: [#10496](https://github.com/rust-lang/cargo/issues/10496)
431414

@@ -1547,3 +1530,9 @@ information.
15471530
The `-Z multitarget` option has been stabilized in the 1.64 release.
15481531
See [`build.target`](config.md#buildtarget) for more information about
15491532
setting the default target platform triples.
1533+
1534+
### crate-type
1535+
1536+
The `--crate-type` flag for `cargo rustc` has been stabilized in the 1.64
1537+
release. See the [`cargo rustc` documentation](../commands/cargo-rustc.md)
1538+
for more information.

src/etc/man/cargo-rustc.1

+24
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ and does not provide machine\-readable timing data.
224224
information about timing information.
225225
.RE
226226
.RE
227+
.sp
228+
\fB\-\-crate\-type\fR \fIcrate\-type\fR
229+
.RS 4
230+
Build for the given crate type. This flag accepts a comma\-separated list of
231+
1 or more crate types, of which the allowed values are the same as \fBcrate\-type\fR
232+
field in the manifest for configurating a Cargo target. See
233+
\fI\f(BIcrate\-type\fI field\fR <https://doc.rust\-lang.org/cargo/reference/cargo\-targets.html#the\-crate\-type\-field>
234+
for possible values.
235+
.sp
236+
If the manifest contains a list, and \fB\-\-crate\-type\fR is provided,
237+
the command\-line argument value will override what is in the manifest.
238+
.sp
239+
This flag only works when building a \fBlib\fR or \fBexample\fR library target.
240+
.RE
227241
.SS "Output Options"
228242
.sp
229243
\fB\-\-target\-dir\fR \fIdirectory\fR
@@ -432,5 +446,15 @@ cargo rustc \-\-lib \-\- \-Z print\-type\-sizes
432446
.fi
433447
.RE
434448
.RE
449+
.sp
450+
.RS 4
451+
\h'-04' 3.\h'+01'Override \fBcrate\-type\fR field in Cargo.toml with command\-line option:
452+
.sp
453+
.RS 4
454+
.nf
455+
cargo rustc \-\-lib \-\-crate\-type lib,cdylib
456+
.fi
457+
.RE
458+
.RE
435459
.SH "SEE ALSO"
436460
\fBcargo\fR(1), \fBcargo\-build\fR(1), \fBrustc\fR(1)

tests/testsuite/rustc.rs

+9-32
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,6 @@ fn fails_with_args_to_all_binaries() {
134134
.run();
135135
}
136136

137-
#[cargo_test]
138-
fn fails_with_crate_type_and_without_unstable_options() {
139-
let p = project().file("src/lib.rs", r#" "#).build();
140-
141-
p.cargo("rustc --crate-type lib")
142-
.masquerade_as_nightly_cargo(&["crate-type"])
143-
.with_status(101)
144-
.with_stderr(
145-
"[ERROR] the `crate-type` flag is unstable, pass `-Z unstable-options` to enable it
146-
See https://github.com/rust-lang/cargo/issues/10083 for more information about the `crate-type` flag.",
147-
)
148-
.run();
149-
}
150-
151137
#[cargo_test]
152138
fn fails_with_crate_type_to_multi_binaries() {
153139
let p = project()
@@ -157,8 +143,7 @@ fn fails_with_crate_type_to_multi_binaries() {
157143
.file("src/lib.rs", r#" "#)
158144
.build();
159145

160-
p.cargo("rustc --crate-type lib -Zunstable-options")
161-
.masquerade_as_nightly_cargo(&["crate-type"])
146+
p.cargo("rustc --crate-type lib")
162147
.with_status(101)
163148
.with_stderr(
164149
"[ERROR] crate types to rustc can only be passed to one target, consider filtering
@@ -191,8 +176,7 @@ fn fails_with_crate_type_to_multi_examples() {
191176
.file("examples/ex2.rs", "")
192177
.build();
193178

194-
p.cargo("rustc -v --example ex1 --example ex2 --crate-type lib,cdylib -Zunstable-options")
195-
.masquerade_as_nightly_cargo(&["crate-type"])
179+
p.cargo("rustc -v --example ex1 --example ex2 --crate-type lib,cdylib")
196180
.with_status(101)
197181
.with_stderr(
198182
"[ERROR] crate types to rustc can only be passed to one target, consider filtering
@@ -205,8 +189,7 @@ the package by passing, e.g., `--lib` or `--example` to specify a single target"
205189
fn fails_with_crate_type_to_binary() {
206190
let p = project().file("src/bin/foo.rs", "fn main() {}").build();
207191

208-
p.cargo("rustc --crate-type lib -Zunstable-options")
209-
.masquerade_as_nightly_cargo(&["crate-type"])
192+
p.cargo("rustc --crate-type lib")
210193
.with_status(101)
211194
.with_stderr(
212195
"[ERROR] crate types can only be specified for libraries and example libraries.
@@ -219,8 +202,7 @@ Binaries, tests, and benchmarks are always the `bin` crate type",
219202
fn build_with_crate_type_for_foo() {
220203
let p = project().file("src/lib.rs", "").build();
221204

222-
p.cargo("rustc -v --crate-type cdylib -Zunstable-options")
223-
.masquerade_as_nightly_cargo(&["crate-type"])
205+
p.cargo("rustc -v --crate-type cdylib")
224206
.with_stderr(
225207
"\
226208
[COMPILING] foo v0.0.1 ([CWD])
@@ -257,8 +239,7 @@ fn build_with_crate_type_for_foo_with_deps() {
257239
.file("a/src/lib.rs", "pub fn hello() {}")
258240
.build();
259241

260-
p.cargo("rustc -v --crate-type cdylib -Zunstable-options")
261-
.masquerade_as_nightly_cargo(&["crate-type"])
242+
p.cargo("rustc -v --crate-type cdylib")
262243
.with_stderr(
263244
"\
264245
[COMPILING] a v0.1.0 ([CWD]/a)
@@ -275,8 +256,7 @@ fn build_with_crate_type_for_foo_with_deps() {
275256
fn build_with_crate_types_for_foo() {
276257
let p = project().file("src/lib.rs", "").build();
277258

278-
p.cargo("rustc -v --crate-type lib,cdylib -Zunstable-options")
279-
.masquerade_as_nightly_cargo(&["crate-type"])
259+
p.cargo("rustc -v --crate-type lib,cdylib")
280260
.with_stderr(
281261
"\
282262
[COMPILING] foo v0.0.1 ([CWD])
@@ -307,8 +287,7 @@ fn build_with_crate_type_to_example() {
307287
.file("examples/ex.rs", "")
308288
.build();
309289

310-
p.cargo("rustc -v --example ex --crate-type cdylib -Zunstable-options")
311-
.masquerade_as_nightly_cargo(&["crate-type"])
290+
p.cargo("rustc -v --example ex --crate-type cdylib")
312291
.with_stderr(
313292
"\
314293
[COMPILING] foo v0.0.1 ([CWD])
@@ -340,8 +319,7 @@ fn build_with_crate_types_to_example() {
340319
.file("examples/ex.rs", "")
341320
.build();
342321

343-
p.cargo("rustc -v --example ex --crate-type lib,cdylib -Zunstable-options")
344-
.masquerade_as_nightly_cargo(&["crate-type"])
322+
p.cargo("rustc -v --example ex --crate-type lib,cdylib")
345323
.with_stderr(
346324
"\
347325
[COMPILING] foo v0.0.1 ([CWD])
@@ -377,8 +355,7 @@ fn build_with_crate_types_to_one_of_multi_examples() {
377355
.file("examples/ex2.rs", "")
378356
.build();
379357

380-
p.cargo("rustc -v --example ex1 --crate-type lib,cdylib -Zunstable-options")
381-
.masquerade_as_nightly_cargo(&["crate-type"])
358+
p.cargo("rustc -v --example ex1 --crate-type lib,cdylib")
382359
.with_stderr(
383360
"\
384361
[COMPILING] foo v0.0.1 ([CWD])

0 commit comments

Comments
 (0)