Skip to content

Commit

Permalink
Auto merge of #125579 - Noratrieb:print-host, r=davidtwco
Browse files Browse the repository at this point in the history
Add `--print host-tuple` to print host target tuple

People often parse `-vV` output to get to the host tuple, which is annoying to do. It's easier to just get it directly.

I called it "host-tuple" instead of "host" because it's clearer that it's just the target name. I'm open to different names, but I think this one is fine.

a quick GitHub search for `'^host` reveals many instances of people doing the parsing, for example:

https://github.com/japaric/xargo/blob/68e0ca57cd90837fe02f262f074182f9cfeb6227/README.md?plain=1#L369
https://github.com/taiki-e/setup-cross-toolchain-action/blob/0e38473b0c562d6db19a98d3ec20a80f7ac189ae/main.sh#L96
https://github.com/taiki-e/cargo-llvm-cov/blob/8a3553b86551eabf9c30c060b1f72a5bbccb98c6/README.md?plain=1#L625
https://github.com/SiliconLabs/cpc-nvm3/blob/43f3ec39709b30700ef7f39d91fa647974323bf1/do.sh#L35

needs a compiler FCP. I could also do an MCP but I think just an FCP here makes the most sense.
  • Loading branch information
bors committed Nov 2, 2024
2 parents b3f75cc + ba48151 commit 8ccb78e
Show file tree
Hide file tree
Showing 40 changed files with 180 additions and 171 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ impl GlobalAsmConfig {
GlobalAsmConfig {
assembler: crate::toolchain::get_toolchain_binary(tcx.sess, "as"),
target: match &tcx.sess.opts.target_triple {
rustc_target::spec::TargetTriple::TargetTriple(triple) => triple.clone(),
rustc_target::spec::TargetTriple::TargetJson { path_for_rustdoc, .. } => {
rustc_target::spec::TargetTuple::TargetTuple(triple) => triple.clone(),
rustc_target::spec::TargetTuple::TargetJson { path_for_rustdoc, .. } => {
path_for_rustdoc.to_str().unwrap().to_owned()
}
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {

// Wasm statics with custom link sections get special treatment as they
// go into custom sections of the wasm executable.
if self.tcx.sess.opts.target_triple.triple().starts_with("wasm32") {
if self.tcx.sess.opts.target_triple.tuple().starts_with("wasm32") {
if let Some(_section) = attrs.link_section {
unimplemented!();
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data:
}

fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
let triple = cgcx.opts.target_triple.triple();
let triple = cgcx.opts.target_triple.tuple();
triple.contains("-ios")
|| triple.contains("-darwin")
|| triple.contains("-tvos")
Expand All @@ -955,7 +955,7 @@ fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
}

fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
cgcx.opts.target_triple.triple().contains("-aix")
cgcx.opts.target_triple.tuple().contains("-aix")
}

pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) -> &'static CStr {
Expand Down Expand Up @@ -1031,7 +1031,7 @@ unsafe fn embed_bitcode(
let is_aix = target_is_aix(cgcx);
let is_apple = target_is_apple(cgcx);
unsafe {
if is_apple || is_aix || cgcx.opts.target_triple.triple().starts_with("wasm") {
if is_apple || is_aix || cgcx.opts.target_triple.tuple().starts_with("wasm") {
// We don't need custom section flags, create LLVM globals.
let llconst = common::bytes_in_context(llcx, bitcode);
let llglobal = llvm::LLVMAddGlobal(
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ fn link_natively(
{
let is_vs_installed = windows_registry::find_vs_version().is_ok();
let has_linker = windows_registry::find_tool(
sess.opts.target_triple.triple(),
sess.opts.target_triple.tuple(),
"link.exe",
)
.is_some();
Expand Down Expand Up @@ -1323,10 +1323,8 @@ fn link_sanitizer_runtime(
} else {
let default_sysroot =
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
let default_tlib = filesearch::make_target_lib_path(
&default_sysroot,
sess.opts.target_triple.triple(),
);
let default_tlib =
filesearch::make_target_lib_path(&default_sysroot, sess.opts.target_triple.tuple());
default_tlib
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn get_linker<'a>(
self_contained: bool,
target_cpu: &'a str,
) -> Box<dyn Linker + 'a> {
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.triple(), "link.exe");
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe");

// If our linker looks like a batch script on Windows then to execute this
// we'll need to spawn `cmd` explicitly. This is primarily done to handle
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use rustc_session::{EarlyDiagCtxt, Session, config, filesearch};
use rustc_span::FileName;
use rustc_span::source_map::FileLoader;
use rustc_target::json::ToJson;
use rustc_target::spec::{Target, TargetTriple};
use rustc_target::spec::{Target, TargetTuple};
use time::OffsetDateTime;
use tracing::trace;

Expand Down Expand Up @@ -731,6 +731,7 @@ fn print_crate_info(
targets.sort_unstable();
println_info!("{}", targets.join("\n"));
}
HostTuple => println_info!("{}", rustc_session::config::host_tuple()),
Sysroot => println_info!("{}", sess.sysroot.display()),
TargetLibdir => println_info!("{}", sess.target_tlib_path.dir.display()),
TargetSpec => {
Expand All @@ -739,7 +740,7 @@ fn print_crate_info(
AllTargetSpecs => {
let mut targets = BTreeMap::new();
for name in rustc_target::spec::TARGETS {
let triple = TargetTriple::from_triple(name);
let triple = TargetTuple::from_tuple(name);
let target = Target::expect_builtin(&triple);
targets.insert(name, target.to_json());
}
Expand Down Expand Up @@ -918,7 +919,7 @@ pub fn version_at_macro_invocation(
safe_println!("binary: {binary}");
safe_println!("commit-hash: {commit_hash}");
safe_println!("commit-date: {commit_date}");
safe_println!("host: {}", config::host_triple());
safe_println!("host: {}", config::host_tuple());
safe_println!("release: {release}");

let debug_flags = matches.opt_strs("Z");
Expand Down Expand Up @@ -1495,7 +1496,7 @@ fn report_ice(
}

let version = util::version_str!().unwrap_or("unknown_version");
let triple = config::host_triple();
let tuple = config::host_tuple();

static FIRST_PANIC: AtomicBool = AtomicBool::new(true);

Expand All @@ -1505,7 +1506,7 @@ fn report_ice(
Ok(mut file) => {
dcx.emit_note(session_diagnostics::IcePath { path: path.clone() });
if FIRST_PANIC.swap(false, Ordering::SeqCst) {
let _ = write!(file, "\n\nrustc version: {version}\nplatform: {triple}");
let _ = write!(file, "\n\nrustc version: {version}\nplatform: {tuple}");
}
Some(file)
}
Expand All @@ -1518,12 +1519,12 @@ fn report_ice(
.map(PathBuf::from)
.map(|env_var| session_diagnostics::IcePathErrorEnv { env_var }),
});
dcx.emit_note(session_diagnostics::IceVersion { version, triple });
dcx.emit_note(session_diagnostics::IceVersion { version, triple: tuple });
None
}
}
} else {
dcx.emit_note(session_diagnostics::IceVersion { version, triple });
dcx.emit_note(session_diagnostics::IceVersion { version, triple: tuple });
None
};

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_macros::Subdiagnostic;
use rustc_span::Span;
use rustc_span::edition::Edition;
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTuple};
use rustc_type_ir::{ClosureKind, FloatTy};
use {rustc_ast as ast, rustc_hir as hir};

Expand Down Expand Up @@ -89,7 +89,7 @@ into_diag_arg_using_display!(
MacroRulesNormalizedIdent,
ParseIntError,
StackProtector,
&TargetTriple,
&TargetTuple,
SplitDebuginfo,
ExitStatus,
ErrCode,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
"we would appreciate a joke overview: \
https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675",
);
diag.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_triple(),));
diag.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_tuple(),));
if let Some((flags, excluded_cargo_defaults)) = rustc_session::utils::extra_compiler_flags() {
diag.note(format!("compiler flags: {}", flags.join(" ")));
if excluded_cargo_defaults {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_data_structures::sync;
use rustc_metadata::{DylibError, load_symbol_from_dylib};
use rustc_middle::ty::CurrentGcx;
use rustc_parse::validate_attr;
use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, host_triple};
use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, host_tuple};
use rustc_session::filesearch::sysroot_candidates;
use rustc_session::lint::{self, BuiltinLintDiag, LintBuffer};
use rustc_session::output::{CRATE_TYPES, categorize_crate_type};
Expand Down Expand Up @@ -310,7 +310,7 @@ fn get_codegen_sysroot(
"cannot load the default codegen backend twice"
);

let target = host_triple();
let target = host_tuple();
let sysroot_candidates = sysroot_candidates();

let sysroot = iter::once(sysroot)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rustc_session::search_paths::PathKind;
use rustc_span::edition::Edition;
use rustc_span::symbol::{Ident, Symbol, sym};
use rustc_span::{DUMMY_SP, Span};
use rustc_target::spec::{PanicStrategy, Target, TargetTriple};
use rustc_target::spec::{PanicStrategy, Target, TargetTuple};
use tracing::{debug, info, trace};

use crate::errors;
Expand Down Expand Up @@ -506,7 +506,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
locator.reset();
locator.is_proc_macro = true;
locator.target = &self.sess.host;
locator.triple = TargetTriple::from_triple(config::host_triple());
locator.tuple = TargetTuple::from_tuple(config::host_tuple());
locator.filesearch = self.sess.host_filesearch(path_kind);

let Some(host_result) = self.load(locator)? else {
Expand Down Expand Up @@ -635,7 +635,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
// FIXME: why is this condition necessary? It was adding in #33625 but I
// don't know why and the original author doesn't remember ...
let can_reuse_cratenum =
locator.triple == self.sess.opts.target_triple || locator.is_proc_macro;
locator.tuple == self.sess.opts.target_triple || locator.is_proc_macro;
Ok(Some(if can_reuse_cratenum {
let mut result = LoadResult::Loaded(library);
for (cnum, data) in self.cstore.iter_crate_data() {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_errors::codes::*;
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol, sym};
use rustc_target::spec::{PanicStrategy, TargetTriple};
use rustc_target::spec::{PanicStrategy, TargetTuple};

use crate::fluent_generated as fluent;
use crate::locator::CrateFlavor;
Expand Down Expand Up @@ -630,7 +630,7 @@ pub struct CannotFindCrate {
pub current_crate: String,
pub is_nightly_build: bool,
pub profiler_runtime: Symbol,
pub locator_triple: TargetTriple,
pub locator_triple: TargetTuple,
pub is_ui_testing: bool,
}

Expand All @@ -641,7 +641,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate {
diag.arg("crate_name", self.crate_name);
diag.arg("current_crate", self.current_crate);
diag.arg("add_info", self.add_info);
diag.arg("locator_triple", self.locator_triple.triple());
diag.arg("locator_triple", self.locator_triple.tuple());
diag.code(E0463);
diag.span(self.span);
if self.crate_name == sym::std || self.crate_name == sym::core {
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ use rustc_session::search_paths::PathKind;
use rustc_session::utils::CanonicalizedPath;
use rustc_span::Span;
use rustc_span::symbol::Symbol;
use rustc_target::spec::{Target, TargetTriple};
use rustc_target::spec::{Target, TargetTuple};
use tracing::{debug, info};

use crate::creader::{Library, MetadataLoader};
Expand All @@ -252,7 +252,7 @@ pub(crate) struct CrateLocator<'a> {
pub hash: Option<Svh>,
extra_filename: Option<&'a str>,
pub target: &'a Target,
pub triple: TargetTriple,
pub tuple: TargetTuple,
pub filesearch: FileSearch<'a>,
pub is_proc_macro: bool,

Expand Down Expand Up @@ -338,7 +338,7 @@ impl<'a> CrateLocator<'a> {
hash,
extra_filename,
target: &sess.target,
triple: sess.opts.target_triple.clone(),
tuple: sess.opts.target_triple.clone(),
filesearch: sess.target_filesearch(path_kind),
is_proc_macro: false,
crate_rejections: CrateRejections::default(),
Expand Down Expand Up @@ -677,8 +677,8 @@ impl<'a> CrateLocator<'a> {
return None;
}

if header.triple != self.triple {
info!("Rejecting via crate triple: expected {} got {}", self.triple, header.triple);
if header.triple != self.tuple {
info!("Rejecting via crate triple: expected {} got {}", self.tuple, header.triple);
self.crate_rejections.via_triple.push(CrateMismatch {
path: libpath.to_path_buf(),
got: header.triple.to_string(),
Expand Down Expand Up @@ -766,7 +766,7 @@ impl<'a> CrateLocator<'a> {
CrateError::LocatorCombined(Box::new(CombinedLocatorError {
crate_name: self.crate_name,
root,
triple: self.triple,
triple: self.tuple,
dll_prefix: self.target.dll_prefix.to_string(),
dll_suffix: self.target.dll_suffix.to_string(),
crate_rejections: self.crate_rejections,
Expand Down Expand Up @@ -909,7 +909,7 @@ struct CrateRejections {
pub(crate) struct CombinedLocatorError {
crate_name: Symbol,
root: Option<CratePaths>,
triple: TargetTriple,
triple: TargetTuple,
dll_prefix: String,
dll_suffix: String,
crate_rejections: CrateRejections,
Expand Down Expand Up @@ -1034,7 +1034,7 @@ impl CrateError {
dcx.emit_err(errors::NoCrateWithTriple {
span,
crate_name,
locator_triple: locator.triple.triple(),
locator_triple: locator.triple.tuple(),
add_info,
found_crates,
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ impl MetadataBlob {
root.stable_crate_id
)?;
writeln!(out, "proc_macro {:?}", root.proc_macro_data.is_some())?;
writeln!(out, "triple {}", root.header.triple.triple())?;
writeln!(out, "triple {}", root.header.triple.tuple())?;
writeln!(out, "edition {}", root.edition)?;
writeln!(out, "symbol_mangling_version {:?}", root.symbol_mangling_version)?;
writeln!(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use rustc_span::edition::Edition;
use rustc_span::hygiene::{ExpnIndex, MacroKind, SyntaxContextData};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{self, ExpnData, ExpnHash, ExpnId, Span};
use rustc_target::spec::{PanicStrategy, TargetTriple};
use rustc_target::spec::{PanicStrategy, TargetTuple};
use table::TableBuilder;
use {rustc_ast as ast, rustc_attr as attr, rustc_hir as hir};

Expand Down Expand Up @@ -213,7 +213,7 @@ pub(crate) struct ProcMacroData {
/// If you do modify this struct, also bump the [`METADATA_VERSION`] constant.
#[derive(MetadataEncodable, MetadataDecodable)]
pub(crate) struct CrateHeader {
pub(crate) triple: TargetTriple,
pub(crate) triple: TargetTuple,
pub(crate) hash: Svh,
pub(crate) name: Symbol,
/// Whether this is the header for a proc-macro crate.
Expand Down
Loading

0 comments on commit 8ccb78e

Please sign in to comment.