From 966f4b3b0c906838e689a438a06b9ade4f839e5c Mon Sep 17 00:00:00 2001
From: Henry Jiang <henry.jiang1@ibm.com>
Date: Tue, 5 Nov 2024 12:58:37 -0500
Subject: [PATCH 1/3] add run-make support for aix

---
 src/tools/compiletest/src/directive-list.rs           | 1 +
 src/tools/run-make-support/src/external_deps/rustc.rs | 5 ++++-
 src/tools/run-make-support/src/targets.rs             | 6 ++++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/tools/compiletest/src/directive-list.rs b/src/tools/compiletest/src/directive-list.rs
index 980b3f6829a81..446e90978f6bc 100644
--- a/src/tools/compiletest/src/directive-list.rs
+++ b/src/tools/compiletest/src/directive-list.rs
@@ -35,6 +35,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
     "ignore-64bit",
     "ignore-aarch64",
     "ignore-aarch64-unknown-linux-gnu",
+    "ignore-aix",
     "ignore-android",
     "ignore-apple",
     "ignore-arm",
diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs
index 35d983dc607fd..c2989aedee1fd 100644
--- a/src/tools/run-make-support/src/external_deps/rustc.rs
+++ b/src/tools/run-make-support/src/external_deps/rustc.rs
@@ -5,7 +5,7 @@ use crate::command::Command;
 use crate::env::env_var;
 use crate::path_helpers::cwd;
 use crate::util::set_host_rpath;
-use crate::{is_darwin, is_msvc, is_windows, uname};
+use crate::{is_aix, is_darwin, is_msvc, is_windows, uname};
 
 /// Construct a new `rustc` invocation. This will automatically set the library
 /// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
@@ -365,6 +365,9 @@ impl Rustc {
             if is_msvc() { None } else { Some("-lstatic:-bundle=stdc++") }
         } else if is_darwin() {
             Some("-lc++")
+        } else if is_aix() {
+            self.cmd.arg("-lc++");
+            Some("-lc++abi")
         } else {
             match &uname()[..] {
                 "FreeBSD" | "SunOS" | "OpenBSD" => None,
diff --git a/src/tools/run-make-support/src/targets.rs b/src/tools/run-make-support/src/targets.rs
index 896abb73fc108..ae004fd0cbdd8 100644
--- a/src/tools/run-make-support/src/targets.rs
+++ b/src/tools/run-make-support/src/targets.rs
@@ -28,6 +28,12 @@ pub fn is_darwin() -> bool {
     target().contains("darwin")
 }
 
+/// Check if target uses AIX.
+#[must_use]
+pub fn is_aix() -> bool {
+    target().contains("aix")
+}
+
 /// Get the target OS on Apple operating systems.
 #[must_use]
 pub fn apple_os() -> &'static str {

From 904e897d07b848d8e17e7addb40bc56fb58cd2ec Mon Sep 17 00:00:00 2001
From: Henry Jiang <henry.jiang1@ibm.com>
Date: Tue, 5 Nov 2024 14:21:08 -0500
Subject: [PATCH 2/3] fix missing use decl

---
 src/tools/run-make-support/src/lib.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index 368b98c9f0dfd..1b2fd6cbe0614 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -77,7 +77,7 @@ pub use env::{env_var, env_var_os, set_current_dir};
 pub use run::{cmd, run, run_fail, run_with_args};
 
 /// Helpers for checking target information.
-pub use targets::{is_darwin, is_msvc, is_windows, llvm_components_contain, target, uname, apple_os};
+pub use targets::{is_aix, is_darwin, is_msvc, is_windows, llvm_components_contain, target, uname, apple_os};
 
 /// Helpers for building names of output artifacts that are potentially target-specific.
 pub use artifact_names::{

From 405017ac354c4d07300204abc7b7035b1776c9c1 Mon Sep 17 00:00:00 2001
From: Henry Jiang <henry.jiang1@ibm.com>
Date: Sun, 10 Nov 2024 21:52:18 -0500
Subject: [PATCH 3/3] refactor flags

---
 .../src/external_deps/rustc.rs                | 20 +++++++++----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs
index c2989aedee1fd..494daeca96364 100644
--- a/src/tools/run-make-support/src/external_deps/rustc.rs
+++ b/src/tools/run-make-support/src/external_deps/rustc.rs
@@ -346,7 +346,7 @@ impl Rustc {
         //     endif
         // endif
         // ```
-        let flag = if is_windows() {
+        if is_windows() {
             // So this is a bit hacky: we can't use the DLL version of libstdc++ because
             // it pulls in the DLL version of libgcc, which means that we end up with 2
             // instances of the DW2 unwinding implementation. This is a problem on
@@ -362,21 +362,19 @@ impl Rustc {
             // So we end up with the following hack: we link use static:-bundle to only
             // link the parts of libstdc++ that we actually use, which doesn't include
             // the dependency on the pthreads DLL.
-            if is_msvc() { None } else { Some("-lstatic:-bundle=stdc++") }
+            if !is_msvc() {
+                self.cmd.arg("-lstatic:-bundle=stdc++");
+            };
         } else if is_darwin() {
-            Some("-lc++")
+            self.cmd.arg("-lc++");
         } else if is_aix() {
             self.cmd.arg("-lc++");
-            Some("-lc++abi")
+            self.cmd.arg("-lc++abi");
         } else {
-            match &uname()[..] {
-                "FreeBSD" | "SunOS" | "OpenBSD" => None,
-                _ => Some("-lstdc++"),
-            }
+            if !matches!(&uname()[..], "FreeBSD" | "SunOS" | "OpenBSD") {
+                self.cmd.arg("-lstdc++");
+            };
         };
-        if let Some(flag) = flag {
-            self.cmd.arg(flag);
-        }
         self
     }
 }