From 56dd9e4dca09c68287b27eeab36672af19849143 Mon Sep 17 00:00:00 2001 From: Fabian Peddinghaus Date: Wed, 2 Sep 2026 13:25:33 +0000 Subject: [PATCH 1/2] Link libatomic where 64-bit atomics are not native, fixing the piwheels build --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93cb757..683f312 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,35 @@ nanobind_add_module( target_include_directories(_cpp PRIVATE src/cpp) target_link_libraries(_cpp PRIVATE Threads::Threads) +# 64-bit atomics compile to libatomic calls on targets without native +# double-word atomics (32-bit ARM as Raspberry Pi OS builds it, among others). +# Without the link the module still links, since extension modules leave symbols +# undefined by design, but fails to load: undefined __atomic_*_8. +include(CheckCXXSourceCompiles) +set(INT64_ATOMICS_SOURCE + " +#include +#include +int main() { + std::atomic value{0}; + std::int64_t expected = 0; + value.fetch_add(1); + value.compare_exchange_weak(expected, 2); + return static_cast(value.load()); +} +") +check_cxx_source_compiles("${INT64_ATOMICS_SOURCE}" HAVE_NATIVE_INT64_ATOMICS) +if(NOT HAVE_NATIVE_INT64_ATOMICS) + set(CMAKE_REQUIRED_LIBRARIES atomic) + check_cxx_source_compiles("${INT64_ATOMICS_SOURCE}" + HAVE_LIBATOMIC_INT64_ATOMICS) + unset(CMAKE_REQUIRED_LIBRARIES) + if(NOT HAVE_LIBATOMIC_INT64_ATOMICS) + message(FATAL_ERROR "64-bit atomics require libatomic, which was not found") + endif() + target_link_libraries(_cpp PRIVATE atomic) +endif() + option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) if(MSVC) From eb82591811df1ae11c3d293a65c4b5d59c814922 Mon Sep 17 00:00:00 2001 From: Fabian Peddinghaus Date: Thu, 3 Sep 2026 12:41:40 +0000 Subject: [PATCH 2/2] Drop the redundant libatomic probe and shrink the atomics check --- CMakeLists.txt | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 683f312..2ea81af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,32 +61,17 @@ nanobind_add_module( target_include_directories(_cpp PRIVATE src/cpp) target_link_libraries(_cpp PRIVATE Threads::Threads) -# 64-bit atomics compile to libatomic calls on targets without native -# double-word atomics (32-bit ARM as Raspberry Pi OS builds it, among others). -# Without the link the module still links, since extension modules leave symbols -# undefined by design, but fails to load: undefined __atomic_*_8. +# 64-bit atomics compile to libatomic calls where the target has no native +# double-word atomics (32-bit ARM as Raspberry Pi OS builds it); the module then +# links but fails to load with an undefined __atomic_*_8 symbol. include(CheckCXXSourceCompiles) -set(INT64_ATOMICS_SOURCE - " -#include -#include -int main() { - std::atomic value{0}; - std::int64_t expected = 0; - value.fetch_add(1); - value.compare_exchange_weak(expected, 2); - return static_cast(value.load()); -} -") -check_cxx_source_compiles("${INT64_ATOMICS_SOURCE}" HAVE_NATIVE_INT64_ATOMICS) +check_cxx_source_compiles( + "#include + #include + std::atomic value; + int main() { return static_cast(value.fetch_add(1)); }" + HAVE_NATIVE_INT64_ATOMICS) if(NOT HAVE_NATIVE_INT64_ATOMICS) - set(CMAKE_REQUIRED_LIBRARIES atomic) - check_cxx_source_compiles("${INT64_ATOMICS_SOURCE}" - HAVE_LIBATOMIC_INT64_ATOMICS) - unset(CMAKE_REQUIRED_LIBRARIES) - if(NOT HAVE_LIBATOMIC_INT64_ATOMICS) - message(FATAL_ERROR "64-bit atomics require libatomic, which was not found") - endif() target_link_libraries(_cpp PRIVATE atomic) endif()