Skip to content

Commit 12a539f

Browse files
authored
Rollup merge of #110668 - ehuss:fix-native-cpu-list, r=cuviper
Fix printing native CPU on cross-compiled compiler. If `rustc` is cross-compiled from a different host, then the "native" entry in `rustc --print=target-cpus` would not appear. There is a check in the printing code that will avoid printing the "native" entry if the user has passed `--target`. However, that check was comparing the `--target` value with the `LLVM_TARGET_TRIPLE` which is the triple of the host that `rustc` was built on (the "build" target in Rust lingo), not the target it was being built for (the "host" in Rust lingo). This fixes it to use the target that LLVM was built for (which I'm pretty sure this is the correct function to determine that). This fixes the cpu listing for aarch64-apple-darwin which is built on CI using the x86_64-apple-darwin host.
2 parents a557ed0 + e4e4110 commit 12a539f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,14 @@ static size_t getLongestEntryLength(ArrayRef<KV> Table) {
310310
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
311311
const TargetMachine *Target = unwrap(TM);
312312
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
313-
const Triple::ArchType HostArch = Triple(sys::getProcessTriple()).getArch();
313+
const Triple::ArchType HostArch = Triple(sys::getDefaultTargetTriple()).getArch();
314314
const Triple::ArchType TargetArch = Target->getTargetTriple().getArch();
315315
const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getCPUTable();
316316
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
317317

318318
printf("Available CPUs for this target:\n");
319+
// Don't print the "native" entry when the user specifies --target with a
320+
// different arch since that could be wrong or misleading.
319321
if (HostArch == TargetArch) {
320322
const StringRef HostCPU = sys::getHostCPUName();
321323
printf(" %-*s - Select the CPU of the current host (currently %.*s).\n",

0 commit comments

Comments
 (0)