Skip to content

Commit 6f80f8d

Browse files
committed
fixup! Use scikit-build-core
1 parent 4d55628 commit 6f80f8d

File tree

13 files changed

+223
-128
lines changed

13 files changed

+223
-128
lines changed

Diff for: .github/workflows/coverage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
python3.10-dbg
4949
- name: Install Python dependencies
5050
run: |
51-
python3 -m pip install --upgrade pip cython pkgconfig
51+
python3 -m pip install --upgrade pip scikit-build-core cython pkgconfig
5252
make test-install
5353
- name: Disable ptrace security restrictions
5454
run: |

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CMakeFiles
1010
CMakeScripts
1111
Testing
1212
Makefile
13+
!/Makefile
1314
cmake_install.cmake
1415
install_manifest.txt
1516
compile_commands.json

Diff for: CMakeLists.txt

+65-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.7)
1+
cmake_minimum_required(VERSION 3.24...3.26)
22
project(memray)
33

44
set(CMAKE_CXX_STANDARD 17)
@@ -21,21 +21,22 @@ if(NOT LZ4_FOUND)
2121
endif()
2222

2323
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
24-
pkg_check_modules(LIBUNWIND REQUIRED libunwind)
24+
pkg_check_modules(UNWIND REQUIRED libunwind)
25+
pkg_check_modules(DEBUGINFOD libdebuginfod)
26+
if(NOT DEBUGINFOD_LIBRARIES)
27+
set(DEBUGINFOD_LIBRARIES "debuginfod")
28+
endif()
2529
endif()
2630

2731
# Set compiler flags
28-
set(COMPILER_FLAGS "-Wall")
32+
add_compile_options(-Wall)
2933
if(NOT DEFINED ENV{NO_MEMRAY_FAST_TLS})
30-
add_definitions(-DUSE_MEMRAY_TLS_MODEL=1)
34+
add_compile_definitions(-DUSE_MEMRAY_TLS_MODEL=1)
3135
endif()
3236

33-
if(DEFINED ENV{MEMRAY_MINIMIZE_INLINING})
34-
set(COMPILER_FLAGS ${COMPILER_FLAGS} -Og)
35-
else()
36-
set(COMPILER_FLAGS ${COMPILER_FLAGS} -flto)
37-
set(LINKER_FLAGS ${LINKER_FLAGS} -flto)
38-
endif()
37+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
38+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -flto")
39+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
3940

4041
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
4142
set(BINARY_FORMAT "elf")
@@ -48,21 +49,23 @@ endif()
4849
# Set up libbacktrace
4950
set(LIBBACKTRACE_DIR ${CMAKE_SOURCE_DIR}/src/vendor/libbacktrace)
5051
set(LIBBACKTRACE_INSTALL_DIR ${LIBBACKTRACE_DIR}/install)
51-
set(LIBBACKTRACE_INCLUDE_DIR ${LIBBACKTRACE_DIR}/install/include)
52-
set(LIBBACKTRACE_LIB_DIR ${LIBBACKTRACE_DIR}/install/lib)
52+
set(LIBBACKTRACE_INCLUDE_DIR ${LIBBACKTRACE_INSTALL_DIR}/include)
53+
set(LIBBACKTRACE_LIB_DIR ${LIBBACKTRACE_INSTALL_DIR}/lib)
5354

