Skip to content

Commit

Permalink
Update doc for --crate-type flag
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jul 9, 2022
1 parent 3066142 commit a474391
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 17 deletions.
17 changes: 17 additions & 0 deletions src/doc/man/cargo-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 70,19 @@ See the [the reference](../reference/profiles.html) for more details on profiles

{{> options-timings }}

{{#option "`--crate-type` _crate-type_"}}
Build for the given crate type. This flag accepts a comma-separated list of
1 or more crate types, of which the allowed values are the same as `crate-type`
field in the manifest for configurating a Cargo target. See
[`crate-type` field](../reference/cargo-targets.html#the-crate-type-field)
for possible values.

If the manifest contains a list, and `--crate-type` is provided,
the command-line argument value will override what is in the manifest.

This flag only works when building a `lib` or `example` library target.
{{/option}}

{{/options}}

### Output Options
Expand Down Expand Up @@ -123,5 136,9 @@ See the [the reference](../reference/profiles.html) for more details on profiles

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

3. Override `crate-type` field in Cargo.toml with command-line option:

cargo rustc --lib --crate-type lib,cdylib

## SEE ALSO
{{man "cargo" 1}}, {{man "cargo-build" 1}}, {{man "rustc" 1}}
17 changes: 17 additions & 0 deletions src/doc/man/generated_txt/cargo-rustc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 191,19 @@ OPTIONS
o json (unstable, requires -Zunstable-options): Emit
machine-readable JSON information about timing information.

--crate-type crate-type
Build for the given crate type. This flag accepts a comma-separated
list of 1 or more crate types, of which the allowed values are the
same as crate-type field in the manifest for configurating a Cargo
target. See crate-type field
<https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-crate-type-field>
for possible values.

If the manifest contains a list, and --crate-type is provided, the
command-line argument value will override what is in the manifest.

This flag only works when building a lib or example library target.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down Expand Up @@ -339,6 352,10 @@ EXAMPLES

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

3. Override crate-type field in Cargo.toml with command-line option:

cargo rustc --lib --crate-type lib,cdylib

SEE ALSO
cargo(1), cargo-build(1), rustc(1)

15 changes: 15 additions & 0 deletions src/doc/src/commands/cargo-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 226,17 @@ information about timing information.</li>



<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>
<dd class="option-desc">Build for the given crate type. This flag accepts a comma-separated list of
1 or more crate types, of which the allowed values are the same as <code>crate-type</code>
field in the manifest for configurating a Cargo target. See
<a href="../reference/cargo-targets.html#the-crate-type-field"><code>crate-type</code> field</a>
for possible values.</p>
<p>If the manifest contains a list, and <code>--crate-type</code> is provided,
the command-line argument value will override what is in the manifest.</p>
<p>This flag only works when building a <code>lib</code> or <code>example</code> library target.</dd>


</dl>

### Output Options
Expand Down Expand Up @@ -410,5 421,9 @@ details on environment variables that Cargo reads.

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

3. Override `crate-type` field in Cargo.toml with command-line option:

cargo rustc --lib --crate-type lib,cdylib

## SEE ALSO
[cargo(1)](cargo.html), [cargo-build(1)](cargo-build.html), [rustc(1)](https://doc.rust-lang.org/rustc/index.html)
23 changes: 6 additions & 17 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,23 437,6 @@ like to stabilize it somehow!

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

### crate-type
* Tracking Issue: [#10083](https://github.com/rust-lang/cargo/issues/10083)
* RFC: [#3180](https://github.com/rust-lang/rfcs/pull/3180)
* Original Pull Request: [#10093](https://github.com/rust-lang/cargo/pull/10093)

`cargo rustc --crate-type=lib,cdylib` forwards the `--crate-type` flag to `rustc`.
This runs `rustc` with the corresponding
[`--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)
flag, and compiling.

When using it, it requires the `-Z unstable-options`
command-line option:

```console
cargo rustc --crate-type lib,cdylib -Z unstable-options
```

### keep-going
* Tracking Issue: [#0](https://github.com/rust-lang/cargo/issues/10496)

Expand Down Expand Up @@ -1569,3 1552,9 @@ unstable and require `-Zunstable-options`.)
The `--config` CLI option has been stabilized in the 1.63 release. See
the [config documentation](config.html#command-line-overrides) for more
information.

### crate-type

The `--crate-type` flag for `cargo rustc` has been stabilized in the 1.64
release. See the [`cargo rustc` documentation](../commands/cargo-rustc.md)
for more information.
24 changes: 24 additions & 0 deletions src/etc/man/cargo-rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 224,20 @@ and does not provide machine\-readable timing data.
information about timing information.
.RE
.RE
.sp
\fB\-\-crate\-type\fR \fIcrate\-type\fR
.RS 4
Build for the given crate type. This flag accepts a comma\-separated list of
1 or more crate types, of which the allowed values are the same as \fBcrate\-type\fR
field in the manifest for configurating a Cargo target. See
\fI\f(BIcrate\-type\fI field\fR <https://doc.rust\-lang.org/cargo/reference/cargo\-targets.html#the\-crate\-type\-field>
for possible values.
.sp
If the manifest contains a list, and \fB\-\-crate\-type\fR is provided,
the command\-line argument value will override what is in the manifest.
.sp
This flag only works when building a \fBlib\fR or \fBexample\fR library target.
.RE
.SS "Output Options"
.sp
\fB\-\-target\-dir\fR \fIdirectory\fR
Expand Down Expand Up @@ -432,5 446,15 @@ cargo rustc \-\-lib \-\- \-Z print\-type\-sizes
.fi
.RE
.RE
.sp
.RS 4
\h'-04' 3.\h' 01'Override \fBcrate\-type\fR field in Cargo.toml with command\-line option:
.sp
.RS 4
.nf
cargo rustc \-\-lib \-\-crate\-type lib,cdylib
.fi
.RE
.RE
.SH "SEE ALSO"
\fBcargo\fR(1), \fBcargo\-build\fR(1), \fBrustc\fR(1)

0 comments on commit a474391

Please sign in to comment.