Skip to content

Commit a65c88c

Browse files
Merge pull request #129 from oscarbenjamin/pr_meson_python
Use meson-python instead of setuptools for wheels
2 parents 1ce152d + cfe2fea commit a65c88c

File tree

16 files changed

+260
-42
lines changed

16 files changed

+260
-42
lines changed

.cirrus.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ cirrus_wheels_macos_arm64_task:
99
env:
1010
PATH: /opt/homebrew/opt/[email protected]/bin:$PATH
1111
CIBW_ARCHS_MACOS: arm64
12+
CIBW_TEST_COMMAND: "python -m flint.test"
1213
install_pre_requirements_script:
13-
- brew install [email protected]
14-
- ln -s python3 /opt/homebrew/opt/[email protected]/bin/python
15-
- which python
16-
- python --version
17-
install_cibuildwheel_script:
18-
- python -m pip install cibuildwheel==2.16.2
14+
- python3 -m venv venv
15+
- venv/bin/pip install --upgrade pip
16+
- venv/bin/pip install cibuildwheel==2.16.2
1917
run_cibuildwheel_script:
20-
- bin/cibw.sh
18+
- venv/bin/cibuildwheel --platform macos
2119
wheels_artifacts:
2220
path: "wheelhouse/*"

.github/workflows/buildwheel.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
os: [ubuntu-20.04, windows-2019, macos-12]
13+
os: [ubuntu-20.04, windows-2019, macos-13]
1414

1515
steps:
1616
- uses: actions/checkout@v4
@@ -31,6 +31,16 @@ jobs:
3131
path-type: inherit
3232
if: ${{ matrix.os == 'windows-2019' }}
3333

34+
# Install pkgconfig on Windows from choco rather than from msys and
35+
# avoid using the Strawberry one.
36+
- run: choco install -y --stoponfirstfailure --checksum 6004DF17818F5A6DBF19CB335CC92702 pkgconfiglite
37+
if: ${{ matrix.os == 'windows-2019' }}
38+
39+
# We have to set this here rather than in the cibuildwheel config
40+
# This is probably something to do with \ vs / in paths...
41+
- run: echo "PKG_CONFIG_PATH=${{ github.workspace }}/.local/lib/pkgconfig" >> $env:GITHUB_ENV
42+
if: ${{ matrix.os == 'windows-2019' }}
43+
3444
- name: Build wheels
3545
uses: pypa/[email protected]
3646
env:
@@ -45,7 +55,7 @@ jobs:
4555

4656
build_sdist:
4757
name: Build sdist
48-
runs-on: ubuntu-20.04
58+
runs-on: ubuntu-22.04
4959

5060
steps:
5161
- uses: actions/checkout@v4
@@ -54,6 +64,11 @@ jobs:
5464
with:
5565
python-version: '3.12'
5666

67+
- run: sudo apt-get update
68+
- run: sudo apt-get install libgmp-dev libmpfr-dev xz-utils ninja-build
69+
- run: curl -O -L https://www.flintlib.org/flint-3.1.0.tar.gz
70+
- run: tar -xzf flint-3.1.0.tar.gz
71+
- run: cd flint-3.1.0 && ./configure --disable-static && make -j4 && sudo make install
5772
- run: pip install build
5873
- run: python -m build --sdist
5974

@@ -91,7 +106,7 @@ jobs:
91106
strategy:
92107
fail-fast: false
93108
matrix:
94-
os: [ubuntu-20.04, windows-2019, macos-12]
109+
os: [ubuntu-20.04, windows-2019, macos-13]
95110
python-version: ['3.9', '3.10', '3.11', '3.12']
96111

97112
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ MANIFEST
1818
.python-version
1919
*.DS_Store
2020
.venv
21+
.hypothesis

bin/activate

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export C_INCLUDE_PATH=$(pwd)/.local/include
22
export LIBRARY_PATH=$(pwd)/.local/lib
33
export LD_LIBRARY_PATH=$(pwd)/.local/lib
4-
export PYTHONPATH=$(pwd)/src

bin/cibw.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

bin/pip_install_ubuntu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PYTHON_FLINT=$1
3535

3636
# First install their dependencies and build dependencies
3737
sudo apt-get update
38-
sudo apt-get install libgmp-dev libmpfr-dev xz-utils
38+
sudo apt-get install libgmp-dev libmpfr-dev xz-utils ninja-build
3939

4040
if [ -z "$FLINT_GIT" ]; then
4141
# Install from release tarball

meson.build

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
project('python-flint', 'cython', 'c')
2+
3+
py = import('python').find_installation(pure: false)
4+
dep_py = py.dependency()
5+
6+
cc = meson.get_compiler('c')
7+
8+
gmp_dep = dependency('gmp')
9+
mpfr_dep = dependency('mpfr')
10+
flint_dep = dependency('flint')
11+
12+
# flint.pc was missing -lflint until Flint 3.1.0
13+
if flint_dep.version().version_compare('<3.1')
14+
flint_dep = cc.find_library('flint')
15+
endif
16+
17+
pyflint_deps = [dep_py, gmp_dep, mpfr_dep, flint_dep]
18+
19+
subdir('src/flint')

