commit 76b969a66e91f790cebdcc45a30aef0a0a910d6b Author: KV2773 Date: Thu Aug 13 12:33:52 2026 -0500 AIX support diff --git a/CMakeLists.txt b/CMakeLists.txt index 791e24bf0..bd992469c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -556,11 +556,26 @@ if(ONNX_BUILD_PYTHON) GIT_REPOSITORY ${_nanobind_URL} GIT_TAG v${_nanobind_VERSION} GIT_SHALLOW TRUE + PATCH_COMMAND git checkout . && git apply --whitespace=fix --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/cmake/external/nanobind_aix.patch ) FetchContent_MakeAvailable(nanobind) endif() - # Configure nanobind: https://nanobind.readthedocs.io/en/latest/api_cmake.html +if (CMAKE_SYSTEM_NAME STREQUAL "AIX") + nanobind_add_module( + onnx_cpp2py_export + NB_STATIC NB_DOMAIN onnx STABLE_ABI FREE_THREADED + "${ONNX_ROOT}/onnx/cpp2py_export.cc") +target_link_libraries(onnx_cpp2py_export PRIVATE +onnx +) + + target_link_options(onnx_cpp2py_export PRIVATE + "-Wl,-bkeepfile:$" # Keeps all objects inside libonnx.a alive + "-Wl,-bexpall" +) +else() + # Configure nanobind: https://nanobind.readthedocs.io/en/latest/api_cmake.html nanobind_add_module( onnx_cpp2py_export NB_STATIC NB_DOMAIN onnx STABLE_ABI FREE_THREADED LTO @@ -568,8 +583,8 @@ if(ONNX_BUILD_PYTHON) # Force-load the whole (static) archive so the operator schemas' static # initializers are not dropped as apparently-unused. $ # is the portable --whole-archive / -force_load / /WHOLEARCHIVE spelling. - target_link_libraries(onnx_cpp2py_export PRIVATE - $) + target_link_libraries(onnx_cpp2py_export PRIVATE $) +endif() endif() add_onnx_compile_options(onnx_proto) diff --git a/cmake/external/nanobind_aix.patch b/cmake/external/nanobind_aix.patch new file mode 100644 index 000000000..d78030ace --- /dev/null +++ b/cmake/external/nanobind_aix.patch @@ -0,0 +1,28 @@ +diff --git a/cmake/nanobind-config.cmake b/cmake/nanobind-config.cmake +index 7684035..469a7e9 100644 +--- a/cmake/nanobind-config.cmake ++++ b/cmake/nanobind-config.cmake +@@ -219,7 +219,7 @@ function (nanobind_build_library TARGET_NAME) + nanobind_lto(${TARGET_NAME}) + + nanobind_strip(${TARGET_NAME}) +- elseif(NOT WIN32 AND NOT APPLE) ++ elseif(NOT WIN32 AND NOT APPLE AND NOT AIX) + target_compile_options(${TARGET_NAME} PUBLIC $<${NB_OPT_SIZE}:-ffunction-sections -fdata-sections>) + target_link_options(${TARGET_NAME} PUBLIC $<${NB_OPT_SIZE}:-Wl,--gc-sections>) + endif() +diff --git a/src/nb_internals.h b/src/nb_internals.h +index cb15de8..c2f50db 100644 +--- a/src/nb_internals.h ++++ b/src/nb_internals.h +@@ -31,6 +31,10 @@ + # define NB_THREAD_LOCAL __thread + #endif + ++#if defined(_AIX) && defined(func_data) ++#undef func_data ++#endif ++ + #if PY_VERSION_HEX >= 0x030A0000 + # define NB_TPFLAGS_IMMUTABLETYPE Py_TPFLAGS_IMMUTABLETYPE + #else diff --git a/CMakeLists.txt b/CMakeLists.txt index bd992469c..6a6ad8b97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -517,7 +517,11 @@ add_dependencies(onnx_proto onnx_proto_gen) add_library(onnx $) add_subdirectory(onnx) add_dependencies(onnx onnx_proto) +if (CMAKE_SYSTEM_NAME MATCHES "AIX") +set_target_properties(onnx PROPERTIES CXX_VISIBILITY_PRESET default) +else() set_target_properties(onnx PROPERTIES CXX_VISIBILITY_PRESET hidden) +endif() add_onnx_global_defines(onnx) if(ONNX_BUILD_PYTHON) diff --git a/cmake/unittest.cmake b/cmake/unittest.cmake index f13e5e16..b72c2544 100644 --- a/cmake/unittest.cmake +++ b/cmake/unittest.cmake @@ -23,6 +23,15 @@ set(test_src add_executable(${UT_NAME} ${test_src}) find_package(Threads REQUIRED) target_link_libraries(${UT_NAME} PRIVATE onnx Threads::Threads) + +if(CMAKE_SYSTEM_NAME STREQUAL "AIX") +target_link_options(onnx_gtests PRIVATE + "-Wl,-bkeepfile:CMakeFiles/onnx_gtests.dir/onnx/test/cpp/checker_test.cc.o" + "-Wl,-bkeepfile:CMakeFiles/onnx_gtests.dir/onnx/test/cpp/shape_inference_test.cc.o" + "-Wl,-bkeepfile:CMakeFiles/onnx_gtests.dir/onnx/test/cpp/utf8_conversion_test.cc.o" +) +endif() + if(TARGET GTest::gtest) target_link_libraries(${UT_NAME} PRIVATE GTest::gtest) else()