Skip to content

Commit cb77ce4

Browse files
committed
refactoring
1 parent 1493a9b commit cb77ce4

File tree

3 files changed

+78
-154
lines changed

3 files changed

+78
-154
lines changed

.github/workflows/build_wheel.yml renamed to .github/workflows/build_wheels.yml

Lines changed: 59 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ on:
55
branches:
66
- main
77
tags:
8-
- "v*"
8+
- "quaddtype-v*"
9+
paths:
10+
- "quaddtype/**"
911
pull_request:
12+
paths:
13+
- "quaddtype/**"
14+
workflow_dispatch:
1015

1116
jobs:
1217
build_wheels_linux:
@@ -29,40 +34,27 @@ jobs:
2934
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
3035
CIBW_BUILD_VERBOSITY: "3"
3136
CIBW_BEFORE_ALL: |
32-
yum install -y wget
33-
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
34-
bash miniconda.sh -b -p /root/miniconda
35-
export PATH="/root/miniconda/bin:$PATH"
36-
conda config --set always_yes yes --set changeps1 no
37-
conda update -q conda
38-
conda info -a
39-
conda config --add channels conda-forge
40-
conda config --set channel_priority strict
41-
conda create -n build_env python=3.10
42-
source activate build_env
43-
conda install -y sleef
37+
git clone 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
4442
CIBW_ENVIRONMENT: >
45-
LD_LIBRARY_PATH="/root/miniconda/envs/build_env/lib:$LD_LIBRARY_PATH"
46-
LIBRARY_PATH="/root/miniconda/envs/build_env/lib:$LIBRARY_PATH"
47-
CFLAGS="-I/root/miniconda/envs/build_env/include $CFLAGS"
48-
CXXFLAGS="-I/root/miniconda/envs/build_env/include $CXXFLAGS"
49-
LDFLAGS="-L/root/miniconda/envs/build_env/lib $LDFLAGS"
50-
SLEEF_PATH="/root/miniconda/envs/build_env"
51-
CIBW_REPAIR_WHEEL_COMMAND: >
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: |
5248
auditwheel repair -w {dest_dir} --plat manylinux_2_28_x86_64 {wheel}
5349
CIBW_TEST_COMMAND: |
54-
python -c "import os; print('SLEEF_PATH:', os.environ.get('SLEEF_PATH', 'Not set'))"
55-
python -c "import platform; print('Python version:', platform.python_version())"
56-
python -c "import sys; print('sys.platform:', sys.platform)"
57-
python -c "import quaddtype; print('quaddtype imported successfully')"
5850
pip install {package}[test]
5951
pytest {project}/tests
6052
CIBW_TEST_EXTRAS: "test"
6153
run: |
6254
python -m cibuildwheel --output-dir wheelhouse
6355
working-directory: ./quaddtype
6456

