Skip to content

Commit 13bcdba

Browse files
authored
Rollup merge of #138864 - Urgau:rework-print-options-doc, r=jieyouxu
Rework `--print` options documentation This PR reworks the `--print` options documentation, by making it more like codegen options with a dedicated page. I also added some examples and split some paragraph into multiple paragraph since we now have more place. r? ```@jieyouxu```
2 parents dfd83be + 7210df1 commit 13bcdba

File tree

3 files changed

+214
-52
lines changed

3 files changed

+214
-52
lines changed

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [What is rustc?](what-is-rustc.md)
44
- [Command-line Arguments](command-line-arguments.md)
5+
- [Print Options](command-line-arguments/print-options.md)
56
- [Codegen Options](codegen-options/index.md)
67
- [Jobserver](jobserver.md)
78
- [Lints](lints/index.md)

src/doc/rustc/src/command-line-arguments.md

+1-52
Original file line numberDiff line numberDiff line change
@@ -247,58 +247,7 @@ types to stdout at the same time will result in an error.
247247
<a id="option-print"></a>
248248
## `--print`: print compiler information
249249

250-
This flag prints out various information about the compiler. This flag may be
251-
specified multiple times, and the information is printed in the order the
252-
flags are specified. Specifying a `--print` flag will usually disable the
253-
[`--emit`](#option-emit) step and will only print the requested information.
254-
The valid types of print values are:
255-
256-
- `crate-name` — The name of the crate.
257-
- `file-names` — The names of the files created by the `link` emit kind.
258-
- `sysroot` — Path to the sysroot.
259-
- `target-libdir` — Path to the target libdir.
260-
- `host-tuple` — The target-tuple string of the host compiler (e.g. `x86_64-unknown-linux-gnu`)
261-
- `cfg` — List of cfg values. See [conditional compilation] for more
262-
information about cfg values.
263-
- `target-list` — List of known targets. The target may be selected with the
264-
`--target` flag.
265-
- `target-cpus` — List of available CPU values for the current target. The
266-
target CPU may be selected with the [`-C target-cpu=val`
267-
flag](codegen-options/index.md#target-cpu).
268-
- `target-features` — List of available target features for the current
269-
target. Target features may be enabled with the [`-C target-feature=val`
270-
flag](codegen-options/index.md#target-feature). This flag is unsafe. See
271-
[known issues](targets/known-issues.md) for more details.
272-
- `relocation-models` — List of relocation models. Relocation models may be
273-
selected with the [`-C relocation-model=val`
274-
flag](codegen-options/index.md#relocation-model).
275-
- `code-models` — List of code models. Code models may be selected with the
276-
[`-C code-model=val` flag](codegen-options/index.md#code-model).
277-
- `tls-models` — List of Thread Local Storage models supported. The model may
278-
be selected with the `-Z tls-model=val` flag.
279-
- `native-static-libs` — This may be used when creating a `staticlib` crate
280-
type. If this is the only flag, it will perform a full compilation and
281-
include a diagnostic note that indicates the linker flags to use when
282-
linking the resulting static library. The note starts with the text
283-
`native-static-libs:` to make it easier to fetch the output.
284-
- `link-args` — This flag does not disable the `--emit` step. When linking,
285-
this flag causes `rustc` to print the full linker invocation in a
286-
human-readable form. This can be useful when debugging linker options. The
287-
exact format of this debugging output is not a stable guarantee, other than
288-
that it will include the linker executable and the text of each command-line
289-
argument passed to the linker.
290-
- `deployment-target` — The currently selected [deployment target] (or minimum OS version)
291-
for the selected Apple platform target. This value can be used or passed along to other
292-
components alongside a Rust build that need this information, such as C compilers.
293-
This returns rustc's minimum supported deployment target if no `*_DEPLOYMENT_TARGET` variable
294-
is present in the environment, or otherwise returns the variable's parsed value.
295-
296-
A filepath may optionally be specified for each requested information kind, in
297-
the format `--print KIND=PATH`, just like for `--emit`. When a path is
298-
specified, information will be written there instead of to stdout.
299-
300-
[conditional compilation]: ../reference/conditional-compilation.html
301-
[deployment target]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html
250+
This flag will allow you to set [print options](command-line-arguments/print-options.md).
302251

303252
<a id="option-g-debug"></a>
304253
## `-g`: include debug information
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Print Options
2+
3+
All of these options are passed to `rustc` via the `--print` flag.
4+
5+
Those options prints out various information about the compiler. Multiple options can be
6+
specified, and the information is printed in the order the options are specified.
7+
8+
Specifying an option will usually disable the [`--emit`](../command-line-arguments.md#option-emit)
9+
step and will only print the requested information.
10+
11+
A filepath may optionally be specified for each requested information kind, in the format
12+
`--print KIND=PATH`, just like for `--emit`. When a path is specified, information will be
13+
written there instead of to stdout.
14+
15+
## `crate-name`
16+
17+
The name of the crate.
18+
19+
Generally coming from either from the `#![crate_name = "..."]` attribute,
20+
[`--crate-name` flag](../command-line-arguments.md#option-crate-name) or the filename.
21+
22+
Example:
23+
24+
```bash
25+
$ rustc --print crate-name --crate-name my_crate a.rs
26+
my_crate
27+
```
28+
29+
## `file-names`
30+
31+
The names of the files created by the `link` emit kind.
32+
33+
## `sysroot`
34+
35+
Abosulte path to the sysroot.
36+
37+
Example (with rustup and the stable toolchain):
38+
39+
```bash
40+
$ rustc --print sysroot a.rs
41+
/home/[REDACTED]/.rustup/toolchains/stable-x86_64-unknown-linux-gnu
42+
```
43+
44+
## `target-libdir`
45+
46+
Path to the target libdir.
47+
48+
Example (with rustup and the stable toolchain):
49+
50+
```bash
51+
$ rustc --print target-libdir a.rs
52+
/home/[REDACTED]/.rustup/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib
53+
```
54+
55+
## `host-tuple`
56+
57+
The target-tuple string of the host compiler.
58+
59+
Example:
60+
61+
```bash
62+
$ rustc --print host-tuple a.rs
63+
x86_64-unknown-linux-gnu
64+
```
65+
66+
Example with the `--target` flag:
67+
68+
```bash
69+
$ rustc --print host-tuple --target "armv7-unknown-linux-gnueabihf" a.rs
70+
x86_64-unknown-linux-gnu
71+
```
72+
73+
## `cfg`
74+
75+
List of cfg values. See [conditional compilation] for more information about cfg values.
76+
77+
Example (for `x86_64-unknown-linux-gnu`):
78+
79+
```bash
80+
$ rustc --print cfg a.rs
81+
debug_assertions
82+
panic="unwind"
83+
target_abi=""
84+
target_arch="x86_64"
85+
target_endian="little"
86+
target_env="gnu"
87+
target_family="unix"
88+
target_feature="fxsr"
89+
target_feature="sse"
90+
target_feature="sse2"
91+
target_has_atomic="16"
92+
target_has_atomic="32"
93+
target_has_atomic="64"
94+
target_has_atomic="8"
95+
target_has_atomic="ptr"
96+
target_os="linux"
97+
target_pointer_width="64"
98+
target_vendor="unknown"
99+
unix
100+
```
101+
102+
## `target-list`
103+
104+
List of known targets. The target may be selected with the `--target` flag.
105+
106+
## `target-cpus`
107+
108+
List of available CPU values for the current target. The target CPU may be selected with
109+
the [`-C target-cpu=val` flag](../codegen-options/index.md#target-cpu).
110+
111+
## `target-features`
112+
113+
List of available target features for the *current target*.
114+
115+
Target features may be enabled with the **unsafe**
116+
[`-C target-feature=val` flag](../codegen-options/index.md#target-feature).
117+
118+
See [known issues](../targets/known-issues.md) for more details.
119+
120+
## `relocation-models`
121+
122+
List of relocation models. Relocation models may be selected with the
123+
[`-C relocation-model=val` flag](../codegen-options/index.md#relocation-model).
124+
125+
Example:
126+
127+
```bash
128+
$ rustc --print relocation-models a.rs
129+
Available relocation models:
130+
static
131+
pic
132+
pie
133+
dynamic-no-pic
134+
ropi
135+
rwpi
136+
ropi-rwpi
137+
default
138+
```
139+
140+
## `code-models`
141+
142+
List of code models. Code models may be selected with the
143+
[`-C code-model=val` flag](../codegen-options/index.md#code-model).
144+
145+
Example:
146+
147+
```bash
148+
$ rustc --print code-models a.rs
149+
Available code models:
150+
tiny
151+
small
152+
kernel
153+
medium
154+
large
155+
```
156+
157+
## `tls-models`
158+
159+
List of Thread Local Storage models supported. The model may be selected with the
160+
`-Z tls-model=val` flag.
161+
162+
Example:
163+
164+
```bash
165+
$ rustc --print tls-models a.rs
166+
Available TLS models:
167+
global-dynamic
168+
local-dynamic
169+
initial-exec
170+
local-exec
171+
emulated
172+
```
173+
174+
## `native-static-libs`
175+
176+
This may be used when creating a `staticlib` crate type.
177+
178+
If this is the only flag, it will perform a full compilation and include a diagnostic note
179+
that indicates the linker flags to use when linking the resulting static library.
180+
181+
The note starts with the text `native-static-libs:` to make it easier to fetch the output.
182+
183+
Example:
184+
185+
```bash
186+
$ rustc --print native-static-libs --crate-type staticlib a.rs
187+
note: Link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms.
188+
189+
note: native-static-libs: -lgcc_s -lutil [REDACTED] -lpthread -lm -ldl -lc
190+
```
191+
192+
## `link-args`
193+
194+
This flag does not disable the `--emit` step. This can be useful when debugging linker options.
195+
196+
When linking, this flag causes `rustc` to print the full linker invocation in a human-readable
197+
form. The exact format of this debugging output is not a stable guarantee, other than that it
198+
will include the linker executable and the text of each command-line argument passed to the
199+
linker.
200+
201+
## `deployment-target`
202+
203+
The currently selected [deployment target] (or minimum OS version) for the selected Apple
204+
platform target.
205+
206+
This value can be used or passed along to other components alongside a Rust build that need
207+
this information, such as C compilers. This returns rustc's minimum supported deployment target
208+
if no `*_DEPLOYMENT_TARGET` variable is present in the environment, or otherwise returns the
209+
variable's parsed value.
210+
211+
[conditional compilation]: ../../reference/conditional-compilation.html
212+
[deployment target]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html

0 commit comments

Comments
 (0)