Skip to content

Commit

Permalink
update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
dwpeng committed Dec 26, 2024
1 parent 53bc54c commit e39a2ea
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 52 deletions.
32 changes: 10 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,26 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]
triplet: [x64-windows-release]
os: [windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set zlib by vcpkg
uses: johnwason/vcpkg-action@v6
with:
pkgs: zlib
triplet: ${{ matrix.triplet }}
github-binarycache: true

- name: dir list
run: dir C:\vcpkg\installed\x64-window-release

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
if: matrix.os == 'windows-latest'
run: |
python -m pip install --upgrade pip
pip install build twine flake8 setuptools wheel
- name: Install cibuildwheel
run: python -m pip install cibuildwheel -U
Invoke-Expression (Invoke-Webrequest 'https://xmake.io/psget.text' -UseBasicParsing).Content
- name: Install xmake
if: matrix.os == 'macos-latest'
run: |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install xmake
- name: Build wheels
if: matrix.os == 'macos-latest'
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: cp310-* cp311-* cp312-* cp313-* cp313t-*
CIBW_FREE_THREADED_SUPPORT: 1
run: |
pip wheel . -w wheelhouse
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ test-cigar
/build
*.egg-info
*.pyc
.xmake
2 changes: 1 addition & 1 deletion python/src/fastseqio/fastseqio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _fastseqio import (
from ._fastseqio import (
seqioFile as _seqioFile,
seqOpenMode as _seqOpenMode,
seqioRecord as _seqioRecord,
Expand Down
71 changes: 42 additions & 29 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
import setuptools
import platform

is_windows = platform.system() == "Windows"


def find_zlib_path_on_windows() -> str:
import os
zlib_path = os.path.join("vcpkg", "installed", "x64-windows-release", "lib")
return os.path.join("C:", zlib_path)


libraries = []
library_dirs = []
if is_windows:
library_dirs.append(find_zlib_path_on_windows())
libraries.append("zlib")
else:
libraries.append("z")


extensions = [
setuptools.Extension(
name="_fastseqio",
sources=["./python/fastseqio.cc", "seqio.c"],
include_dirs=[".", "python/pybind11/include"],
extra_compile_args=[],
libraries=libraries,
library_dirs=library_dirs,
import re
import subprocess
import shutil

def get_shared_lib_path():
shutil.rmtree("build", ignore_errors=True)
p = subprocess.run(["xmake", "clean"], check=True)
p = subprocess.Popen(
["xmake build -v"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
]
out, err = p.communicate()
if p.returncode != 0:
raise RuntimeError("Failed to build the shared library")
out = out.decode("utf-8") + err.decode("utf-8")
shared_lib_path = re.findall(r"-o ([\w\/\.]+[\.a-z]+)", out)
return shared_lib_path[-1]

# Copy the shared library to the package directory
if platform.system() == "Darwin" or platform.system() == "Windows":
extension = []
shared_lib_path = get_shared_lib_path()
if platform.system() == "Darwin":
subprocess.run(
["cp", shared_lib_path, "./python/src/fastseqio/_fastseqio.dylib"], check=True
)
elif platform.system() == "Windows":
subprocess.run(
["copy", shared_lib_path, "./python/src/fastseqio/_fastseqio.pyd"],
check=True,
)
package_data = ({"fastseqio": ["*.so", "*.pyd", "*.dylib"]},)
elif platform.system() == "Linux":
extension = [
setuptools.Extension(
"_fastseqio",
sources=["./seqio.c", "./python/fastseqio.cc"],
include_dirs=[".", "python/pybind11/include"],
extra_compile_args=["-lz"],
)
]
package_data = {}

setuptools.setup(
name="fastseqio",
Expand All @@ -40,5 +52,6 @@ def find_zlib_path_on_windows() -> str:
description="A package for reading and writing fasta/fastq files",
packages=setuptools.find_namespace_packages(where="./python/src"),
package_dir={"": "./python/src"},
ext_modules=extensions,
ext_modules=extension,
package_data=package_data, # type: ignore
)
13 changes: 13 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_rules("mode.debug", "mode.release")

add_requires("zlib")
add_requires("python 3.x")

target("_fastseqio")
add_rules("python.library")
add_files("seqio.c")
add_files("python/fastseqio.cc", {moduletype = "python"})
add_includedirs(".", "python/pybind11/include")
add_includedirs(".")
add_packages("zlib")
add_packages("python")

0 comments on commit e39a2ea

Please sign in to comment.