5455
# Add custom command to build libbacktrace
5556
add_custom_command(
5657
OUTPUT ${LIBBACKTRACE_LIB_DIR}/libbacktrace.a
58+
OUTPUT ${LIBBACKTRACE_INCLUDE_DIR}/libbacktrace/backtrace.h
59+
OUTPUT ${LIBBACKTRACE_INCLUDE_DIR}/libbacktrace/internal.h
5760
COMMAND mkdir -p ${LIBBACKTRACE_INSTALL_DIR}
5861
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/libbacktrace_build
5962
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/libbacktrace_build &&
60-
${LIBBACKTRACE_DIR}/configure
61-
--with-pic
62-
--prefix=${LIBBACKTRACE_INSTALL_DIR}
63-
--includedir=${LIBBACKTRACE_INSTALL_DIR}/include/libbacktrace
64-
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/libbacktrace_build && make -j
65-
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/libbacktrace_build && make install
63+
${LIBBACKTRACE_DIR}/configure
64+
--with-pic
65+
--prefix=${LIBBACKTRACE_INSTALL_DIR}
66+
--includedir=${LIBBACKTRACE_INCLUDE_DIR}/libbacktrace
67+
COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/libbacktrace_build -j
68+
COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/libbacktrace_build install
6669
DEPENDS ${LIBBACKTRACE_DIR}/configure
6770
)
6871
add_custom_target(libbacktrace DEPENDS ${LIBBACKTRACE_LIB_DIR}/libbacktrace.a)
@@ -72,15 +75,22 @@ add_custom_target(libbacktrace DEPENDS ${LIBBACKTRACE_LIB_DIR}/libbacktrace.a)
7275
add_custom_command(
7376
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_memray.cpp
7477
COMMAND Python::Interpreter -m cython
75-
--cplus
76-
-3
78+
--cplus
79+
-3
80+
-X embedsignature=True
81+
-X boundscheck=False
82+
-X wraparound=False
83+
-X cdivision=True
84+
-X c_string_type=unicode
85+
-X c_string_encoding=utf8
7786
-I ${CMAKE_SOURCE_DIR}/src/memray/
78-
${CMAKE_SOURCE_DIR}/src/memray/_memray.pyx
87+
${CMAKE_SOURCE_DIR}/src/memray/_memray.pyx
7988
-o ${CMAKE_CURRENT_BINARY_DIR}/_memray.cpp
89+
--module-name memray._memray
8090
DEPENDS ${CMAKE_SOURCE_DIR}/src/memray/_memray.pyx
8191
VERBATIM
8292
)
83-
set(MEMRAY_SOURCES
93+
python_add_library(_memray MODULE WITH_SOABI
8494
src/memray/_memray/compat.cpp
8595
src/memray/_memray/hooks.cpp
8696
src/memray/_memray/tracking_api.cpp
@@ -95,45 +105,63 @@ set(MEMRAY_SOURCES
95105
src/memray/_memray/snapshot.cpp
96106
src/memray/_memray/socket_reader_thread.cpp
97107
src/memray/_memray/native_resolver.cpp
108+
${CMAKE_CURRENT_BINARY_DIR}/_memray.cpp
98109
)
99-
python_add_library(_memray MODULE WITH_SOABI ${MEMRAY_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/_memray.cpp)
100-
target_include_directories(_memray PRIVATE
110+
111+
target_include_directories(_memray PRIVATE
101112
${CMAKE_SOURCE_DIR}/src/memray/_memray
102-
${LIBBACKTRACE_INCLUDE_DIR}
113+
${LIBBACKTRACE_INCLUDE_DIR}
103114
${LZ4_INCLUDE_DIRS}
115+
${UNWIND_INCLUDE_DIRS}
116+
${DEBUGINFOD_INCLUDE_DIRS}
104117
)
105-
target_link_libraries(_memray PRIVATE ${LZ4_LIBRARIES} dl ${LIBUNWIND_LIBRARIES} ${LIBBACKTRACE_LIB_DIR}/libbacktrace.a)
106-
target_link_options(_memray PRIVATE ${LZ4_LDFLAGS})
107-
target_compile_options(_memray PRIVATE ${COMPILER_FLAGS})
108-
target_link_options(_memray PRIVATE ${LINKER_FLAGS})
118+
target_link_libraries(_memray PRIVATE
119+
${LIBBACKTRACE_LIB_DIR}/libbacktrace.a
120+
${LZ4_LIBRARIES}
121+
${UNWIND_LIBRARIES}
122+
${DEBUGINFOD_LIBRARIES}
123+
dl
124+
)
125+
set_target_properties(_memray PROPERTIES INSTALL_RPATH "${DEBUGINFOD_LIBRARY_DIRS}")
126+
127+
set(CMAKE_BUILD_RPATH "${LZ4_LIBRARY_DIRS}:")
128+
target_link_options(_memray PRIVATE ${LZ4_LDFLAGS} ${UNWIND_LDFLAGS} ${DEBUGINFOD_LDFLAGS})
129+
target_compile_options(_memray PRIVATE ${LZ4_CFLAGS} ${UNWIND_CFLAGS} ${DEBUGINFOD_CFLAGS})
109130
add_dependencies(_memray libbacktrace)
110131

111132
# _test_utils extension
112133

113134
add_custom_command(
114135
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_memray_test_utils.cpp
115136
COMMAND Python::Interpreter -m cython
116-
--cplus
137+
--cplus
117138
-3
139+
-X embedsignature=True
140+
-X boundscheck=False
141+
-X wraparound=False
142+
-X cdivision=True
143+
-X c_string_type=unicode
144+
-X c_string_encoding=utf8
118145
-I ${CMAKE_SOURCE_DIR}/src/memray/
119-
${CMAKE_SOURCE_DIR}/src/memray/_memray_test_utils.pyx
146+
${CMAKE_SOURCE_DIR}/src/memray/_memray_test_utils.pyx
120147
-o ${CMAKE_CURRENT_BINARY_DIR}/_memray_test_utils.cpp
121148
--module-name memray._test_utils
122149
DEPENDS ${CMAKE_SOURCE_DIR}/src/memray/_memray_test_utils.pyx
123150
VERBATIM
124151
)
125-
python_add_library(_test_utils MODULE WITH_SOABI ${CMAKE_CURRENT_BINARY_DIR}/_memray_test_utils.cpp)
126-
target_include_directories(_test_utils PRIVATE
152+
python_add_library(_test_utils MODULE WITH_SOABI
153+
${CMAKE_CURRENT_BINARY_DIR}/_memray_test_utils.cpp
154+
)
155+
target_include_directories(_test_utils PRIVATE
127156
${CMAKE_SOURCE_DIR}/src/memray/_memray
128157
)
129158

130159
# _inject extension
131160

132-
set(INJECT_SOURCES
161+
python_add_library(_inject MODULE WITH_SOABI USE_SABI 3.7
133162
src/memray/_memray/inject.cpp
134163
)
135-
python_add_library(_inject MODULE WITH_SOABI USE_SABI 3.7 ${INJECT_SOURCES})
136-
target_include_directories(_inject PRIVATE
164+
target_include_directories(_inject PRIVATE
137165
${CMAKE_SOURCE_DIR}/src/memray
138166
)
139167
target_compile_options(_test_utils PRIVATE ${COMPILER_FLAGS})
@@ -143,4 +171,4 @@ target_link_options(_inject PRIVATE ${LINKER_FLAGS})
143171

144172

145173
# Install targets
146-
install(TARGETS _memray _test_utils _inject LIBRARY DESTINATION memray)
174+
install(TARGETS _memray _test_utils _inject LIBRARY DESTINATION memray)

Diff for: MANIFEST.in

-41
This file was deleted.

Diff for: Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ build: build-js build-ext ## (default) Build package extensions and assets in-p
2525

2626
.PHONY: build-ext
2727
build-ext: ## Build package extensions in-place
28-
$(PYTHON) -m pip install --no-build-isolation --config-settings=editable.rebuild=true -Cbuild-dir=build -ve.
28+
$(PYTHON) -m pip install -ve . \
29+
--no-build-isolation \
30+
--config-settings=editable.verbose=false \
31+
--config-settings=cmake.build-type=Debug \
32+
-Cbuild-dir=build
2933

3034
$(reporters_path)/templates/assets/%.js: $(reporters_path)/assets/%.js
3135
$(NPM) install
@@ -102,7 +106,7 @@ helgrind: ## Run helgrind, with the correct configuration
102106
.PHONY: ccoverage
103107
ccoverage: ## Run the test suite, with C++ code coverage
104108
$(MAKE) clean
105-
CFLAGS="$(CFLAGS) -O0 -pg --coverage" $(MAKE) build
109+
CFLAGS="$(CFLAGS) -O0 -pg --coverage" CXXFLAGS="$(CXXFLAGS) -O0 -pg --coverage" $(MAKE) build
106110
$(MAKE) check
107111
gcov -i build/*/src/memray/_memray -i -d
108112
lcov --capture --directory . --output-file cppcoverage.lcov

Diff for: docs/examples/README.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Make sure you install the required dependencies by running
1111
directory. The examples below use the project in the ``mandelbrot`` folder, but
1212
you can use the same instructions to launch the other examples as well.
1313

14-
To track memory allocations, invoke ``memray3.9 run``:
14+
To track memory allocations, invoke ``memray run``:
1515

1616
.. code:: shell
1717
18-
memray3.9 run mandelbrot/mandelbrot.py
18+
memray run mandelbrot/mandelbrot.py
1919
2020
Memray will print a message displaying the output file it creates.
2121

@@ -28,7 +28,7 @@ graph, use the following command:
2828

2929
.. code:: shell
3030
31-
memray3.9 flamegraph mandelbrot/memray-mandelbrot.py.187967.bin
31+
memray flamegraph mandelbrot/memray-mandelbrot.py.187967.bin
3232
3333
The HTML file for the flame graph will be generated under
3434
``mandelbrot/memray-flamegraph-mandelbrot.py.187967.html``. The flame graph

Diff for: docs/getting_started.rst

+4-10
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@ You can invoke Memray the following way:
2626
2727
python3.9 -m memray
2828
29-
Or alternatively through the version-qualified ``memrayX.Y`` script:
30-
31-
.. code:: shell
32-
33-
memray3.9
34-
35-
You can also invoke Memray without version-qualifying it:
29+
Or alternatively through the ``memray`` script:
3630

3731
.. code:: shell
3832
3933
memray
4034
41-
The downside to the unqualified ``memray`` script is that it's not immediately
35+
The downside to using the ``memray`` script is that it's not immediately
4236
clear what Python interpreter will be used to execute Memray. If you're using
4337
a virtual environment that's not a problem because you know exactly what interpreter is
4438
in use, but otherwise you need to be careful to ensure that ``memray`` is
@@ -56,7 +50,7 @@ To run memray on the ``example.py`` script, use :doc:`the run subcommand <run>`.
5650

5751
.. code:: shell
5852
59-
memray3.9 run example.py
53+
memray run example.py
6054
6155
This will execute the script and track its memory allocations, displaying the name of the file where results are being recorded with a message like:
6256

@@ -72,7 +66,7 @@ the results file:
7266

7367
.. code:: shell
7468
75-
memray3.9 flamegraph memray-example.py.4131.bin
69+
memray flamegraph memray-example.py.4131.bin
7670
7771
This will generate the ``memray-flamegraph-example.py.4131.html`` file in the current directory. See the :doc:`flamegraph`
7872
documentation which explains how to interpret flame graphs.

Diff for: docs/run.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ You can run a program in live mode using ``run --live``:
140140

141141
.. code:: shell
142142
143-
memray3.9 run --live application.py
143+
memray run --live application.py
144144
145145
Immediately Memray will start your application in the background and will run a TUI in the foreground that you can use
146146
to analyze your application's memory usage. If you don't want to run your program in the background, you can instead
147147
use ``run --live-remote``:
148148

149149
.. code:: shell
150150
151-
memray3.9 run --live-remote application.py
151+
memray run --live-remote application.py
152152
153153
In this mode, Memray will choose an unused port, bind to it, and display a message saying:
154154

@@ -160,7 +160,7 @@ It will wait for you to run:
160160

161161
.. code:: shell
162162
163-
memray3.9 live <port>
163+
memray live <port>
164164
165165
in another terminal window to attach to it. Regardless of whether you choose to use one terminal or two, the resulting
166166
TUI is exactly the same. See :doc:`live` for details on how to interpret and control the TUI.

0 commit comments

Comments
 (0)