Skip to content

Commit 8eeafe5

Browse files
committed
fix the build
1 parent 4521bff commit 8eeafe5

7 files changed

Lines changed: 349 additions & 1041 deletions

File tree

.github/workflows/publish.yml

Lines changed: 191 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,205 @@ on:
55
types: [published]
66
workflow_dispatch:
77

8+
permissions:
9+
contents: write
10+
id-token: write
11+
812
jobs:
13+
build-wheels:
14+
name: Build wheels on ${{ matrix.os }} for Python ${{ matrix.python-version }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
19+
include:
20+
# Linux x86_64 - all Python versions
21+
- os: ubuntu-latest
22+
arch: x86_64
23+
# Linux aarch64 - all Python versions
24+
- os: ubuntu-latest
25+
arch: aarch64
26+
# macOS Intel - all Python versions
27+
- os: macos-13
28+
arch: x86_64
29+
# macOS Apple Silicon - all Python versions
30+
- os: macos-14
31+
arch: arm64
32+
# Windows - all Python versions
33+
- os: windows-latest
34+
arch: x86_64
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
39+
- name: Setup Python
40+
uses: actions/setup-python@v5
41+
with:
42+
python-version: ${{ matrix.python-version }}
43+
44+
- name: Setup Zig
45+
uses: goto-bus-stop/setup-zig@v2
46+
with:
47+
version: 0.14.0
48+
49+
- name: Setup uv
50+
uses: astral-sh/setup-uv@v3
51+
with:
52+
version: "latest"
53+
54+
- name: Setup QEMU (for ARM on Linux)
55+
if: runner.os == 'Linux' && matrix.arch == 'aarch64'
56+
uses: docker/setup-qemu-action@v3
57+
58+
- name: Build wheel
59+
run: uv build
60+
61+
- name: Upload wheel
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: dist-${{ matrix.os }}-${{ matrix.arch }}-py${{ matrix.python-version }}
65+
path: |
66+
dist/*.whl
67+
dist/*.tar.gz
68+
if-no-files-found: error
69+
970
publish:
71+
needs: build-wheels
1072
runs-on: ubuntu-latest
1173
steps:
1274
- name: Checkout
1375
uses: actions/checkout@v4
76+
77+
- name: Setup Python
78+
uses: actions/setup-python@v5
79+
with:
80+
python-version: "3.11"
81+
1482
- name: Setup uv
1583
uses: astral-sh/setup-uv@v3
1684
with:
1785
version: "latest"
18-
- name: Build package
19-
run: uv build
86+
87+
- name: Download all wheels
88+
uses: actions/download-artifact@v4
89+
with:
90+
pattern: dist-*
91+
path: dist
92+
merge-multiple: true
93+
94+
- name: Get version
95+
id: get_version
96+
run: |
97+
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
98+
echo "version=$VERSION" >> $GITHUB_OUTPUT
99+
100+
- name: Create platform download table
101+
run: |
102+
echo "## 📦 Platform Downloads" > platform_table.md
103+
echo "" >> platform_table.md
104+
echo "| Platform | Architecture | Python Version | Download |" >> platform_table.md
105+
echo "|----------|--------------|----------------|----------|" >> platform_table.md
106+
107+
for file in dist/*.whl; do
108+
if [[ $file =~ zigx-([0-9]+\.[0-9]+\.[0-9]+)-cp([0-9]+)-cp([0-9]+)-(.+)\.whl ]]; then
109+
version="${BASH_REMATCH[1]}"
110+
py_version="${BASH_REMATCH[2]}"
111+
platform="${BASH_REMATCH[4]}"
112+
113+
# Convert platform codes to readable names
114+
case $platform in
115+
"linux_x86_64") readable_platform="Linux" readable_arch="x86_64" ;;
116+
"linux_aarch64") readable_platform="Linux" readable_arch="ARM64" ;;
117+
"macosx_10_13_x86_64"|"macosx_11_0_x86_64") readable_platform="macOS" readable_arch="Intel" ;;
118+
"macosx_11_0_arm64") readable_platform="macOS" readable_arch="Apple Silicon" ;;
119+
"win_amd64") readable_platform="Windows" readable_arch="x86_64" ;;
120+
*) readable_platform="$platform" readable_arch="Unknown" ;;
121+
esac
122+
123+
# Convert Python version number to readable version
124+
case $py_version in
125+
"38") py_readable="3.8" ;;
126+
"39") py_readable="3.9" ;;
127+
"310") py_readable="3.10" ;;
128+
"311") py_readable="3.11" ;;
129+
"312") py_readable="3.12" ;;
130+
"313") py_readable="3.13" ;;
131+
"314") py_readable="3.14" ;;
132+
*) py_readable="$py_version" ;;
133+
esac
134+
135+
filename=$(basename "$file")
136+
echo "| $readable_platform | $readable_arch | $py_readable | [\`$filename\`](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/$filename) |" >> platform_table.md
137+
fi
138+
done
139+
140+
echo "" >> platform_table.md
141+
cat platform_table.md
142+
143+
- name: Upload artifacts to release
144+
if: github.event_name == 'release'
145+
uses: softprops/action-gh-release@v2
146+
with:
147+
files: dist/*
148+
body_path: platform_table.md
149+
env:
150+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
151+
20152
- name: Publish to PyPI
21-
run: uv publish --trusted-publishing=always
153+
run: uv publish
154+
155+
- name: Update release notes
156+
if: github.event_name == 'release'
157+
run: |
158+
# Create enhanced release notes
159+
cat << EOF > temp_notes.md
160+
# ZigX v${{ steps.get_version.outputs.version }} Release Notes
161+
162+
## 🚀 Release
163+
164+
Welcome to ZigX v${{ steps.get_version.outputs.version }}, a high-performance Python extension that seamlessly integrates Zig's native performance with Python's ease of use!
165+
166+
### ✨ Key Features
167+
168+
- **Direct Zig Integration**: Compile Zig code into native Python extensions without intermediate C bindings
169+
- **Automatic GIL Management**: Smart GIL release during native calls for true parallel execution
170+
- **Cross-Platform Support**: Works on Windows, macOS, and Linux
171+
- **PEP 517 Build System**: Modern Python packaging with Hatchling backend
172+
- **Type Safety**: Full mypy support with comprehensive type annotations
173+
174+
### 📦 Installation
175+
176+
\`\`\`bash
177+
pip install zigx
178+
# or
179+
uv pip install zigx
180+
\`\`\`
181+
182+
### 🔗 Links
183+
184+
- 📚 [Documentation](https://muhammad-fiaz.github.io/zigx)
185+
- 🐛 [Issues](${{ github.server_url }}/${{ github.repository }}/issues)
186+
- 💻 [Source](${{ github.server_url }}/${{ github.repository }})
187+
188+
### 📦 Platform Support
189+
190+
This release includes pre-built wheels for:
191+
- Linux (x86_64, aarch64)
192+
- macOS (x86_64 Intel, arm64 Apple Silicon)
193+
- Windows (x86_64)
194+
195+
All wheels support Python versions 3.8 through 3.14.
196+
197+
---
198+
199+
✅ **Successfully published to PyPI!**
200+
EOF
201+
ENHANCED_NOTES=$(cat temp_notes.md)
202+
rm temp_notes.md
203+
204+
# Use GitHub CLI to update release
205+
gh release edit ${{ github.event.release.tag_name }} \
206+
--notes "$ENHANCED_NOTES" \
207+
--repo ${{ github.repository }}
208+
env:
209+
GH_TOKEN: ${{ secrets.GH_TOKEN }}

README.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ ZigX makes it easy to create Python extensions using Zig, providing automatic ct
2121
## Features
2222

2323
- 🚀 **Pure Zig Implementation** - No Python build dependencies beyond standard library
24-
- 📦 **Wheel Building** - Create platform-specific wheels with proper metadata
24+
- 📦 **Bootstrapped Wheels** - Pre-compiled binaries bundled for all platforms
2525
- 🔧 **Development Mode** - Hot-reload friendly `develop` command
2626
- 📝 **Type Stubs** - Automatic `.pyi` file generation for IDE support
2727
- 🔒 **GIL-Safe** - Automatic GIL release for ctypes calls (just like maturin/pyo3)
28-
- 🌐 **Cross-Platform** - Supports Linux, Windows, and macOS
28+
- 🌐 **Cross-Platform** - Supports Linux (x86_64, aarch64), Windows (x86_64), and macOS (x86_64, arm64)
2929
- 🎯 **Automatic Export Detection** - No configuration needed, exports are detected from Zig source
30-
-**uv Integration** - Works seamlessly as a PEP 517 build backend
30+
-**uv Integration** - Works seamlessly with modern Python tooling
31+
- 💪 **No Zig Required** - Install and use without needing Zig compiler (binaries pre-built)
3132

3233
## Installation
3334

35+
### From PyPI (Recommended)
36+
3437
```bash
3538
pip install zigx
3639
```
@@ -41,7 +44,25 @@ Or with uv (recommended):
4144
uv pip install zigx
4245
```
4346

44-
## Quick Start
47+
**No Zig installation required!** ZigX wheels include pre-compiled binaries for your platform.
48+
49+
### From Source (Requires Zig 0.14.0+)
50+
51+
```bash
52+
git clone https://github.com/muhammad-fiaz/zigx.git
53+
cd zigx
54+
uv pip install -e .
55+
```
56+
57+
## Documentation
58+
59+
📚 **Full documentation is available at [muhammad-fiaz.github.io/zigx](https://muhammad-fiaz.github.io/zigx)**
60+
61+
The documentation includes:
62+
- Getting started guide
63+
- API reference
64+
- Examples and tutorials
65+
- Troubleshooting guide
4566

4667
### Create a New Project
4768

@@ -201,9 +222,30 @@ pub export fn heavy_computation(data: [*]f64, len: usize) f64 {
201222

202223
## Requirements
203224

204-
- **Zig** 0.14.0 or later (0.15.0+ recommended)
205-
- **Python** 3.8 or later
206-
- **uv** (recommended) or pip
225+
### System Requirements
226+
227+
- **Operating System**: Linux, macOS, or Windows
228+
- **Architecture**: x86_64, ARM64
229+
230+
### Software Requirements
231+
232+
- **Zig Compiler**: 0.14.0 or later (0.15.0+ recommended)
233+
- Download from: https://ziglang.org/download/
234+
- **Python**: 3.8 or later
235+
- **Build Tool**: uv (recommended) or pip or hatchling or poetry
236+
237+
### Optional Dependencies
238+
239+
For development:
240+
- pytest (testing)
241+
- ruff (linting)
242+
- mypy (type checking)
243+
- mkdocs (documentation)
244+
- hatchling (build backend)
245+
246+
For documentation building:
247+
- mkdocs-material
248+
- mkdocstrings[python]
207249

208250
## Documentation
209251

pyproject.toml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ classifiers = [
2727
"Topic :: Software Development :: Code Generators",
2828
"Typing :: Typed",
2929
]
30-
dependencies = []
30+
dependencies = [
31+
]
3132

3233
[project.optional-dependencies]
3334
dev = [
@@ -53,11 +54,17 @@ Changelog = "https://github.com/muhammad-fiaz/zigx/blob/main/CHANGELOG.md"
5354
zigx = "zigx:main"
5455

5556
[build-system]
56-
requires = ["uv_build>=0.9.13,<0.10"]
57-
build-backend = "uv_build"
57+
requires = ["hatchling"]
58+
build-backend = "hatchling.build"
59+
60+
[tool.hatch.build.hooks.custom]
61+
path = "zigx/build.py"
5862

59-
[tool.uv.build-backend]
60-
module-root = ""
63+
[tool.hatch.build.targets.wheel]
64+
packages = ["zigx"]
65+
66+
[tool.hatch.build.targets.wheel.force-include]
67+
"zigx/zig-out/bin/*" = "zigx/bin/"
6168

6269
[tool.ruff]
6370
target-version = "py38"
@@ -72,3 +79,6 @@ python_version = "3.9"
7279
warn_return_any = true
7380
warn_unused_configs = true
7481
disallow_untyped_defs = true
82+
83+
[tool.uv]
84+
trusted-publishing = "always"

zigx/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def find_zigx_binary() -> Optional[Path]:
3131
# Check if running from source
3232
pkg_dir = Path(__file__).parent
3333

34-
# Look for zig-out directory (built binary)
34+
# Look in installed bin directory (from wheel)
35+
bin_dir = pkg_dir / "bin" / get_binary_name()
36+
if bin_dir.exists():
37+
return bin_dir
38+
39+
# Look for zig-out directory (built binary, development mode)
3540
zig_out = pkg_dir / "zig-out" / "bin" / get_binary_name()
3641
if zig_out.exists():
3742
return zig_out
@@ -41,9 +46,9 @@ def find_zigx_binary() -> Optional[Path]:
4146
if parent_zig_out.exists():
4247
return parent_zig_out
4348

44-
# Look in installed location
45-
bin_dir = Path(sys.prefix) / "bin"
46-
installed = bin_dir / get_binary_name()
49+
# Look in system bin directory
50+
sys_bin_dir = Path(sys.prefix) / "bin"
51+
installed = sys_bin_dir / get_binary_name()
4752
if installed.exists():
4853
return installed
4954

zigx/__main__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Allow running zigx as: python -m zigx"""
2+
3+
import sys
4+
5+
from zigx import main
6+
7+
if __name__ == "__main__":
8+
sys.exit(main())

0 commit comments

Comments
 (0)