pyproject.toml

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[build-system]
2-
requires = ["setuptools",
3-
"numpy; sys_platform == 'win32' and python_version < '3.12'",
4-
"Cython>=3"]
5-
build-backend = "setuptools.build_meta"
2+
requires = ["meson-python", "cython"]
3+
build-backend = "mesonpy"
64

75
[project]
86
name = "python-flint"
@@ -21,18 +19,46 @@ classifiers = [
2119
file = "README.md"
2220
content-type = "text/markdown"
2321

22+
[tool.spin]
23+
package = "flint"
24+
25+
[tool.spin.commands]
26+
27+
"Build" = [
28+
"spin.cmds.meson.build",
29+
"spin.cmds.meson.test",
30+
"spin.cmds.build.sdist",
31+
"spin.cmds.pip.install",
32+
]
33+
"Documentation" = [
34+
"spin.cmds.meson.docs",
35+
]
36+
"Environments" = [
37+
"spin.cmds.meson.shell",
38+
"spin.cmds.meson.ipython",
39+
"spin.cmds.meson.python",
40+
"spin.cmds.meson.run",
41+
]
42+
2443
[tool.cibuildwheel]
2544
build = "cp39-* cp310-* cp311-* cp312-*"
2645
skip = "*-win32 *-manylinux_i686 *-musllinux_*"
2746
manylinux-x86_64-image = "manylinux2014"
2847
manylinux-i686-image = "manylinux2014"
2948
test-command = "python -c \"import flint; print(str(flint.fmpz(2)))\""
3049

31-
[tool.cibuildwheel.environment]
32-
# bin/build_dependencies_unix.sh places headers and shared libraries under .local
33-
C_INCLUDE_PATH = "$(pwd)/.local/include/"
34-
LIBRARY_PATH = "$(pwd)/.local/lib/"
50+
[tool.cibuildwheel.linux.environment]
51+
# LD_LIBRARY_PATH is needed by auditwheel
3552
LD_LIBRARY_PATH = "$(pwd)/.local/lib:$LD_LIBRARY_PATH"
53+
PKG_CONFIG_PATH = "$(pwd)/.local/lib/pkgconfig"
54+
55+
[tool.cibuildwheel.macos.environment]
56+
PKG_CONFIG_PATH = "$(pwd)/.local/lib/pkgconfig"
57+
58+
[tool.cibuildwheel.windows.environment]
59+
# Setting PKG_CONFIG_PATH here breaks pkgconfig for some reason...
60+
# We set it in the CI workflow instead.
61+
# PKG_CONFIG_PATH = "$(pwd)/.local/lib/pkgconfig:$PKG_CONFIG_PATH"
3662

3763
[tool.cibuildwheel.linux]
3864
before-all = "bin/cibw_before_all_linux.sh"
@@ -44,6 +70,3 @@ before-all = "bin/cibw_before_all_macosx_$(uname -m).sh"
4470
before-all = "C:\\msys64\\usr\\bin\\bash bin/cibw_before_all_windows.sh"
4571
before-build = "pip install delvewheel && C:\\msys64\\usr\\bin\\bash bin/cibw_before_build_windows.sh"
4672
repair-wheel-command = "bin\\cibw_repair_wheel_command_windows.bat {dest_dir} {wheel}"
47-
48-
[tool.cibuildwheel.windows.environment]
49-
PYTHON_FLINT_MINGW64 = "true"

src/flint/flint_base/meson.build

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pkgdir = 'flint/flint_base'
2+
3+
pyfiles = [
4+
'__init__.py',
5+
]
6+
7+
exts = [
8+
'flint_base',
9+
'flint_context',
10+
]
11+
12+
py.install_sources(
13+
pyfiles,
14+
pure: false,
15+
subdir: pkgdir,
16+
)
17+
18+
foreach ext : exts
19+
py.extension_module(
20+
ext,
21+
ext + '.pyx',
22+
dependencies: pyflint_deps,
23+
install: true,
24+
subdir: pkgdir,
25+
)
26+
endforeach

src/flint/functions/meson.build

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pyfiles = [
2+
'__init__.py',
3+
]
4+
5+
exts = [
6+
'showgood',
7+
]
8+
9+
py.install_sources(
10+
pyfiles,
11+
pure: false,
12+
subdir: 'flint/functions',
13+
)
14+
15+
foreach ext : exts
16+
py.extension_module(
17+
ext,
18+
ext + '.pyx',
19+
dependencies: pyflint_deps,
20+
install: true,
21+
subdir: 'flint/functions',
22+
)
23+
endforeach

0 commit comments

Comments
 (0)