Skip to content

Commit 1176fde

Browse files
committed
feat: add Windows CI workflow and update setup.py for Windows build
1 parent 204b1c4 commit 1176fde

4 files changed

Lines changed: 97 additions & 32 deletions

File tree

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,45 @@ jobs:
4848
CIBW_ARCHS: ${{ matrix.arch }}
4949
CIBW_MANYLINUX_*_IMAGE: ${{ matrix.manylinux-image }}
5050
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux-image }}
51+
52+
test-on-windows:
53+
name: Build wheels on Windows for ${{ matrix.arch }}
54+
runs-on: ${{ matrix.os }}
55+
strategy:
56+
matrix:
57+
os: [windows-latest]
58+
python-version: [38, 39, 310, 311, 312, 313]
59+
arch: [AMD64]
60+
61+
steps:
62+
- uses: actions/checkout@v3
63+
with:
64+
submodules: recursive
65+
- name: Set up Python
66+
uses: actions/setup-python@v4
67+
with:
68+
python-version: 3.11
69+
- name: Setup Zig
70+
uses: mlugg/setup-zig@v1
71+
with:
72+
version: 0.13.0
73+
- name: build static zlib for windows
74+
run: |
75+
zig build -Doptimize=ReleaseFast
76+
77+
- name: Install dependencies
78+
run: |
79+
python -m pip install --upgrade pip
80+
pip install build twine setuptools wheel
81+
82+
- name: Install cibuildwheel
83+
run: python -m pip install cibuildwheel -U
84+
85+
- name: Build wheels
86+
run: python -m cibuildwheel --output-dir wheelhouse
87+
env:
88+
CIBW_BUILD: 'cp${{ matrix.python-version }}-*'
89+
CIBW_SKIP: '*musllinux*'
90+
CIBW_ARCHS: ${{ matrix.arch }}
91+
CIBW_MANYLINUX_*_IMAGE: ${{ matrix.manylinux-image }}
92+
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux-image }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ test-cigar
1818
*.egg-info
1919
*.pyc
2020
.xmake
21+
.zig-*
22+
zig-out

build.zig

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const mode = b.standardOptimizeOption(.{});
6+
7+
const zlib = b.addStaticLibrary(.{
8+
.name = "z",
9+
.target = target,
10+
.optimize = mode,
11+
});
12+
13+
zlib.linkLibC();
14+
zlib.addIncludePath(b.path("./deps/zlib"));
15+
zlib.addCSourceFiles(.{
16+
.root = b.path("./deps/zlib"),
17+
.files = &[_][]const u8{
18+
"adler32.c",
19+
"compress.c",
20+
"crc32.c",
21+
"deflate.c",
22+
"gzclose.c",
23+
"gzlib.c",
24+
"gzread.c",
25+
"gzwrite.c",
26+
"inflate.c",
27+
"infback.c",
28+
"inftrees.c",
29+
"inffast.c",
30+
"trees.c",
31+
"uncompr.c",
32+
"zutil.c",
33+
},
34+
.flags = &[_][]const u8{
35+
"-std=c89",
36+
"-O2",
37+
},
38+
});
39+
40+
b.installArtifact(zlib);
41+
}

setup.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,8 @@
11
import setuptools
2-
import re
3-
import os
4-
import sys
5-
6-
7-
def get_shared_lib_path():
8-
for root, dirs, files in os.walk("build"):
9-
for file in files:
10-
if re.search(r"\.(pyd|so|dylib)$", file):
11-
return os.path.join(root, file)
12-
raise FileNotFoundError("Shared library not found")
13-
14-
15-
def copy_file(src, dst):
16-
with open(src, "rb") as f:
17-
with open(dst, "wb") as g:
18-
g.write(f.read())
19-
print(f"Copy {src} to {dst}")
20-
21-
22-
if sys.platform == "darwin" or sys.platform == "win32":
23-
extension = []
24-
shared_lib_path = get_shared_lib_path()
25-
print("###########################")
26-
print(shared_lib_path)
27-
print("###########################")
28-
target_path = "./python/src/fastseqio/_fastseqio"
29-
suffix = os.path.splitext(shared_lib_path)[1]
30-
target_path += suffix
31-
copy_file(shared_lib_path, target_path)
32-
package_data = {"fastseqio": ["*.so", "*.pyd", "*.dylib"]}
332

3+
import sys
344

35-
elif sys.platform == "linux":
5+
if sys.platform == "linux":
366
extension = [
377
setuptools.Extension(
388
"_fastseqio",
@@ -42,6 +12,16 @@ def copy_file(src, dst):
4212
)
4313
]
4414
package_data = {}
15+
elif sys.platform == "win32":
16+
extension = [
17+
setuptools.Extension(
18+
"_fastseqio",
19+
sources=["./seqio.c", "./python/fastseqio.cc"],
20+
include_dirs=[".", "python/pybind11/include", "./deps/zlib"],
21+
extra_objects=["./zig-out/lib/z.lib"],
22+
)
23+
]
24+
package_data = {}
4525
else:
4626
raise ValueError("")
4727

0 commit comments

Comments
 (0)