Skip to content

Commit ce43e5a

Browse files
authored
Merge pull request #1 from Blosc/ci-wheels-simple
Streamlining cmake
2 parents 252ddc0 + a9b2bd1 commit ce43e5a

11 files changed

Lines changed: 286 additions & 144 deletions

File tree

.github/workflows/cibuildwheels.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ jobs:
3434
- name: Build wheels
3535
uses: pypa/cibuildwheel@v2.22.0
3636
env:
37-
CIBW_BEFORE_BUILD: python3 -m pip install --upgrade pip && python3 -m pip install blosc2
38-
CIBW_ENVIRONMENT: CMAKE_ARGS="-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
37+
CIBW_BEFORE_BUILD: python3 -m pip install --upgrade pip && python3 -m pip install -r requirements-build.txt
3938
CIBW_BUILD: 'cp313-*'
4039
CIBW_BEFORE_TEST: python3 -m pip install --upgrade pip && python3 -m pip install -r requirements-test.txt
4140
CIBW_TEST_COMMAND: /bin/sh -c "cd /tmp && BLOSC_TRACE=1 python3 -m pytest {project}/tests"
@@ -74,7 +73,6 @@ jobs:
7473
- name: Install test deps
7574
run: |
7675
python -m pip install --upgrade pip
77-
python -m pip install blosc2
7876
python -m pip install -r requirements-test.txt
7977
8078
- name: Install wheel
@@ -104,8 +102,8 @@ jobs:
104102
- name: Build wheels
105103
uses: pypa/cibuildwheel@v2.22.0
106104
env:
107-
CIBW_BEFORE_BUILD: python3 -m pip install --upgrade pip && python3 -m pip install blosc2
108-
CIBW_ENVIRONMENT: CMAKE_ARGS="-DCMAKE_POLICY_VERSION_MINIMUM=3.5" DONT_BUILD_EXAMPLES=1
105+
CIBW_BEFORE_BUILD: python3 -m pip install --upgrade pip && python3 -m pip install -r requirements-build.txt
106+
CIBW_ENVIRONMENT: DONT_BUILD_EXAMPLES=1
109107
CIBW_BUILD: 'cp313-*'
110108
CIBW_BEFORE_TEST: python3 -m pip install --upgrade pip && python3 -m pip install -r requirements-test.txt
111109
CIBW_TEST_COMMAND: /bin/sh -c "cd /tmp && BLOSC_TRACE=1 python3 -m pytest {project}/tests"
@@ -137,8 +135,8 @@ jobs:
137135
- name: Build wheels
138136
uses: pypa/cibuildwheel@v2.22.0
139137
env:
140-
CIBW_BEFORE_BUILD: python3 -m pip install --upgrade pip && python3 -m pip install blosc2
141-
CIBW_ENVIRONMENT: CMAKE_OSX_ARCHITECTURES=arm64 CMAKE_ARGS="-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
138+
CIBW_BEFORE_BUILD: python3 -m pip install --upgrade pip && python3 -m pip install -r requirements-build.txt
139+
CIBW_ENVIRONMENT: CMAKE_OSX_ARCHITECTURES=arm64
142140
CIBW_BUILD: 'cp313-*'
143141
CIBW_BEFORE_TEST: python3 -m pip install --upgrade pip && python3 -m pip install -r requirements-test.txt
144142
CIBW_TEST_COMMAND: /bin/sh -c "cd /tmp && BLOSC_TRACE=1 python3 -m pytest {project}/tests"
@@ -175,11 +173,17 @@ jobs:
175173
- name: Build wheels
176174
uses: pypa/cibuildwheel@v2.22.0
177175
env:
178-
CIBW_BEFORE_ALL: python -m pip install cibuildwheel -U
179-
CIBW_ENVIRONMENT: CMAKE_ARGS="-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
176+
CIBW_BEFORE_ALL: python -m pip install -r requirements-build.txt
180177
CIBW_BUILD: 'cp312-win_amd64'
178+
# OpenZL doesn't like MSVC
179+
CIBW_ENVIRONMENT_WINDOWS: >-
180+
CMAKE_GENERATOR=Ninja
181+
CC=clang-cl
182+
CXX=clang-cl
183+
# Windows tests are currently disabled (wheel is built but not tested).
184+
# Uncomment the lines below to re-enable Windows tests.
181185
CIBW_BEFORE_TEST: python -m pip install --upgrade pip && python -m pip install -r requirements-test.txt
182-
CIBW_TEST_COMMAND: cmd /V /C "set BLOSC_TRACE=1 && set BLOSC2_GROK_DEBUG_DLL=1 && cd /D %TEMP% && python -m pytest {project}/tests"
186+
CIBW_TEST_COMMAND: cmd /V /C "set BLOSC_TRACE=1 && cd /D %TEMP% && python -m pytest {project}/tests"
183187

