I want to override a build script, which means adding a configuration section that looks like this:
[target.x86_64-unknown-linux-gnu.foo]
rustc-link-search = ["/path/to/foo"]
rustc-link-lib = ["foo"]
root = "/path/to/foo"
key = "value"
But I'm using a Mac, so x86_64-unknown-linux-gnu
isn't the correct target triple.
How do I discover which target triple rustc or cargo are currently using?
rustc --print cfg
prints a list of values that don't seem to correspond to the triple (there's no unknown
in there, in particular).
rustc --print target-list
displays all available targets; I just want the default.
Tier 3 targets are those which the Rust codebase has support for, but which the Rust project does not build or test automatically, so they may or may not work.
rustup is a toolchain multiplexer. It installs and manages many Rust toolchains and presents them all through a single set of tools installed to ~/. cargo/bin .
Tradeoff #4: LLVM and poor LLVM IR generationrustc uses LLVM to generate code. LLVM can generate very fast code, but it comes at a cost. LLVM is a very big system. In fact, LLVM code makes up the majority of the Rust codebase.
cargo uses rustc -vV
to detect the default target triple (source). We can do the same thing:
use std::process::Command;
use anyhow::{format_err, Context, Result};
use std::str;
fn get_target() -> Result<String> {
let output = Command::new("rustc")
.arg("-vV")
.output()
.context("Failed to run rustc to get the host target")?;
let output = str::from_utf8(&output.stdout).context("`rustc -vV` didn't return utf8 output")?;
let field = "host: ";
let host = output
.lines()
.find(|l| l.starts_with(field))
.map(|l| &l[field.len()..])
.ok_or_else(|| {
format_err!(
"`rustc -vV` didn't have a line for `{}`, got:\n{}",
field.trim(),
output
)
})?
.to_string();
Ok(host)
}
fn main() -> Result<()> {
let host = get_target()?;
println!("target triple: {}", host);
Ok(())
}
rustc --print cfg
will output something like the following:
$ rustc --print cfg
debug_assertions
target_arch="x86_64"
target_endian="little"
target_env="gnu"
target_family="unix"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_os="linux"
target_pointer_width="64"
target_vendor="unknown"
unix
The target is <arch>-<vendor>-<os>-<env>
.
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