diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 00000000..acbd6248 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,48 @@ +name: Build + +on: [push, pull_request] + +# doing as cibuildwheel docs says leads to frankenstein arm builds on macos +# so lets be more explicit, no linux arm build as not available on github + +jobs: + build_wheels: + name: Wheel ${{ matrix.python }}-${{ matrix.buildplat[1] }} + runs-on: ${{ matrix.buildplat[0] }} + strategy: + fail-fast: false + matrix: + buildplat: + - [ubuntu-latest, manylinux_x86_64, auto] + - [macos-13, macosx_x86_64, x86_64] + - [macos-14, macosx_arm64, arm64] + python: ["cp38", "cp39", "cp310", "cp311", "cp312"] + + steps: + - uses: actions/checkout@v4 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.20.0 + env: + CIBW_ARCHS: ${{ matrix.buildplat[2] }} + CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }} + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.python }}-${{ matrix.buildplat[1] }} + path: ./wheelhouse/*.whl + + + build-sdist: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: Build sdist + run: python setup.py sdist + - uses: actions/upload-artifact@v4 + with: + name: sdist + path: dist diff --git a/MANIFEST.in b/MANIFEST.in index 3df1d198..ea2262ce 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,6 @@ include *.h +include *.c include Makefile -include ksw2_dispatch.c -include main.c include README.md include sse2neon/emmintrin.h include python/cmappy.h diff --git a/Makefile b/Makefile index 17b13b64..939bc0b7 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,13 @@ ifneq ($(tsan),) LIBS+=-fsanitize=thread -ldl endif +ifneq ($(python),) + # this allows us to build libminimap2.a here and then link to + # it in the python extension build, rather than doing + CFLAGS+=-fPIC +endif + + .PHONY:all extra clean depend .SUFFIXES:.c .o diff --git a/setup.py b/setup.py index 775168a6..80c89543 100644 --- a/setup.py +++ b/setup.py @@ -1,26 +1,37 @@ try: from setuptools import setup, Extension + from setuptools.command.build_ext import build_ext except ImportError: from distutils.core import setup from distutils.extension import Extension + from distutils.command.build_ext import build_ext -import sys, platform +import sys, platform, subprocess -sys.path.append('python') - -extra_compile_args = ['-DHAVE_KALLOC'] -include_dirs = ["."] - -if platform.machine() in ["aarch64", "arm64"]: - include_dirs.append("sse2neon/") - extra_compile_args.extend(['-ftree-vectorize', '-DKSW_SSE2_ONLY', '-D__SSE2__']) -else: - extra_compile_args.append('-msse4.1') # WARNING: ancient x86_64 CPUs don't have SSE4 def readme(): with open('python/README.rst') as f: return f.read() + +class LibMM2Build(build_ext): + # Uses Makefile to build library, avoids duplicating logic + # determining which objects to compile but does require + # end users to have Make (since precompiled wheels are not + # distributed on PyPI). + def run(self): + def compile_libminimap2(*args, **kwargs): + cmd = ['make', 'libminimap2.a'] + list(args) + subprocess.check_call(cmd) + options = ["python=1"] + if platform.machine() in ["aarch64", "arm64"]: + options += ["arm_neon=1", "aarch64=1"] + self.execute( + compile_libminimap2, options, + f'Compiling libminimap2 using Makefile with options: {options}') + build_ext.run(self) + + setup( name = 'mappy', version = '2.28', @@ -32,16 +43,15 @@ def readme(): license = 'MIT', keywords = 'sequence-alignment', scripts = ['python/minimap2.py'], - ext_modules = [Extension('mappy', - sources = ['python/mappy.pyx', 'align.c', 'bseq.c', 'lchain.c', 'seed.c', 'format.c', 'hit.c', 'index.c', 'pe.c', 'options.c', - 'ksw2_extd2_sse.c', 'ksw2_exts2_sse.c', 'ksw2_extz2_sse.c', 'ksw2_ll_sse.c', - 'kalloc.c', 'kthread.c', 'map.c', 'misc.c', 'sdust.c', 'sketch.c', 'esterr.c', 'splitidx.c'], - depends = ['minimap.h', 'bseq.h', 'kalloc.h', 'kdq.h', 'khash.h', 'kseq.h', 'ksort.h', - 'ksw2.h', 'kthread.h', 'kvec.h', 'mmpriv.h', 'sdust.h', - 'python/cmappy.h', 'python/cmappy.pxd'], - extra_compile_args = extra_compile_args, - include_dirs = include_dirs, - libraries = ['z', 'm', 'pthread'])], + cmdclass = {'build_ext': LibMM2Build}, + ext_modules = [ + Extension( + 'mappy', + sources = ['python/mappy.pyx'], + depends = ['python/cmappy.h', 'python/cmappy.pxd'], + include_dirs = ['.'], + extra_objects = ['libminimap2.a'], + libraries = ['z', 'm', 'pthread'])], classifiers = [ 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: MIT License',