diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml new file mode 100644 index 00000000..dedafe4d --- /dev/null +++ b/.github/workflows/build_wheels.yml @@ -0,0 +1,247 @@ +name: Build Wheels + +on: + push: + branches: + - main + tags: + - 'quaddtype-v*' + paths: + - 'quaddtype/**' + pull_request: + paths: + - 'quaddtype/**' + workflow_dispatch: + +jobs: + build_wheels_linux: + name: Build wheels on Linux + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '>=3.10.0' + + - name: Install cibuildwheel + run: pip install cibuildwheel==2.20.0 + + - name: Build wheels + env: + CIBW_BUILD: 'cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64' + CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28 + CIBW_BUILD_VERBOSITY: '3' + CIBW_BEFORE_ALL: | + git clone https://github.com/shibatch/sleef.git + cd sleef + cmake -S . -B build -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON + cmake --build build/ --clean-first -j + cmake --install build --prefix /usr/local + CIBW_ENVIRONMENT: > + CFLAGS="-I/usr/local/include $CFLAGS" + CXXFLAGS="-I/usr/local/include $CXXFLAGS" + LDFLAGS="-L/usr/local/lib64 $LDFLAGS" + LD_LIBRARY_PATH="/usr/local/lib64:$LD_LIBRARY_PATH" + CIBW_REPAIR_WHEEL_COMMAND: | + auditwheel repair -w {dest_dir} --plat manylinux_2_28_x86_64 {wheel} + CIBW_TEST_COMMAND: | + pip install {package}[test] + pytest {project}/tests + CIBW_TEST_EXTRAS: 'test' + run: | + python -m cibuildwheel --output-dir wheelhouse + working-directory: ./quaddtype + + - uses: actions/upload-artifact@v4 + with: + path: ./quaddtype/wheelhouse/*.whl + name: wheels-linux + + build_wheels_macos: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-13, macos-14] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install SLEEF + env: + MACOSX_DEPLOYMENT_TARGET: '11.0' + run: | + git clone https://github.com/shibatch/sleef.git + cd sleef + cmake -S . -B build \ + -DSLEEF_BUILD_QUAD:BOOL=ON \ + -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \ + -DCMAKE_INSTALL_RPATH="@loader_path/../lib" \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON + cmake --build build/ --clean-first -j + sudo cmake --install build --prefix /usr/local + - name: Install cibuildwheel + run: pip install cibuildwheel==2.20.0 + + - name: Build wheels + env: + CIBW_BUILD: 'cp310-* cp311-* cp312-*' + CIBW_ARCHS_MACOS: ${{ matrix.os == 'macos-13' && 'x86_64' || 'arm64' }} + CIBW_BUILD_VERBOSITY: '1' + CIBW_ENVIRONMENT: > + MACOSX_DEPLOYMENT_TARGET="11.0" + DYLD_LIBRARY_PATH="/usr/local/lib:$DYLD_LIBRARY_PATH" + CFLAGS="-I/usr/local/include $CFLAGS" + CXXFLAGS="-I/usr/local/include $CXXFLAGS" + LDFLAGS="-L/usr/local/lib $LDFLAGS" + CIBW_REPAIR_WHEEL_COMMAND: > + delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} + CIBW_TEST_COMMAND: | + pip install {package}[test] + pytest {project}/tests + CIBW_TEST_EXTRAS: 'test' + run: | + python -m cibuildwheel --output-dir wheelhouse + working-directory: ./quaddtype + + - uses: actions/upload-artifact@v4 + with: + path: ./quaddtype/wheelhouse/*.whl + name: wheels-${{ matrix.os }} + + build_wheels_windows: + name: Build wheels on Windows + runs-on: windows-latest + strategy: + matrix: + architecture: [x64] + + steps: + - uses: actions/checkout@v3 + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.architecture }} + + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + architecture: ${{ matrix.architecture }} + + - name: Install CMake + uses: lukka/get-cmake@latest + + - name: Clone and Build SLEEF + shell: pwsh + run: | + git clone https://github.com/shibatch/sleef.git + cd sleef + 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 + cmake --build build --config Release --parallel + cmake --install build --prefix "C:/sleef" --config Release + + - name: Setup build environment + shell: pwsh + run: | + $env:INCLUDE += ";C:\sleef\include" + $env:LIB += ";C:\sleef\lib" + $env:PATH = "C:\sleef\bin;$env:PATH" + echo "INCLUDE=$env:INCLUDE" >> $env:GITHUB_ENV + echo "LIB=$env:LIB" >> $env:GITHUB_ENV + echo "PATH=$env:PATH" >> $env:GITHUB_ENV + + - name: Install build dependencies + shell: bash -l {0} + run: | + pip install -U pip + pip install cibuildwheel==2.20.0 ninja meson meson-python numpy delvewheel pytest + + - name: Build wheels + env: + CIBW_BUILD: 'cp310-* cp311-* cp312-*' + CIBW_SKIP: 'pp* cp36-* cp37-* cp38-* cp39-* cp313-*' + CIBW_ARCHS_WINDOWS: ${{ matrix.architecture == 'x86' && 'x86' || 'AMD64' }} + CIBW_BUILD_VERBOSITY: '3' + DISTUTILS_USE_SDK: '1' + MSSdk: '1' + CIBW_BEFORE_BUILD: | + pip install meson meson-python ninja numpy + CIBW_REPAIR_WHEEL_COMMAND: 'delvewheel repair -w {dest_dir} {wheel} --add-path C:\sleef\bin' + CIBW_TEST_COMMAND: | + pip install {package}[test] + python -m pytest -v {project}/test + CIBW_TEST_EXTRAS: test + CIBW_TEST_FAIL_FAST: 1 + shell: pwsh + run: | + python -m cibuildwheel --output-dir wheelhouse + if (-not (Test-Path wheelhouse/*.whl)) { throw "Wheel was not created" } + working-directory: ./quaddtype + + - uses: actions/upload-artifact@v4 + with: + path: ./quaddtype/wheelhouse/*.whl + name: wheels-windows-${{ matrix.architecture }} + + publish_to_testpypi: + name: Publish to TestPyPI + needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/quaddtype-v') + steps: + - name: Download all workflow run artifacts + uses: actions/download-artifact@v4 + with: + path: dist + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@v1.9.0 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + repository-url: https://test.pypi.org/legacy/ + packages-dir: dist/* + + create_release: + name: Create Release + needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/quaddtype-v') + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Download all workflow run artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Upload Release Assets + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: ./artifacts/**/*.whl + env: + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} diff --git a/.gitignore b/.gitignore index 65005454..441eecd1 100644 --- a/.gitignore +++ b/.gitignore @@ -133,4 +133,5 @@ compile_commands.json .ruff-cache/ .asv -.vscode/ \ No newline at end of file +.vscode/ +*.whl diff --git a/quaddtype/meson.build b/quaddtype/meson.build index d6e651b8..e7e8dd97 100644 --- a/quaddtype/meson.build +++ b/quaddtype/meson.build @@ -1,19 +1,26 @@ -project('numpy_quaddtype', 'c', 'cpp', default_options : ['cpp_std=c++17', 'b_pie=true']) +project('numpy_quaddtype', 'c', 'cpp', default_options : ['cpp_std=c++20', 'b_pie=true']) py_mod = import('python') py = py_mod.find_installation() +py_dep = py.dependency() c = meson.get_compiler('c') +cpp = meson.get_compiler('cpp') -sleef_dep = c.find_library('sleef') -sleefquad_dep = c.find_library('sleefquad') +is_windows = build_machine.system() == 'windows' + +if is_windows + add_project_arguments('-DWIN32', '-D_WINDOWS', language : ['c', 'cpp']) +endif + +sleef_dep = [ + c.find_library('sleef', required : true), + c.find_library('sleefquad', required : true) +] incdir_numpy = run_command(py, - [ - '-c', - 'import numpy; import os; print(os.path.relpath(numpy.get_include()))' - ], - check: true + ['-c', 'import numpy; print(numpy.get_include())'], + check : true ).stdout().strip() includes = include_directories( @@ -50,10 +57,11 @@ py.install_sources( ) py.extension_module('_quaddtype_main', -srcs, -c_args: ['-g', '-O0', '-lsleef', '-lsleefquad'], -dependencies: [sleef_dep, sleefquad_dep], -install: true, -subdir: 'numpy_quaddtype', -include_directories: includes + srcs, + link_args: is_windows ? ['/DEFAULTLIB:sleef', '/DEFAULTLIB:sleefquad'] : ['-lsleef', '-lsleefquad'], + link_language: 'cpp', + dependencies: [sleef_dep, py_dep], + install: true, + subdir: 'numpy_quaddtype', + include_directories: includes ) \ No newline at end of file diff --git a/quaddtype/pyproject.toml b/quaddtype/pyproject.toml index 836b73f2..30898c72 100644 --- a/quaddtype/pyproject.toml +++ b/quaddtype/pyproject.toml @@ -2,7 +2,6 @@ requires = [ "meson>=1.3.2", "meson-python", - "patchelf", "wheel", "numpy" ] @@ -13,8 +12,8 @@ name = "numpy_quaddtype" description = "Quad (128-bit) float dtype for numpy" version = "0.0.1" readme = 'README.md' -author = "Swayam Singh" -requires-python = ">=3.9.0" +authors = [{name = "Swayam Singh", email = "singhswayam008@gmail.com"}] +requires-python = ">=3.10.0" dependencies = [ "numpy" ]