From 59393dee5cc62e0222208d6f988095e5cdfe60df Mon Sep 17 00:00:00 2001
From: Ranjit Ranjan <ranjit.ranjan@ibm.com>
Date: Mon, 3 Feb 2025 02:32:22 -0600
Subject: [PATCH 2/3] aix enablement for xgboost

---
 include/xgboost/collective/socket.h  | 2 +-
 python-package/packager/nativelib.py | 2 ++
 python-package/xgboost/core.py       | 5 ++++-
 python-package/xgboost/libpath.py    | 2 ++
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/xgboost/collective/socket.h b/include/xgboost/collective/socket.h
index 84885cf31..146dc9947 100644
--- a/include/xgboost/collective/socket.h
+++ b/include/xgboost/collective/socket.h
@@ -319,7 +319,7 @@ class TCPSocket {
 #elif defined(__APPLE__)
     return domain_;
 #elif defined(__unix__)
-#ifndef __PASE__
+#if defined (__PASE__) && not defined(_AIX)
     std::int32_t domain;
     socklen_t len = sizeof(domain);
     xgboost_CHECK_SYS_CALL(
diff --git a/python-package/packager/nativelib.py b/python-package/packager/nativelib.py
index 1a3df2ea8..88c9420c0 100644
--- a/python-package/packager/nativelib.py
+++ b/python-package/packager/nativelib.py
@@ -22,6 +22,8 @@ def _lib_name() -> str:
         name = "libxgboost.dylib"
     elif system() == "Windows":
         name = "xgboost.dll"
+    elif system() == 'AIX':
+        name = 'libxgboost.a'
     else:
         raise NotImplementedError(f"System {system()} not supported")
     return name
diff --git a/python-package/xgboost/core.py b/python-package/xgboost/core.py
index f21290a50..cfb471bf8 100644
--- a/python-package/xgboost/core.py
+++ b/python-package/xgboost/core.py
@@ -208,7 +208,10 @@ def _load_lib() -> ctypes.CDLL:
             os.environ["PATH"] = os.pathsep.join(
                 pathBackup + [os.path.dirname(lib_path)]
             )
-            lib = ctypes.cdll.LoadLibrary(lib_path)
+            if sys.platform == 'aix':
+                lib = ctypes.cdll.LoadLibrary(lib_path + '(libxgboost.so)') 
+            else:
+                lib = ctypes.cdll.LoadLibrary(lib_path)
             setattr(lib, "path", os.path.normpath(lib_path))
             lib_success = True
             break
diff --git a/python-package/xgboost/libpath.py b/python-package/xgboost/libpath.py
index 92d46a0bb..36588d645 100644
--- a/python-package/xgboost/libpath.py
+++ b/python-package/xgboost/libpath.py
@@ -50,6 +50,8 @@ def find_lib_path() -> List[str]:
         dll_path = [os.path.join(p, "libxgboost.dylib") for p in dll_path]
     elif sys.platform == "cygwin":
         dll_path = [os.path.join(p, "cygxgboost.dll") for p in dll_path]
+    elif sys.platform == 'aix':
+        dll_path = [os.path.join(p, 'libxgboost.a') for p in dll_path]
     if platform.system() == "OS400":
         dll_path = [os.path.join(p, "libxgboost.so") for p in dll_path]
 
-- 
2.41.0

