Skip to content

Commit 0b0cef4

Browse files
committed
Prepare for PyPI
1 parent 22c4953 commit 0b0cef4

8 files changed

Lines changed: 37 additions & 15 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ sftp-config.json
2020
# Clangd cache
2121
*.cache/
2222
.lint-logs/
23+
# Python wheels
24+
*.whl

libCacheSim-python/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
cmake_minimum_required(VERSION 3.15...3.27)
22

33
# Include exported variables from cache
4-
set(PARENT_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../build")
4+
if(DEFINED LIBCB_BUILD_DIR)
5+
set(PARENT_BUILD_DIR "${LIBCB_BUILD_DIR}")
6+
message(STATUS "Using provided LIBCB_BUILD_DIR: ${LIBCB_BUILD_DIR}")
7+
else()
8+
set(PARENT_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../build")
9+
endif()
510
set(EXPORT_FILE "${PARENT_BUILD_DIR}/export_vars.cmake")
611

712
if(EXISTS "${EXPORT_FILE}")
@@ -48,10 +53,10 @@ include_directories(${GLib_CONFIG_INCLUDE_DIR})
4853
include_directories(${XGBOOST_INCLUDE_DIR})
4954
include_directories(${LIGHTGBM_PATH})
5055
include_directories(${ZSTD_INCLUDE_DIR})
51-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/bin)
56+
include_directories(${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin)
5257

5358
# Find the main libCacheSim library
54-
set(MAIN_PROJECT_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../build")
59+
set(MAIN_PROJECT_BUILD_DIR "${PARENT_BUILD_DIR}")
5560
set(MAIN_PROJECT_LIB_PATH "${MAIN_PROJECT_BUILD_DIR}/liblibCacheSim.a")
5661

5762
if(EXISTS "${MAIN_PROJECT_LIB_PATH}")
@@ -61,7 +66,7 @@ if(EXISTS "${MAIN_PROJECT_LIB_PATH}")
6166
add_library(libCacheSim_main STATIC IMPORTED)
6267
set_target_properties(libCacheSim_main PROPERTIES
6368
IMPORTED_LOCATION "${MAIN_PROJECT_LIB_PATH}"
64-
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/include;${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/utils/include;${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim"
69+
INTERFACE_INCLUDE_DIRECTORIES "${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/include;${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/utils/include;${MAIN_PROJECT_SOURCE_DIR}/libCacheSim"
6570
)
6671

6772
# Link dependencies that the main library needs
@@ -74,7 +79,7 @@ endif()
7479

7580
python_add_library(_libcachesim MODULE
7681
src/pylibcachesim.cpp
77-
${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/bin/cli_reader_utils.c
82+
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/cli_reader_utils.c
7883
WITH_SOABI
7984
)
8085

libCacheSim-python/MAINFEST.in

Whitespace-only changes.

libCacheSim-python/export/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
set(EXPORT_FILE "${CMAKE_BINARY_DIR}/export_vars.cmake")
44
file(WRITE "${EXPORT_FILE}" "")
55

6+
get_filename_component(MAIN_PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR} ABSOLUTE)
7+
file(WRITE ${CMAKE_BINARY_DIR}/export_vars.cmake "set(MAIN_PROJECT_SOURCE_DIR \"${MAIN_PROJECT_SOURCE_DIR}\")\n")
8+
file(APPEND ${CMAKE_BINARY_DIR}/export_vars.cmake "set(dependency_libs \"${dependency_libs}\")\n")
9+
file(APPEND ${CMAKE_BINARY_DIR}/export_vars.cmake "set(LIBCACHESIM_VERSION \"${LIBCACHESIM_VERSION}\")\n")
10+
611
# ==============================================================================
712
# Export project metadata
813
# ==============================================================================

libCacheSim-python/pyproject.toml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ test = ["pytest"]
1616

1717
[tool.scikit-build]
1818
wheel.expand-macos-universal-tags = true
19-
minimum-version = "build-system.requires"
20-
cmake.args = ["-G", "Ninja"]
2119

2220
[tool.pytest.ini_options]
2321
minversion = "8.0"
@@ -32,12 +30,23 @@ testpaths = ["tests"]
3230

3331

3432
[tool.cibuildwheel]
35-
build-frontend = "build[uv]"
36-
test-command = "pytest {project}/tests"
37-
test-extras = ["test"]
33+
build-frontend = "build"
34+
manylinux-x86_64-image = "quay.io/pypa/manylinux_2_34_x86_64"
35+
# Only build for x86_64 architectures
36+
build = "*-manylinux_x86_64"
37+
# Install build dependencies using dnf. This runs once per container.
38+
before-all = "dnf install -y ninja-build cmake libzstd-devel glib2-devel"
39+
# We add 'rm -rf build' to ensure a clean build inside the container.
40+
# The C++ core is built first, then the wheel build will use it.
41+
# Use absolute paths to avoid issues with the working directory.
42+
before-build = "rm -rf /project/build && cmake -S /project -B /project/build -G Ninja && cmake --build /project/build"
43+
# Set the environment variable for the wheel build step.
44+
environment = { LCS_BUILD_DIR = "/project/build" }
45+
# test-requires = "pytest"
46+
# test-command = "pytest {project}/tests"
3847

39-
[tool.cibuildwheel.pyodide]
40-
build-frontend = {name = "build", args = ["--exports", "whole_archive"]}
48+
# [tool.cibuildwheel.pyodide]
49+
# build-frontend = {name = "build", args = ["--exports", "whole_archive"]}
4150

4251
[tool.ruff.lint]
4352
extend-select = [
@@ -70,4 +79,4 @@ ignore = [
7079
isort.required-imports = ["from __future__ import annotations"]
7180

7281
[tool.ruff.lint.per-file-ignores]
73-
"tests/**" = ["T20"]
82+
"tests/**" = ["T20"]

libCacheSim/dataStructure/minimalIncrementCBF.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int minimalIncrementCBF_init(struct minimalIncrementCBF *CBF, int entries,
5353
CBF->counter_num = CBF->hashes * 2;
5454
}
5555

56-
CBF->bf = (unsigned int *)calloc(sizeof(unsigned int), CBF->counter_num);
56+
CBF->bf = (unsigned int *)calloc(CBF->counter_num, sizeof(unsigned int));
5757
// TODO: check whether unsigned int is enough for the size of each counter
5858

5959
if (CBF->bf == NULL) {

libCacheSim/include/libCacheSim/mem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#elif HEAP_ALLOCATOR == HEAP_ALLOCATOR_MALLOC
2323
#include <stdlib.h>
2424
#define my_malloc(type) (type *)malloc(sizeof(type))
25-
#define my_malloc_n(type, n) (type *)calloc(sizeof(type), n)
25+
#define my_malloc_n(type, n) (type *)calloc(n, sizeof(type))
2626
#define my_free(size, addr) free(addr)
2727

2828
#elif HEAP_ALLOCATOR == HEAP_ALLOCATOR_ALIGNED_MALLOC

scripts/build_pypi.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python3 -m cibuildwheel --platform linux libCacheSim-python

0 commit comments

Comments
 (0)