|
| 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