184188
- name: Upload wheels
185189
uses: actions/upload-artifact@v4

CMakeLists.txt

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,82 @@
1+
##############################################################################
2+
# blosc2-openzl: OpenZL plugin for Blosc2
3+
#
4+
# Copyright (c) 2026 The Blosc Development Team <blosc@blosc.org>
5+
# https://blosc.org
6+
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
7+
##############################################################################
8+
19
cmake_minimum_required(VERSION 3.20)
2-
project(blosc2_openzl LANGUAGES C)
10+
project(blosc2_openzl LANGUAGES C CXX) # enable CXX just to get openzl to compile
11+
12+
# Build statically
13+
set(BUILD_SHARED_LIBS OFF)
14+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
15+
set(CMAKE_FIND_FRAMEWORK NEVER)
316

417
include(GNUInstallDirs)
518
include(FetchContent)
619

20+
message("Building Blosc2 plugin...")
21+
22+
# Necessary when calling via cmake (to know which python to call)
23+
find_package(Python REQUIRED COMPONENTS Interpreter)
24+
25+
# Propagate CMAKE_OSX_ARCHITECTURES env variable into CMAKE_SYSTEM_PROCESSOR
26+
if(DEFINED ENV{CMAKE_OSX_ARCHITECTURES})
27+
if("$ENV{CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
28+
set(CMAKE_SYSTEM_PROCESSOR arm64)
29+
endif()
30+
endif()
31+
732
# ============================================================
833
# Step 1: Find C-Blosc2
934
# ============================================================
10-
# Find blosc2.h
11-
find_package(Python COMPONENTS Interpreter NumPy Development.Module REQUIRED)
12-
if (UNIX)
13-
cmake_path(SET Python_ROOT NORMALIZE "${Python_NumPy_INCLUDE_DIRS}/../../..")
14-
else()
15-
cmake_path(SET Python_ROOT NORMALIZE "${Python_NumPy_INCLUDE_DIRS}/../../..")
16-
endif()
17-
cmake_path(SET Python_INCLUDE NORMALIZE "${Python_ROOT}/include")
18-
message(STATUS "Found Python include: ${Python_ROOT}")
19-
cmake_path(SET Python_LIB NORMALIZE "${Python_ROOT}/lib")
20-
cmake_path(SET Python_LIB64 NORMALIZE "${Python_ROOT}/lib64")
21-
cmake_path(SET Python_Blosc2_INCLUDE NORMALIZE "${Python_ROOT}/include/blosc2.h")
22-
cmake_path(HAS_FILENAME Python_Blosc2_INCLUDE HAS_BLOSC2)
23-
if(HAS_BLOSC2)
24-
set(BLOSC2_INCLUDE_DIR ${Python_INCLUDE})
25-
message(STATUS "Found Blosc2 include: ${Python_Blosc2_INCLUDE}")
35+
# Find blosc2 package location using Python
36+
execute_process(
37+
COMMAND "${Python_EXECUTABLE}" -c "import blosc2, pathlib; print(pathlib.Path(blosc2.__file__).parent)"
38+
OUTPUT_VARIABLE BLOSC2_PACKAGE_DIR
39+
OUTPUT_STRIP_TRAILING_WHITESPACE
40+
RESULT_VARIABLE BLOSC2_IMPORT_RESULT
41+
)
42+
43+
# To compile blosc2_openzl, we only need the include files (although in the future may need to link with libblosc2)
44+
if(BLOSC2_IMPORT_RESULT EQUAL 0 AND EXISTS "${BLOSC2_PACKAGE_DIR}")
45+
message(STATUS "Found blosc2 package at: ${BLOSC2_PACKAGE_DIR}")
46+
47+
# Try only PEP 427 compliant structure (blosc2/include/)
48+
set(BLOSC2_INCLUDE_DIR "${BLOSC2_PACKAGE_DIR}/include")
49+
if(NOT EXISTS "${BLOSC2_INCLUDE_DIR}/blosc2.h")
50+
message(FATAL_ERROR "blosc2 package found but blosc2.h not found. Tried:\n ${BLOSC2_PACKAGE_DIR}/include")
51+
else()
52+
message(STATUS "Found Blosc2 include: ${BLOSC2_INCLUDE_DIR}/blosc2.h")
53+
endif()
2654
else()
27-
message(FATAL_ERROR "No Blosc2 includes found. Aborting.")
55+
message(FATAL_ERROR "Could not import blosc2 package. Please install it first: pip install blosc2")
2856
endif()
2957

30-
include_directories("${BLOSC2_INCLUDE_DIR}")
31-
link_directories(${Python_LIB})
32-
if (UNIX AND NOT APPLE)
33-
link_directories(${Python_LIB64})
34-
endif (UNIX AND NOT APPLE)
35-
36-
# ============================================================
37-
# Step 2: Fetch OpenZL (C-only)
38-
# ============================================================
39-
# Disable everything non-C
40-
set(OPENZL_BUILD_PYTHON_EXT OFF CACHE BOOL "" FORCE)
41-
set(OPENZL_BUILD_TESTS OFF CACHE BOOL "" FORCE)
42-
set(OPENZL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
43-
set(OPENZL_INSTALL OFF CACHE BOOL "" FORCE)
44-
set(OPENZL_BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
58+
# For the test_openzl executable, we also need the actual blosc2 lib
59+
# Try only PEP 427 compliant structure (blosc2/lib/)
60+
set(BLOSC2_LIB_DIR "${BLOSC2_PACKAGE_DIR}/lib")
61+
if(NOT EXISTS "${BLOSC2_LIB_DIR}")
62+
message(FATAL_ERROR "blosc2 lib dir not found. Tried:\n ${BLOSC2_PACKAGE_DIR}/lib")
63+
endif()
4564

46-
FetchContent_Declare(
47-
openzl
48-
GIT_REPOSITORY https://github.com/facebook/openzl.git
49-
GIT_TAG 4010c5f047441756092b039dcc8cfe7565a91d85 # pin exact version
65+
find_library(BLOSC2_LIBRARY
66+
NAMES blosc2 libblosc2
67+
PATHS "${BLOSC2_LIB_DIR}"
68+
NO_DEFAULT_PATH
5069
)
51-
FetchContent_MakeAvailable(openzl)
5270

53-
# OpenZL target resolution
54-
if(TARGET OpenZL::openzl)
55-
set(OPENZL_TARGET OpenZL::openzl)
56-
elseif(TARGET openzl)
57-
set(OPENZL_TARGET openzl)
71+
if(BLOSC2_LIBRARY)
72+
message(STATUS "Found Blosc2 library: ${BLOSC2_LIBRARY}")
73+
set(BLOSC2_LIBRARIES "${BLOSC2_LIBRARY}")
74+
get_filename_component(BLOSC2_LIBRARY_DIR_RESOLVED "${BLOSC2_LIBRARY}" DIRECTORY)
5875
else()
59-
message(FATAL_ERROR "OpenZL target not found")
76+
message(FATAL_ERROR "Blosc2 library not found in ${BLOSC2_LIB_DIR}. Please install the blosc2 Python package with bundled libraries.")
6077
endif()
6178

6279
# ============================================================
63-
# Step 3: blosc2_openzl plugin
80+
# blosc2_openzl plugin source files
6481
# ============================================================
65-
6682
add_subdirectory(src)

blosc2_openzl/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ class OpenZLProfile(Enum):
4343

4444
def get_libpath():
4545
system = platform.system()
46-
if system in ["Linux", "Darwin"]:
46+
if system in "Linux":
4747
libname = "libblosc2_openzl.so"
48+
elif system == "Darwin":
49+
# in future, on macOS may compile to .os (e.g. if blosc2 funcs added to blosc2_openzl.c)
50+
libname = "libblosc2_openzl.dylib"
4851
elif system == "Windows":
4952
libname = "blosc2_openzl.dll"
5053
else:
5154
raise RuntimeError("Unsupported system: ", system)
52-
return os.path.abspath("/home/lshaw/miniconda3/envs/blosc2env/lib/python3.13/site-packages/blosc2_openzl/libblosc2_openzl.so")
55+
return os.path.abspath(Path(__file__).parent / libname)
5356

5457

5558
libpath = get_libpath()

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
##############################################################################
2-
# blosc2_openzl: OpenZL plugin for Blosc2
2+
# blosc2-openzl: OpenZL plugin for Blosc2
33
#
44
# Copyright (c) 2026 The Blosc Development Team <blosc@blosc.org>
55
# https://blosc.org
66
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
77
##############################################################################
88

99
[build-system]
10-
requires = ["scikit-build-core", "blosc2"]
10+
requires = ["scikit-build-core", "blosc2>=4.0.0.b1"]
1111
build-backend = "scikit_build_core.build"
1212

1313
[project]

requirements-build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
scikit-build-core
2-
blosc2
2+
blosc2>=4.0.0b1
33
cibuildwheel

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest
2+
blosc2>=4.0.0b1

0 commit comments

Comments
 (0)