Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build for Linux AArch64 and other miscellaneous cleanups #710

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
# macos-13 is an intel runner, macos-14 is a arm64 runner
platform: [ubuntu-latest, windows-latest, macos-13, macos-14]
# macos-13 is an intel runner, macos-14 is an arm64 runner
platform: [ubuntu-latest, ubuntu-22.04-arm, windows-latest, macos-13, macos-14]

defaults:
run:
Expand All @@ -28,7 +28,7 @@ jobs:
fetch-depth: 0 # required for version resolution

- name: Set up Conda
uses: conda-incubator/[email protected].0
uses: conda-incubator/[email protected].1
with:
channels: conda-forge
miniforge-version: latest
Expand Down Expand Up @@ -56,8 +56,7 @@ jobs:
# Since zarr v3 requires numpy >= 1.25, on Python 3.11 leave it out
# so we can have some tests of our minimum version of numpy (1.24)
if: matrix.python-version != '3.11'
# TODO: remove --pre option when zarr v3 is out
run: python -m pip install --pre zarr>=3.0.0b2
run: python -m pip install zarr>=3

- name: List installed packages
run: python -m pip list
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
fail-fast: false
matrix:
# macos-13 is an intel runner, macos-14 is a arm64 runner
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
# macos-13 is an intel runner, macos-14 is an arm64 runner
os: [ubuntu-latest, ubuntu-22.04-arm, windows-latest, macos-13, macos-14]
env:
CIBW_TEST_COMMAND: python -c "import numcodecs"
CIBW_BUILD: "cp311-* cp312-* cp313-*"
Expand Down
8 changes: 7 additions & 1 deletion docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Release notes
Unreleased
----------

Enhancements
~~~~~~~~~~~~

* Add support for the Linux AArch64 architecture.
By :user:`Agriya Khetarpal <agriyakhetarpal>`, :issue:`288`.

Improvements
~~~~~~~~~~~~
* Raise a custom `UnknownCodecError` when trying to retrieve an unavailable codec.
Expand All @@ -40,7 +46,7 @@ Breaking changes

Deprecations
~~~~~~~~~~~~
The following ``blosc`` funcitons are deprecated, with no replacement.
The following ``blosc`` functions are deprecated, with no replacement.
This is because they are not intended to be public API.

- ``numcodecs.blosc.init``
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ filterwarnings = [
[tool.cibuildwheel]
environment = { DISABLE_NUMCODECS_AVX2=1 }
[tool.cibuildwheel.macos]
environment = { MACOSX_DEPLOYMENT_TARGET=10.9, DISABLE_NUMCODECS_AVX2=1, CFLAGS="$CFLAGS -Wno-implicit-function-declaration" }
# cibuildwheel uses 3.12 for the Python driver, which supports High Sierra and later
# https://github.com/pypa/cibuildwheel/blob/ee63bf16da6cddfb925f542f2c7b59ad50e93969/action.yml#L31
environment = { MACOSX_DEPLOYMENT_TARGET=10.13, DISABLE_NUMCODECS_AVX2=1, CFLAGS="$CFLAGS -Wno-implicit-function-declaration" }
[[tool.cibuildwheel.overrides]]
select = "*-macosx_arm64"
environment = { DISABLE_NUMCODECS_AVX2=1, DISABLE_NUMCODECS_SSE2=1 }
Expand Down
35 changes: 30 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
# determine CPU support for SSE2 and AVX2
cpu_info = cpuinfo.get_cpu_info()
flags = cpu_info.get('flags', [])
have_sse2 = 'sse2' in flags
have_avx2 = 'avx2' in flags
machine = cpuinfo.platform.machine()

# only check for x86 features on x86_64 arch
have_sse2 = False
have_avx2 = False
if machine == 'x86_64':
have_sse2 = 'sse2' in flags
have_avx2 = 'avx2' in flags

disable_sse2 = 'DISABLE_NUMCODECS_SSE2' in os.environ
disable_avx2 = 'DISABLE_NUMCODECS_AVX2' in os.environ

Expand All @@ -24,7 +31,7 @@
if have_cflags:
# respect compiler options set by user
pass
elif os.name == 'posix':
elif os.name == 'posix' and machine == 'x86_64':
if disable_sse2:
base_compile_args.append('-mno-sse2')
elif have_sse2:
Expand Down Expand Up @@ -53,8 +60,14 @@ def blosc_extension():
info('setting up Blosc extension')

extra_compile_args = base_compile_args.copy()
extra_link_args = []
define_macros = []

# ensure pthread is properly linked on POSIX systems
if os.name == 'posix':
extra_compile_args.append('-pthread')
extra_link_args.append('-pthread')

# setup blosc sources
blosc_sources = [f for f in glob('c-blosc/blosc/*.c') if 'avx2' not in f and 'sse2' not in f]
include_dirs = [os.path.join('c-blosc', 'blosc')]
Expand Down Expand Up @@ -118,6 +131,7 @@ def blosc_extension():
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
extra_objects=extra_objects,
),
]
Expand Down Expand Up @@ -302,13 +316,24 @@ class BuildFailed(Exception):
pass


def get_arch_specific_objects():
machine = cpuinfo.platform.machine()
if machine == 'x86_64':
return [S[:-1] + 'o' for S in glob("c-blosc/internal-complibs/zstd*/decompress/*amd64.S")]
elif machine == 'aarch64':
return [S[:-1] + 'o' for S in glob("c-blosc/internal-complibs/zstd*/decompress/*aarch64.S")]
return []


class ve_build_ext(build_ext):
# This class allows C extension building to fail.

def run(self):
try:
if cpuinfo.platform.machine() == 'x86_64':
S_files = glob('c-blosc/internal-complibs/zstd*/decompress/*amd64.S')
machine = cpuinfo.platform.machine()
if machine in ('x86_64', 'aarch64'):
pattern = '*amd64.S' if machine == 'x86_64' else '*aarch64.S'
S_files = glob(f'c-blosc/internal-complibs/zstd*/decompress/{pattern}')
compiler = ccompiler.new_compiler()
customize_compiler(compiler)
compiler.src_extensions.append('.S')
Expand Down
Loading