Skip to content

Commit cb6d7c4

Browse files
authored
Merge pull request #100 from SwayamInSync/quaddtype-packaging
Packaging QuadDType
2 parents 1111a86 + b725e15 commit cb6d7c4

File tree

6 files changed

+277
-29
lines changed

6 files changed

+277
-29
lines changed

.github/workflows/build_wheels.yml

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
name: Build Wheels
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "quaddtype-v*"
9+
paths:
10+
- "quaddtype/**"
11+
pull_request:
12+
paths:
13+
- "quaddtype/**"
14+
workflow_dispatch:
15+
16+
jobs:
17+
build_wheels_linux:
18+
name: Build wheels on Linux
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ">=3.10.0"
27+
28+
- name: Install cibuildwheel
29+
run: pip install cibuildwheel==2.20.0
30+
31+
- name: Build wheels
32+
env:
33+
CIBW_BUILD: "cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64"
34+
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
35+
CIBW_BUILD_VERBOSITY: "3"
36+
CIBW_BEFORE_ALL: |
37+
git clone --branch 3.8 https://github.com/shibatch/sleef.git
38+
cd sleef
39+
cmake -S . -B build -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
40+
cmake --build build/ --clean-first -j
41+
cmake --install build --prefix /usr/local
42+
CIBW_ENVIRONMENT: >
43+
CFLAGS="-I/usr/local/include $CFLAGS"
44+
CXXFLAGS="-I/usr/local/include $CXXFLAGS"
45+
LDFLAGS="-L/usr/local/lib64 $LDFLAGS"
46+
LD_LIBRARY_PATH="/usr/local/lib64:$LD_LIBRARY_PATH"
47+
CIBW_REPAIR_WHEEL_COMMAND: |
48+
auditwheel repair -w {dest_dir} --plat manylinux_2_28_x86_64 {wheel}
49+
CIBW_TEST_COMMAND: |
50+
pip install {package}[test]
51+
pytest -s {project}/tests
52+
CIBW_TEST_EXTRAS: "test"
53+
run: |
54+
python -m cibuildwheel --output-dir wheelhouse
55+
working-directory: ./quaddtype
56+
57+
- uses: actions/upload-artifact@v4
58+
with:
59+
path: ./quaddtype/wheelhouse/*.whl
60+
name: wheels-linux
61+
62+
build_wheels_macos:
63+
name: Build wheels on ${{ matrix.os }}
64+
runs-on: ${{ matrix.os }}
65+
strategy:
66+
matrix:
67+
os: [macos-13, macos-14]
68+
69+
steps:
70+
- uses: actions/checkout@v3
71+
72+
- name: Set up Python
73+
uses: actions/setup-python@v4
74+
with:
75+
python-version: "3.10"
76+
77+
- name: Install SLEEF
78+
env:
79+
MACOSX_DEPLOYMENT_TARGET: "11.0"
80+
run: |
81+
git clone --branch 3.8 https://github.com/shibatch/sleef.git
82+
cd sleef
83+
cmake -S . -B build \
84+
-DSLEEF_BUILD_QUAD:BOOL=ON \
85+
-DSLEEF_BUILD_SHARED_LIBS:BOOL=ON \
86+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
87+
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
88+
-DCMAKE_INSTALL_RPATH="@loader_path/../lib" \
89+
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON
90+
cmake --build build/ --clean-first -j
91+
sudo cmake --install build --prefix /usr/local
92+
- name: Install cibuildwheel
93+
run: pip install cibuildwheel==2.20.0
94+
95+
- name: Build wheels
96+
env:
97+
CIBW_BUILD: "cp310-* cp311-* cp312-*"
98+
CIBW_ARCHS_MACOS: ${{ matrix.os == 'macos-13' && 'x86_64' || 'arm64' }}
99+
CIBW_BUILD_VERBOSITY: "1"
100+
CIBW_ENVIRONMENT: >
101+
MACOSX_DEPLOYMENT_TARGET="11.0"
102+
DYLD_LIBRARY_PATH="/usr/local/lib:$DYLD_LIBRARY_PATH"
103+
CFLAGS="-I/usr/local/include $CFLAGS"
104+
CXXFLAGS="-I/usr/local/include $CXXFLAGS"
105+
LDFLAGS="-L/usr/local/lib $LDFLAGS"
106+
CIBW_REPAIR_WHEEL_COMMAND: >
107+
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
108+
CIBW_TEST_COMMAND: |
109+
pip install {package}[test]
110+
pytest {project}/tests
111+
CIBW_TEST_EXTRAS: "test"
112+
run: |
113+
python -m cibuildwheel --output-dir wheelhouse
114+
working-directory: ./quaddtype
115+
116+
- uses: actions/upload-artifact@v4
117+
with:
118+
path: ./quaddtype/wheelhouse/*.whl
119+
name: wheels-${{ matrix.os }}
120+
121+
build_wheels_windows:
122+
name: Build wheels on Windows
123+
runs-on: windows-latest
124+
strategy:
125+
matrix:
126+
architecture: [x64]
127+
128+
steps:
129+
- uses: actions/checkout@v3
130+
131+
- name: Setup MSVC
132+
uses: ilammy/msvc-dev-cmd@v1
133+
with:
134+
arch: ${{ matrix.architecture }}
135+
136+
- name: Set up Python 3.10
137+
uses: actions/setup-python@v4
138+
with:
139+
python-version: "3.10"
140+
architecture: ${{ matrix.architecture }}
141+
142+
- name: Install CMake
143+
uses: lukka/get-cmake@latest
144+
145+
- name: Clone and Build SLEEF
146+
shell: pwsh
147+
run: |
148+
git clone --branch 3.8 https://github.com/shibatch/sleef.git
149+
cd sleef
150+
cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture == 'x86' && 'Win32' || 'x64' }} -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
151+
cmake --build build --config Release --parallel
152+
cmake --install build --prefix "C:/sleef" --config Release
153+
154+
- name: Setup build environment
155+
shell: pwsh
156+
run: |
157+
$env:INCLUDE += ";C:\sleef\include"
158+
$env:LIB += ";C:\sleef\lib"
159+
$env:PATH = "C:\sleef\bin;$env:PATH"
160+
echo "INCLUDE=$env:INCLUDE" >> $env:GITHUB_ENV
161+
echo "LIB=$env:LIB" >> $env:GITHUB_ENV
162+
echo "PATH=$env:PATH" >> $env:GITHUB_ENV
163+
164+
- name: Install build dependencies
165+
shell: bash -l {0}
166+
run: |
167+
pip install -U pip
168+
pip install cibuildwheel==2.20.0 ninja meson meson-python numpy delvewheel pytest
169+
170+
- name: Build wheels
171+
env:
172+
CIBW_BUILD: "cp310-* cp311-* cp312-*"
173+
CIBW_SKIP: "pp* cp36-* cp37-* cp38-* cp39-* cp313-*"
174+
CIBW_ARCHS_WINDOWS: ${{ matrix.architecture == 'x86' && 'x86' || 'AMD64' }}
175+
CIBW_BUILD_VERBOSITY: "3"
176+
DISTUTILS_USE_SDK: "1"
177+
MSSdk: "1"
178+
CIBW_BEFORE_BUILD: |
179+
pip install meson meson-python ninja numpy
180+
CIBW_REPAIR_WHEEL_COMMAND: 'delvewheel repair -w {dest_dir} {wheel} --add-path C:\sleef\bin'
181+
CIBW_TEST_COMMAND: |
182+
pip install {package}[test]
183+
python -m pytest -v {project}/test
184+
CIBW_TEST_EXTRAS: test
185+
CIBW_TEST_FAIL_FAST: 1
186+
shell: pwsh
187+
run: |
188+
python -m cibuildwheel --output-dir wheelhouse
189+
if (-not (Test-Path wheelhouse/*.whl)) { throw "Wheel was not created" }
190+
working-directory: ./quaddtype
191+
192+
- uses: actions/upload-artifact@v4
193+
with:
194+
path: ./quaddtype/wheelhouse/*.whl
195+
name: wheels-windows-${{ matrix.architecture }}
196+
197+
publish_to_testpypi:
198+
name: Publish to TestPyPI
199+
needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows]
200+
runs-on: ubuntu-latest
201+
if: startsWith(github.ref, 'refs/tags/quaddtype-v')
202+
steps:
203+
- name: Download all workflow run artifacts
204+
uses: actions/download-artifact@v4
205+
with:
206+
path: dist
207+
- name: Publish to TestPyPI
208+
uses: pypa/[email protected]
209+
with:
210+
user: __token__
211+
password: ${{ secrets.PYPI_API_TOKEN }}
212+
repository-url: https://test.pypi.org/legacy/
213+
packages-dir: dist/*
214+
215+
create_release:
216+
name: Create Release
217+
needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows]
218+
runs-on: ubuntu-latest
219+
if: startsWith(github.ref, 'refs/tags/quaddtype-v')
220+
221+
steps:
222+
- name: Checkout code
223+
uses: actions/checkout@v2
224+
225+
- name: Download all workflow run artifacts
226+
uses: actions/download-artifact@v4
227+
with:
228+
path: artifacts
229+
230+
- name: Create Release
231+
id: create_release
232+
uses: actions/create-release@v1
233+
env:
234+
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
235+
with:
236+
tag_name: ${{ github.ref }}
237+
release_name: Release ${{ github.ref }}
238+
draft: false
239+
prerelease: false
240+
241+
- name: Upload Release Assets
242+
uses: softprops/action-gh-release@v1
243+
if: startsWith(github.ref, 'refs/tags/')
244+
with:
245+
files: ./artifacts/**/*.whl
246+
env:
247+
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
sudo apt-get install -y libmpfr-dev libssl-dev libfftw3-dev
6262
- name: Install SLEEF
6363
run: |
64-
git clone https://github.com/shibatch/sleef.git
64+
git clone --branch 3.8 https://github.com/shibatch/sleef.git
6565
cd sleef
6666
cmake -S . -B build -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
6767
cmake --build build/ --clean-first -j

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,7 @@ compile_commands.json
133133