65-
- uses: actions/upload-artifact@v3
57+
- uses: actions/upload-artifact@v4
6658
with:
6759
path: ./quaddtype/wheelhouse/*.whl
6860
name: wheels-linux
@@ -80,59 +72,48 @@ jobs:
8072
- name: Set up Python
8173
uses: actions/setup-python@v4
8274
with:
83-
python-version: ">=3.10.0"
84-
85-
- name: Setup Miniconda
86-
uses: conda-incubator/setup-miniconda@v3
87-
with:
88-
auto-update-conda: true
8975
python-version: "3.10"
90-
channels: conda-forge
9176

9277
- name: Install SLEEF
93-
shell: bash -l {0}
78+
env:
79+
MACOSX_DEPLOYMENT_TARGET: "11.0"
9480
run: |
95-
conda install -y -c conda-forge sleef
96-
echo $CONDA_PREFIX
97-
echo "SLEEF_PATH=$CONDA_PREFIX" >> $GITHUB_ENV
98-
81+
git clone 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
9992
- name: Install cibuildwheel
10093
run: pip install cibuildwheel==2.20.0
10194

10295
- name: Build wheels
10396
env:
104-
CIBW_BUILD_VERBOSITY: "1"
97+
CIBW_BUILD: "cp310-* cp311-* cp312-*"
10598
CIBW_ARCHS_MACOS: ${{ matrix.os == 'macos-13' && 'x86_64' || 'arm64' }}
106-
CIBW_SKIP: "pp* cp36-* cp37-* cp38-* cp39-* cp313-*"
99+
CIBW_BUILD_VERBOSITY: "1"
107100
CIBW_ENVIRONMENT: >
108-
SLEEF_PATH="${{ env.SLEEF_PATH }}"
109-
DYLD_LIBRARY_PATH="${{ env.SLEEF_PATH }}/lib:$DYLD_LIBRARY_PATH"
110-
LIBRARY_PATH="${{ env.SLEEF_PATH }}/lib:$LIBRARY_PATH"
111-
CFLAGS="-I${{ env.SLEEF_PATH }}/include $CFLAGS"
112-
CXXFLAGS="-I${{ env.SLEEF_PATH }}/include $CXXFLAGS"
113-
LDFLAGS="-L${{ env.SLEEF_PATH }}/lib $LDFLAGS"
114-
MACOSX_DEPLOYMENT_TARGET="10.13"
115-
CIBW_REPAIR_WHEEL_COMMAND: "delocate-wheel -w {dest_dir} -v {wheel}"
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}
116108
CIBW_TEST_COMMAND: |
117-
python -c "import os; print('SLEEF_PATH:', os.environ.get('SLEEF_PATH', 'Not set'))"
118-
python -c "import platform; print('Python version:', platform.python_version())"
119-
python -c "import sys; print('sys.platform:', sys.platform)"
120-
python -c "import quaddtype; print('quaddtype imported successfully')"
121109
pip install {package}[test]
122110
pytest {project}/tests
123111
CIBW_TEST_EXTRAS: "test"
124112
run: |
125-
echo "SLEEF_PATH: $SLEEF_PATH"
126-
ls $SLEEF_PATH/include/sleef*
127-
echo "PATH: $PATH"
128-
which python
129-
python --version
130-
which pip
131-
pip --version
132-
cd quaddtype
133113
python -m cibuildwheel --output-dir wheelhouse
114+
working-directory: ./quaddtype
134115

135-
- uses: actions/upload-artifact@v3
116+
- uses: actions/upload-artifact@v4
136117
with:
137118
path: ./quaddtype/wheelhouse/*.whl
138119
name: wheels-${{ matrix.os }}
@@ -171,20 +152,16 @@ jobs:
171152
conda config --add channels conda-forge
172153
conda config --set channel_priority strict
173154
conda install -y sleef numpy
174-
conda list
175-
if [ ! -f "$CONDA_PREFIX/Library/include/sleef.h" ]; then
176-
echo "sleef.h not found. Installation may have failed."
177-
exit 1
178-
fi
179-
ls -l "$CONDA_PREFIX/Library/include/sleef.h"
180-
ls -l "$CONDA_PREFIX/Library/lib/sleef"*
181155
182-
- name: Set environment variables
156+
- name: Setup build environment
183157
shell: pwsh
184158
run: |
185-
echo "CONDA_PREFIX=$env:CONDA_PREFIX" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
186-
$numpy_path = python -c "import numpy; import os; print(os.path.abspath(numpy.get_include()).replace(os.sep, '/'))"
187-
echo "NUMPY_INCLUDE_DIR=$numpy_path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
159+
$env:INCLUDE += ";$env:CONDA_PREFIX\Library\include"
160+
$env:LIB += ";$env:CONDA_PREFIX\Library\lib"
161+
$env:PATH = "$env:CONDA_PREFIX\Library\bin;$env:PATH"
162+
echo "INCLUDE=$env:INCLUDE" >> $env:GITHUB_ENV
163+
echo "LIB=$env:LIB" >> $env:GITHUB_ENV
164+
echo "PATH=$env:PATH" >> $env:GITHUB_ENV
188165
189166
- name: Install build dependencies
190167
shell: bash -l {0}
@@ -194,36 +171,27 @@ jobs:
194171
195172
- name: Build wheels
196173
env:
197-
CONDA_PREFIX: ${{ env.CONDA_PREFIX }}
174+
CIBW_BUILD: "cp310-* cp311-* cp312-*"
198175
CIBW_SKIP: "pp* cp36-* cp37-* cp38-* cp39-* cp313-*"
199176
CIBW_ARCHS_WINDOWS: ${{ matrix.architecture == 'x86' && 'x86' || 'AMD64' }}
200-
CIBW_BUILD_VERBOSITY: "1"
201-
SLEEF_INCLUDE_DIR: ${{ env.CONDA_PREFIX }}\Library\include
202-
SLEEF_LIBRARY: ${{ env.CONDA_PREFIX }}\Library\lib
177+
CIBW_BUILD_VERBOSITY: "3"
203178
DISTUTILS_USE_SDK: "1"
204179
MSSdk: "1"
205-
NUMPY_INCLUDE_DIR: ${{ env.NUMPY_INCLUDE_DIR }}
206-
CIBW_ENVIRONMENT: >-
207-
NUMPY_INCLUDE_DIR="${{ env.NUMPY_INCLUDE_DIR }}"
208-
SLEEF_INCLUDE_DIR="${{ env.CONDA_PREFIX }}/Library/include"
209-
SLEEF_LIBRARY="${{ env.CONDA_PREFIX }}/Library/lib"
210-
CIBW_BEFORE_BUILD: pip install meson meson-python ninja numpy
180+
CIBW_BEFORE_BUILD: |
181+
pip install meson meson-python ninja numpy
211182
CIBW_REPAIR_WHEEL_COMMAND: "delvewheel repair -w {dest_dir} {wheel}"
212183
CIBW_TEST_COMMAND: |
213-
python -c "import platform; print('Python version:', platform.python_version())"
214-
python -c "import sys; print('sys.platform:', sys.platform)"
215-
python -c "import quaddtype; print('quaddtype imported successfully')"
216184
pip install {package}[test]
217-
pytest {project}\tests -v || (echo "Tests failed" && exit 1)
218-
CIBW_TEST_EXTRAS: "test"
185+
python -m pytest -v {project}/test
186+
CIBW_TEST_EXTRAS: test
219187
CIBW_TEST_FAIL_FAST: 1
220188
shell: pwsh
221189
run: |
222190
python -m cibuildwheel --output-dir wheelhouse
223191
if (-not (Test-Path wheelhouse/*.whl)) { throw "Wheel was not created" }
224192
working-directory: ./quaddtype
225193

226-
- uses: actions/upload-artifact@v3
194+
- uses: actions/upload-artifact@v4
227195
with:
228196
path: ./quaddtype/wheelhouse/*.whl
229197
name: wheels-windows-${{ matrix.architecture }}
@@ -232,10 +200,10 @@ jobs:
232200
name: Publish to TestPyPI
233201
needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows]
234202
runs-on: ubuntu-latest
235-
if: startsWith(github.ref, 'refs/tags/')
203+
if: startsWith(github.ref, 'refs/tags/quaddtype-v')
236204
steps:
237205
- name: Download all workflow run artifacts
238-
uses: actions/download-artifact@v2
206+
uses: actions/download-artifact@v4
239207
with:
240208
path: dist
241209
- name: Publish to TestPyPI
@@ -250,14 +218,14 @@ jobs:
250218
name: Create Release
251219
needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows]
252220
runs-on: ubuntu-latest
253-
if: startsWith(github.ref, 'refs/tags/')
221+
if: startsWith(github.ref, 'refs/tags/quaddtype-v')
254222

255223
steps:
256224
- name: Checkout code
257225
uses: actions/checkout@v2
258226

259227
- name: Download all workflow run artifacts
260-
uses: actions/download-artifact@v2
228+
uses: actions/download-artifact@v4
261229
with:
262230
path: artifacts
263231

quaddtype/meson.build

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,27 @@
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

810
is_windows = build_machine.system() == 'windows'
911

10-
incdir_numpy = ''
1112
if is_windows
1213
add_project_arguments('-DWIN32', '-D_WINDOWS', language : ['c', 'cpp'])
13-
14-
conda_env_dir = run_command('cmd', '/c', 'echo %CONDA_PREFIX%', check: true).stdout().strip()
15-
sleef_include_dir = conda_env_dir + '\\Library\\include'
16-
sleef_library_dir = conda_env_dir + '\\Library\\lib'
17-
incdir_numpy = run_command('cmd', '/c', 'echo %NUMPY_INCLUDE_DIR%', check: true).stdout().strip()
18-
19-
add_project_arguments('-I' + sleef_include_dir, language: ['c', 'cpp'])
20-
add_project_link_arguments('-L' + sleef_library_dir, language: ['c', 'cpp'])
21-
22-
sleef_lib = c.find_library('sleef', dirs: [sleef_library_dir])
23-
sleefquad_lib = c.find_library('sleefquad', dirs: [sleef_library_dir])
24-
25-
sleef_dep = declare_dependency(include_directories: include_directories(sleef_include_dir),
26-
dependencies: [sleef_lib, sleefquad_lib])
27-
else
28-
# Linux and macOS configuration
29-
30-
# Get the SLEEF path
31-
sleef_path = run_command('bash', '-c', 'echo $SLEEF_PATH', check: false).stdout().strip()
32-
if sleef_path == ''
33-
sleef_path = run_command('bash', '-c', 'echo $CONDA_PREFIX', check: false).stdout().strip()
34-
endif
35-
36-
if sleef_path == ''
37-
error('SLEEF_PATH or CONDA_PREFIX environment variable is not set')
38-
endif
39-
40-
add_project_link_arguments('-L' + sleef_path + '/lib', language: ['c', 'cpp'])
41-
42-
sleef_include_dir = sleef_path + '/include'
43-
sleef_library_dir = sleef_path + '/lib'
44-
45-
add_project_arguments('-I' + sleef_include_dir, language: ['c', 'cpp'])
46-
add_project_link_arguments('-L' + sleef_library_dir, language: ['c', 'cpp'])
47-
48-
sleef_dep = c.find_library('sleef', dirs: [sleef_library_dir])
49-
sleefquad_dep = c.find_library('sleefquad', dirs: [sleef_library_dir])
5014
endif
5115

52-
if not sleef_dep.found() or (not is_windows and not sleefquad_dep.found())
53-
error('SLEEF library not found. Please ensure it is installed in your conda environment.')
54-
endif
16+
sleef_dep = [
17+
c.find_library('sleef', required : true),
18+
c.find_library('sleefquad', required : true)
19+
]
5520

56-
# Try to get NumPy include path from environment variable first
57-
if incdir_numpy == ''
58-
incdir_numpy = run_command(py,
59-
[
60-
'-c',
61-
'import numpy; import os; print(os.path.relpath(numpy.get_include()))'
62-
],
63-
check: false
64-
).stdout().strip()
65-
66-
if incdir_numpy == ''
67-
error('NumPy include directory not found. Please set NUMPY_INCLUDE_DIR or ensure NumPy is installed.')
68-
endif
69-
endif
21+
incdir_numpy = run_command(py,
22+
['-c', 'import numpy; print(numpy.get_include())'],
23+
check : true
24+
).stdout().strip()
7025

7126
includes = include_directories(
7227
[
@@ -102,10 +57,11 @@ py.install_sources(
10257
)
10358

10459
py.extension_module('_quaddtype_main',
105-
srcs,
106-
c_args: ['-g', '-O0', '-lsleef', '-lsleefquad'],
107-
dependencies: [sleef_dep, sleefquad_dep],
108-
install: true,
109-
subdir: 'numpy_quaddtype',
110-
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
11167
)

quaddtype/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-backend = "mesonpy"
1010
[project]
1111
name = "numpy_quaddtype"
1212
description = "Quad (128-bit) float dtype for numpy"
13-
version = "0.0.2"
13+
version = "0.0.1"
1414
readme = 'README.md'
1515
authors = [{name = "Swayam Singh", email = "singhswayam008@gmail.com"}]
1616
requires-python = ">=3.10.0"

0 commit comments

Comments
 (0)