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

Pymake #1234

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Pymake #1234

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
48 changes: 48 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 31 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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',
Expand Down
Loading