From 87caaab3681b95fa633aac48b9794364e18c467d Mon Sep 17 00:00:00 2001
From: Josh Stone <jistone@redhat.com>
Date: Fri, 9 Jun 2023 15:23:08 -0700
Subject: [PATCH] Let environment variables override some default CPUs

---
 compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs | 2 +-
 compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs       | 2 +-
 compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs
index fd896e086b54..08d0c43d20b4 100644
--- a/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs
+++ b/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs
@@ -2,7 +2,7 @@
 
 pub fn target() -> Target {
     let mut base = super::linux_gnu_base::opts();
-    base.cpu = "ppc64le".into();
+    base.cpu = option_env!("RUSTC_TARGET_CPU_PPC64LE").unwrap_or("ppc64le").into();
     base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
     base.max_atomic_width = Some(64);
     base.stack_probes = StackProbeType::Inline;
diff --git a/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs
index f2c722b9a89d..17a14d10b27e 100644
--- a/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs
+++ b/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs
@@ -5,7 +5,7 @@ pub fn target() -> Target {
     let mut base = super::linux_gnu_base::opts();
     base.endian = Endian::Big;
     // z10 is the oldest CPU supported by LLVM
-    base.cpu = "z10".into();
+    base.cpu = option_env!("RUSTC_TARGET_CPU_S390X").unwrap_or("z10").into();
     // FIXME: The ABI implementation in cabi_s390x.rs is for now hard-coded to assume the no-vector
     // ABI. Pass the -vector feature string to LLVM to respect this assumption. On LLVM < 16, we
     // also strip v128 from the data_layout below to match the older LLVM's expectation.
diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs
index 2f970f87cc64..7ee62cd62a5c 100644
--- a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs
+++ b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs
@@ -2,7 +2,7 @@
 
 pub fn target() -> Target {
     let mut base = super::linux_gnu_base::opts();
-    base.cpu = "x86-64".into();
+    base.cpu = option_env!("RUSTC_TARGET_CPU_X86_64").unwrap_or("x86-64").into();
     base.plt_by_default = false;
     base.max_atomic_width = Some(64);
     base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
-- 
2.41.0

