使用 gcc 时,我可以通过运行gcc -dumpmachine
. 在我当前的系统上,这给了我x86_64-linux-gnu
.
我怎样才能稳定rustc
打印我的主机三倍?(x86_64-unknown-linux-gnu
在这种情况下)
rustc
的文档似乎不包含除--print
and之外的任何相关内容--version
。似乎都没有产生宿主目标三倍。
澄清:到目前为止,关于 nightly 给出了两个答案,我想强调这个问题专门针对稳定 rustc
的编译器。
使用 gcc 时,我可以通过运行gcc -dumpmachine
. 在我当前的系统上,这给了我x86_64-linux-gnu
.
我怎样才能稳定rustc
打印我的主机三倍?(x86_64-unknown-linux-gnu
在这种情况下)
rustc
的文档似乎不包含除--print
and之外的任何相关内容--version
。似乎都没有产生宿主目标三倍。
澄清:到目前为止,关于 nightly 给出了两个答案,我想强调这个问题专门针对稳定 rustc
的编译器。
使用 Rust nightly,您可以打印“目标规范 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"
}
要在命令行上从中解析目标三元组,您可以使用如下工具jq
:
$ rustc +nightly -Z unstable-options --print target-spec-json | jq -r '."llvm-target"'
x86_64-unknown-linux-gnu
这还不稳定(因此需要-Z unstable-options
编译器选项),但它可能会在未来出现。该功能是在#38061中添加的。
rustc --version --verbose
会给你一些输出,比如:
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
主机是您的目标三重奏。
rustc
(从版本 1.45.2 开始)似乎没有提供任何方法来获得主机目标三倍。
作为一种解决方法,我决定使用strace
一个小的虚拟程序来欺骗编译器显示主机三元组;rustc
根据平台三元组将预编译的库存储在单独的目录中。
这就是我最终的结果:
strace -f -e trace=file rustc <(echo "fn main(){};") 2>&1 | \
grep -E "(libstd-.*\.rlib)|(libcore-.*\.rlib)" | \
sed -E "s:^.*\"/.*/([^/]+-[^/]+(-[/^]+(-[^/]+)?)?)/.*\".*$:\1:g;t;d" | \
sort | uniq
它可以像您期望的那样工作,在 64 位 Linux 系统上安装 ABI rust x86_64-unknown-linux-gnu
。gnu
理论上,这应该适用于任何版本的 rustc。我可以确认它适用于 rustc 1.43.0(Ubuntu 18.04 附带)和 1.45.2。
以下是使用此命令时需要注意的一些注意事项:
<(..)
构造。可以修改此命令以使用显式临时文件,但会增加复杂性。uniq
(with --count
), sort
, 并head
选择访问次数最多的三元组。干杯!