From ae331befa5bef341c5be533a4f7b54d17458086f Mon Sep 17 00:00:00 2001 From: dance858 Date: Sat, 5 Sep 2026 08:45:58 -0700 Subject: [PATCH] Compile the extension with the engine's explicit Release flags The _sparsediffengine target was only optimized because CMake's default CMAKE_C_FLAGS_RELEASE happens to be -O3 -DNDEBUG. Pin cmake.build-type to Release in pyproject.toml and give the extension the same per-config target_compile_options block the engine applies to dnlp_diff, so the optimization level no longer depends on toolchain defaults. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01CUDtSX6BT4SiDzfPKVZF9C --- CMakeLists.txt | 18 ++++++++++++++++++ pyproject.toml | 1 + 2 files changed, 19 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3525ba..6e10a72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,24 @@ python3_add_library(_sparsediffengine MODULE sparsediffpy/_bindings/bindings.c ) +# Match the engine's per-config optimization flags so the extension doesn't rely on +# the toolchain's default CMAKE_C_FLAGS_RELEASE. +if(MSVC) + target_compile_options(_sparsediffengine PRIVATE + $<$:/Od /Zi> + $<$:/O2 /DNDEBUG> + $<$:/O2 /Zi /DNDEBUG> + $<$:/Os /DNDEBUG> + ) +else() + target_compile_options(_sparsediffengine PRIVATE + $<$:-g -O0> + $<$:-O3 -DNDEBUG> + $<$:-O2 -g -DNDEBUG> + $<$:-Os -DNDEBUG> + ) +endif() + target_include_directories(_sparsediffengine PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/SparseDiffEngine/include ${CMAKE_CURRENT_SOURCE_DIR}/SparseDiffEngine/include/atoms diff --git a/pyproject.toml b/pyproject.toml index 02ae584..677defb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ content-type = "text/markdown" [tool.scikit-build] cmake.version = ">=3.15" +cmake.build-type = "Release" wheel.packages = ["sparsediffpy"] # Persistent build dir: avoids scikit-build-core's TemporaryDirectory, whose cleanup # intermittently fails on Windows CI with WinError 32 (lingering mspdbsrv/AV handle).