Skip to content

Commit

Permalink
Compiling SZ using cmake.
Browse files Browse the repository at this point in the history
  • Loading branch information
orioltinto committed Nov 3, 2022
1 parent 356e7b5 commit 3e9df6a
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__license__ = "MIT"
__date__ = "15/12/2020"


import shutil
from glob import glob
import logging
import os
Expand Down Expand Up @@ -70,6 +70,7 @@
import wheel
from wheel.bdist_wheel import get_platform


class BDistWheel(bdist_wheel):
"""Override bdist_wheel to handle as pure python package"""

Expand Down Expand Up @@ -421,6 +422,12 @@ class PluginBuildExt(build_ext):
It also handles extra compile arguments depending on the build options.
"""

def run(self):
for ext in self.extensions:
if isinstance(ext, SZ):
self.build_cmake(ext)
super().run()

def get_export_symbols(self, ext):
"""Overridden to remove PyInit_* export"""
return ext.export_symbols
Expand Down Expand Up @@ -472,6 +479,33 @@ def build_extensions(self):

build_ext.build_extensions(self)

def build_cmake(self, ext):
import pathlib
cwd = pathlib.Path().absolute()

# these dirs will be created in build_py, so if you don't have
# any python sources to bundle, the dirs will be missing
build_temp = pathlib.Path(self.build_temp)
if not build_temp.exists():
build_temp.mkdir(parents=True, exist_ok=True)

extdir = pathlib.Path(self.get_ext_fullpath(ext.name)).parent
if not extdir.exists():
extdir.mkdir(parents=True, exist_ok=True)

folder = extdir.absolute()
cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=' + folder.as_posix(),
"-DBUILD_HDF5_FILTER:BOOL=ON",
]

os.chdir(str(build_temp))

self.spawn(['cmake', str(cwd) + "/src/SZ"] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.'])
os.chdir(str(cwd))


class HDF5PluginExtension(Extension):
"""Extension adding specific things to build a HDF5 plugin"""
Expand Down Expand Up @@ -525,6 +559,12 @@ def hdf5_plugin_name(self):
return module_name[5:] # Strip libh5


class SZ(HDF5PluginExtension):
def __init__(self, sse2=None, avx2=None, cpp11=None, cpp11_required=False, **kwargs):
self.name = "hdf5plugin.plugins.libh5sz"
super().__init__(self.name, sse2=sse2, avx2=avx2, cpp11=cpp11, cpp11_required=cpp11_required, sources=[], **kwargs)


def prefix(directory, files):
"""Add a directory as prefix to a list of files.
Expand All @@ -538,7 +578,6 @@ def prefix(directory, files):
PLUGIN_LIB_DEPENDENCIES = dict()
"""Mapping plugin name to library name they depend on"""


# bitshuffle (+lz4) plugin
# Plugins from https://github.com/kiyo-masui/bitshuffle
bithsuffle_dir = 'src/bitshuffle'
Expand Down Expand Up @@ -858,7 +897,7 @@ def apply_filter_strip(libraries, extensions, dependencies):
return libraries, extensions

libraries, extensions = apply_filter_strip(
libraries=[snappy_lib, charls_lib, zfp_lib, sz_lib],
libraries=[snappy_lib, charls_lib, zfp_lib],
extensions=[
bzip2_plugin,
lz4_plugin,
Expand All @@ -867,15 +906,16 @@ def apply_filter_strip(libraries, extensions, dependencies):
fcidecomp_plugin,
h5zfp_plugin,
zstandard_plugin,
sz_plugin,
],
dependencies=PLUGIN_LIB_DEPENDENCIES,
)

# raise Exception((libraries, extensions))
# Add SZ extension.
extensions += [SZ()]

# setup


def get_version(debian=False):
"""Returns current version number from _version.py file"""
dirname = os.path.join(
Expand Down

0 comments on commit 3e9df6a

Please sign in to comment.