From a2cb4b1fa0bd0a871f07de2c8575a9a8ce1a2187 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Thu, 5 Feb 2026 15:47:44 +0000 Subject: [PATCH 1/2] wip --- cmake/macros/macro_setup_test.cmake | 6 ++++- setup.py | 40 ++++++++++++----------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/cmake/macros/macro_setup_test.cmake b/cmake/macros/macro_setup_test.cmake index 3f0faf6..e052bd9 100644 --- a/cmake/macros/macro_setup_test.cmake +++ b/cmake/macros/macro_setup_test.cmake @@ -19,9 +19,13 @@ macro(setup_test namel) target_link_libraries( ${namel}.${buildl} - PRIVATE kintera::kintera + PRIVATE kintera::kintera $,kintera::kintera_cu,> gtest_main) + if (UNIX AND NOT APPLE) + target_link_options(${namel}.${buildl} PRIVATE -Wl,--no-as-needed) + endif() + add_test(NAME ${namel}.${buildl} COMMAND ${namel}.${buildl}) endmacro() diff --git a/setup.py b/setup.py index 5a5b2f3..19ec4c1 100644 --- a/setup.py +++ b/setup.py @@ -21,9 +21,15 @@ def parse_library_names(libdir): library_names.extend(['netcdf']) # move current library name to first - current = [item for item in library_names if item.startswith('kintera')] - other = [item for item in library_names if not item.startswith('kintera')] - return current + other + #current = [item for item in library_names if item.startswith('kintera')] + #other = [item for item in library_names if not item.startswith('kintera')] + # 1) non-cuda libs first (consumers) + kintera_non_cuda = [l for l in library_names if l.startswith("kintera") and "cuda" not in l] + # 2) cuda libs last (providers) + kintera_cuda = [l for l in library_names if l.startswith("kintera") and "cuda" in l] + # 3) everything else + other = [l for l in library_names if not l.startswith("kintera")] + return kintera_non_cuda + other + kintera_cuda site_dir = sysconfig.get_paths()["purelib"] @@ -62,27 +68,15 @@ def parse_library_names(libdir): "-Wl,-rpath,$ORIGIN/../pyharp/lib", ] -if torch.cuda.is_available(): - ext_module = cpp_extension.CUDAExtension( - name='kintera.kintera', - sources=glob.glob('python/csrc/*.cpp'), - include_dirs=include_dirs, - library_dirs=lib_dirs, - libraries=libraries, - extra_compile_args={'nvcc': ['--extended-lambda'], - 'cc': ["-Wno-attributes"]}, - extra_link_args=extra_link_args, +ext_module = cpp_extension.CppExtension( + name='kintera.kintera', + sources=glob.glob('python/csrc/*.cpp'), + include_dirs=include_dirs, + library_dirs=lib_dirs, + libraries=libraries, + extra_compile_args=['-Wno-attributes'], + extra_link_args=extra_link_args, ) -else: - ext_module = cpp_extension.CppExtension( - name='kintera.kintera', - sources=glob.glob('python/csrc/*.cpp'), - include_dirs=include_dirs, - library_dirs=lib_dirs, - libraries=libraries, - extra_compile_args=['-Wno-attributes'], - extra_link_args=extra_link_args, - ) setup( package_dir={"kintera": "python"}, From a153c5ac6f9f8f53971d5fd8adb47a348b76e91d Mon Sep 17 00:00:00 2001 From: mac/cli Date: Thu, 5 Feb 2026 14:05:27 -0500 Subject: [PATCH 2/2] wip --- cmake/macros/macro_setup_problem.cmake | 4 ++++ setup.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/cmake/macros/macro_setup_problem.cmake b/cmake/macros/macro_setup_problem.cmake index c034a74..0f293df 100644 --- a/cmake/macros/macro_setup_problem.cmake +++ b/cmake/macros/macro_setup_problem.cmake @@ -22,4 +22,8 @@ macro(setup_problem namel) ${namel}.${buildl} PRIVATE kintera::kintera $,kintera::kintera_cu,>) + + if (UNIX AND NOT APPLE) + target_link_options(${namel}.${buildl} PRIVATE -Wl,--no-as-needed) + endif() endmacro() diff --git a/setup.py b/setup.py index 19ec4c1..3051035 100644 --- a/setup.py +++ b/setup.py @@ -62,10 +62,12 @@ def parse_library_names(libdir): ] else: extra_link_args = [ + "-Wl,--no-as-needed", "-Wl,-rpath,$ORIGIN/lib", "-Wl,-rpath,$ORIGIN/../torch/lib", "-Wl,-rpath,$ORIGIN/../pydisort/lib", "-Wl,-rpath,$ORIGIN/../pyharp/lib", + "-Wl,--as-needed", ] ext_module = cpp_extension.CppExtension(