134134
.ruff-cache/
135135
.asv
136-
.vscode/
136+
.vscode/
137+
*.whl
138+
.DS_Store
139+
.idea/

quaddtype/meson.build

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
project('numpy_quaddtype', 'c', 'cpp', default_options : ['cpp_std=c++17', 'b_pie=true'])
1+
project('numpy_quaddtype', 'c', 'cpp', default_options : ['cpp_std=c++20', 'b_pie=true'])
22

33
py_mod = import('python')
44
py = py_mod.find_installation()
5+
py_dep = py.dependency()
56

67
c = meson.get_compiler('c')
8+
cpp = meson.get_compiler('cpp')
79

8-
sleef_dep = c.find_library('sleef')
9-
sleefquad_dep = c.find_library('sleefquad')
10+
is_windows = build_machine.system() == 'windows'
11+
12+
if is_windows
13+
add_project_arguments('-DWIN32', '-D_WINDOWS', language : ['c', 'cpp'])
14+
endif
15+
16+
sleef_dep = [
17+
c.find_library('sleef', required : true),
18+
c.find_library('sleefquad', required : true)
19+
]
1020

1121
incdir_numpy = run_command(py,
12-
[
13-
'-c',
14-
'import numpy; import os; print(os.path.relpath(numpy.get_include()))'
15-
],
16-
check: true
22+
['-c', 'import numpy; print(numpy.get_include())'],
23+
check : true
1724
).stdout().strip()
1825

