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
– Ixtlerustc
? I'm trying to avoid maintaining a handwritten mapping of triples if I can avoid it. – Clingfishgcc
's triplet output via bash and substitute it in a build command – Ixtle