When working with gcc, I can get what gcc thinks is my host's triplet by running gcc -dumpmachine
. On my current system, this gives me x86_64-linux-gnu
.
How can I get stable rustc
to print my host triple? (x86_64-unknown-linux-gnu
in this case)
rustc
's documentation doesn't seem to contain anything relevant besides the --print
and --version
. Neither seem to produce the host target triple.
Clarification: with two answers being given about nightly so far, I want to stress that this question is specifically about stable rustc
compilers.
With Rust nightly, you can print the "target spec JSON":
$ rustc +nightly -Z unstable-options --print target-spec-json
{
"arch": "x86_64",
"cpu": "x86-64",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"dynamic-linking": true,
"env": "gnu",
"executables": true,
"has-elf-tls": true,
"has-rpath": true,
"is-builtin": true,
"linker-flavor": "gcc",
"linker-is-gnu": true,
"llvm-target": "x86_64-unknown-linux-gnu",
"max-atomic-width": 64,
"os": "linux",
"position-independent-executables": true,
"pre-link-args": {
"gcc": [
"-Wl,--as-needed",
"-Wl,-z,noexecstack",
"-m64"
]
},
"relro-level": "full",
"stack-probes": true,
"target-c-int-width": "32",
"target-endian": "little",
"target-family": "unix",
"target-pointer-width": "64",
"vendor": "unknown"
}
To parse the target triple from this on the command line, you could use a tool like jq
:
$ rustc +nightly -Z unstable-options --print target-spec-json | jq -r '."llvm-target"'
x86_64-unknown-linux-gnu
This isn't stable yet (and therefore requires the -Z unstable-options
compiler option), but it probably will be in the future. The feature was added in #38061.
rustc --version --verbose
Will give you some output like:
rustc 1.35.0-nightly (474e7a648 2019-04-07)
binary: rustc
commit-hash: 474e7a6486758ea6fc761893b1a49cd9076fb0ab
commit-date: 2019-04-07
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0
Where host is your target triple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With