1926
includes = include_directories(
@@ -50,10 +57,11 @@ py.install_sources(
5057
)
5158

5259
py.extension_module('_quaddtype_main',
53-
srcs,
54-
c_args: ['-g', '-O0', '-lsleef', '-lsleefquad'],
55-
dependencies: [sleef_dep, sleefquad_dep],
56-
install: true,
57-
subdir: 'numpy_quaddtype',
58-
include_directories: includes
60+
srcs,
61+
link_args: is_windows ? ['/DEFAULTLIB:sleef', '/DEFAULTLIB:sleefquad'] : ['-lsleef', '-lsleefquad'],
62+
link_language: 'cpp',
63+
dependencies: [sleef_dep, py_dep],
64+
install: true,
65+
subdir: 'numpy_quaddtype',
66+
include_directories: includes
5967
)

quaddtype/pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
requires = [
33
"meson>=1.3.2",
44
"meson-python",
5-
"patchelf",
65
"wheel",
76
"numpy"
87
]
@@ -13,8 +12,8 @@ name = "numpy_quaddtype"
1312
description = "Quad (128-bit) float dtype for numpy"
1413
version = "0.0.1"
1514
readme = 'README.md'
16-
author = "Swayam Singh"
17-
requires-python = ">=3.9.0"
15+
authors = [{name = "Swayam Singh", email = "[email protected]"}]
16+
requires-python = ">=3.10.0"
1817
dependencies = [
1918
"numpy"
2019
]

quaddtype/tests/test_quaddtype.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,6 @@ def test_unary_ops(op, val, expected):
7171
assert result == expected_val, f"{op}({val}) should be {expected}, but got {result}"
7272

7373

74-
def test_nan_and_inf():
75-
# NaN should not equal itself
76-
assert QuadPrecision("nan") != QuadPrecision("nan")
77-
78-
# Test infinity comparisons
79-
assert QuadPrecision("inf") > QuadPrecision("1e1000")
80-
assert QuadPrecision("-inf") < QuadPrecision("-1e1000")
81-
82-
8374
def test_dtype_creation():
8475
dtype = QuadPrecDType()
8576
assert isinstance(dtype, np.dtype)
@@ -101,4 +92,4 @@ def test_array_operations():
10192
result = arr1 + arr2
10293
expected = np.array(
10394
[QuadPrecision("2.0"), QuadPrecision("3.5"), QuadPrecision("5.0")])
104-
assert np.all(result == expected)
95+
assert all(x == y for x, y in zip(result, expected))

0 commit comments

Comments
 (0)