From 7e3f498b1912ea3cc2cc11f57cccd7f51bb2e23b Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Fri, 30 Jan 2026 04:17:37 +0000 Subject: [PATCH 1/2] wip --- setup.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 0911d40f..e54e5c84 100644 --- a/setup.py +++ b/setup.py @@ -21,9 +21,16 @@ 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('snap')] - other = [item for item in library_names if not item.startswith('snap')] - return current + other + #current = [item for item in library_names if item.startswith('snap')] + #other = [item for item in library_names if not item.startswith('snap')] + + # 1) non-cuda libs first (consumers) + snap_non_cuda = [l for l in library_names if l.startswith("snap") and "cuda" not in l] + # 2) cuda libs last (providers) + snap_cuda = [l for l in library_names if l.startswith("snap") and "cuda" in l] + # 3) everything else + other = [l for l in library_names if not l.startswith("snap")] + return snap_non_cuda + other + snap_cuda site_dir = sysconfig.get_paths()["purelib"] @@ -58,11 +65,13 @@ 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,-rpath,$ORIGIN/../kintera/lib", + "-Wl,--as-needed", ] ext_module = cpp_extension.CppExtension( From 954ecf527a2878d3c7db4ed12a1499d648f38a0d Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Thu, 5 Feb 2026 14:33:46 -0500 Subject: [PATCH 2/2] wip --- cmake/macros/macro_setup_cuda_test.cmake | 4 ++++ cmake/macros/macro_setup_problem.cmake | 4 ++++ cmake/macros/macro_setup_test.cmake | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/cmake/macros/macro_setup_cuda_test.cmake b/cmake/macros/macro_setup_cuda_test.cmake index 9ec67a30..fba374c6 100644 --- a/cmake/macros/macro_setup_cuda_test.cmake +++ b/cmake/macros/macro_setup_cuda_test.cmake @@ -25,5 +25,9 @@ macro(setup_cuda_test namel) target_link_libraries( ${namel}.${buildl} PRIVATE snapy::snap snapy::snap_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/cmake/macros/macro_setup_problem.cmake b/cmake/macros/macro_setup_problem.cmake index 78357607..ce741bad 100644 --- a/cmake/macros/macro_setup_problem.cmake +++ b/cmake/macros/macro_setup_problem.cmake @@ -23,4 +23,8 @@ macro(setup_problem namel) ${namel}.${buildl} PRIVATE snapy::snap $,snapy::snap_cu,>) + + if (UNIX AND NOT APPLE) + target_link_options(${namel}.${buildl} PRIVATE -Wl,--no-as-needed) + endif() endmacro() diff --git a/cmake/macros/macro_setup_test.cmake b/cmake/macros/macro_setup_test.cmake index f1428692..82d6a23c 100644 --- a/cmake/macros/macro_setup_test.cmake +++ b/cmake/macros/macro_setup_test.cmake @@ -26,5 +26,9 @@ macro(setup_test namel) $,snapy::snap_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()