Skip to content

Commit da57e63

Browse files
committed
Sync build configuration with Memray
- Start setting `CMAKE_CXX_VISIBILITY_PRESET` to `hidden` to avoid unintentionally exposing symbols from our extension module that could potentially conflict with other modules. - Ensure that directories searched for shared libraries are added to the RPATH with `CMAKE_INSTALL_RPATH_USE_LINK_PATH`. - Ensure that the Python version we find includes a configuration for building extension modules that against the stable ABI. - Build with -Wall to enable extra warnings. - Pass `-D_FILE_OFFSET_BITS=64` to opt into 64-bit file IO APIs even on 32-bit platforms. This currently doesn't have any effect, since we only build for 64-bit platforms, but it would be needed if we ever added i686 support, and matching Memray will make maintenance cheaper. - Enable extra debugging in the C++ STL for debug builds. - Build with link time optimizations enabled for CMake release mode builds. - Optimize for debugging in CMake debug builds. - Require `scikit-build-core` 0.9 or newer. - Enable extra logging during builds. - Avoid stripping debug info from the built extension module. - Automatically build in debug mode rather than release mode when passing the `-e` / `--editable` flag to `pip install`. Signed-off-by: Matt Wozniski <godlygeek@gmail.com>
1 parent 4d4ef00 commit da57e63

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ project(pystack LANGUAGES CXX)
55
set(CMAKE_CXX_STANDARD 20)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
8+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
9+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
810

911
# Find Python
10-
find_package(Python 3.9 COMPONENTS Interpreter Development.Module REQUIRED)
12+
find_package(Python COMPONENTS Interpreter Development.Module Development.SABIModule REQUIRED)
13+
14+
# Set compiler flags
15+
add_compile_options(-Wall)
16+
add_compile_definitions(_FILE_OFFSET_BITS=64)
17+
18+
add_compile_definitions(
19+
"$<$<CONFIG:Debug>:_GLIBCXX_DEBUG>"
20+
"$<$<CONFIG:Debug>:_LIBCPP_DEBUG>"
21+
)
22+
23+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
24+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -flto")
25+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
1126

1227
# Find nanobind
1328
execute_process(

pyproject.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ Homepage = "https://github.com/bloomberg/pystack"
5858
pystack = "pystack.__main__:main"
5959

6060
[tool.scikit-build]
61+
minimum-version = "0.9"
62+
cmake.verbose = true
63+
cmake.build-type = "RelWithDebInfo"
64+
logging.level = "INFO"
65+
install.strip = false
6166
wheel.packages = ["src/pystack"]
6267
wheel.install-dir = "pystack"
6368
wheel.exclude = ["pystack/_pystack/**"]
@@ -75,8 +80,11 @@ sdist.exclude = [
7580
"uv.lock",
7681
]
7782

78-
[tool.scikit-build.cmake.define]
79-
CMAKE_BUILD_TYPE = "Release"
83+
[[tool.scikit-build.overrides]]
84+
if.state = "editable"
85+
build-dir = "build"
86+
editable.verbose = false
87+
cmake.build-type = "Debug"
8088

8189
[tool.ruff]
8290
line-length = 95

0 commit comments

Comments
 (0)