Skip to content

Commit 8bfe949

Browse files
committed
Improve meson build
1 parent 98d94b3 commit 8bfe949

File tree

6 files changed

+84
-189
lines changed

6 files changed

+84
-189
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
needs: [dist]
119119

120120
env:
121-
# Ubuntu packages to install so that the project's "python -m build --sdist" can succeed
121+
# Ubuntu packages to install so that building the sdist can succeed
122122
DIST_PREREQ: libpari-dev pari-doc libbz2-dev bzip2
123123
# Name of this project in the Sage distribution
124124
SPKG: cypari

MANIFEST.in

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

cypari2/meson.build

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
py.install_sources(
2+
'__init__.py',
3+
'closure.pxd',
4+
'convert.pxd',
5+
'gen.pxd',
6+
'handle_error.pxd',
7+
'pari_instance.pxd',
8+
'paridecl.pxd',
9+
'paripriv.pxd',
10+
'pycore_long.pxd',
11+
'stack.pxd',
12+
'string_utils.pxd',
13+
'types.pxd',
14+
'cypari.h',
15+
'pycore_long.h',
16+
'auto_paridecl.pxd',
17+
'auto_gen.pxi',
18+
'auto_instance.pxi',
19+
subdir: 'cypari2'
20+
)
21+
22+
23+
extension_data = {
24+
'closure': files('closure.pyx'),
25+
'stack': files('stack.pyx'),
26+
'custom_block': files('custom_block.pyx'),
27+
'convert': files('convert.pyx'),
28+
'string_utils': files('string_utils.pyx'),
29+
'handle_error': files('handle_error.pyx'),
30+
'gen': files('gen.pyx'),
31+
'pari_instance': files('pari_instance.pyx')
32+
}
33+
34+
foreach name, pyx : extension_data
35+
py.extension_module(
36+
name,
37+
sources: pyx,
38+
subdir: 'cypari2',
39+
install: true,
40+
#include_directories: [inc_dirs, 'cypari2'],
41+
dependencies: [cysignals, pari],
42+
)
43+
endforeach
44+

meson.build

Lines changed: 33 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,51 @@
1-
project('cypari2', 'c',
2-
version: run_command(
3-
'cat', files('VERSION'),
4-
check: true
5-
).stdout().strip(),
6-
default_options: ['warning_level=0']
1+
project('cypari2',
2+
['c', 'cython'],
3+
version: files('VERSION'),
4+
license: 'GPL v3',
5+
default_options: ['c_std=c17', 'cpp_std=c++17', 'python.install_env=auto'],
6+
meson_version: '>=1.2',
77
)
88

9-
# Import Python module
9+
# Python module
10+
# https://mesonbuild.com/Python-module.html
1011
py = import('python').find_installation(pure: false)
1112

12-
# Add dependencies
13-
cython = find_program('cython', required: true)
13+
# Compilers
14+
cc = meson.get_compiler('c')
15+
cython = meson.get_compiler('cython')
1416

15-
# Import the dependencies we need
16-
cysignals_dep = dependency('cysignals', required: false)
17-
cysignals_include_dir = []
18-
19-
if not cysignals_dep.found()
20-
# Try to find cysignals via Python
21-
cysignals_result = run_command(
22-
py.full_path(), '-c',
17+
# Dependencies
18+
inc_cysignals = run_command(
19+
py,
20+
[
21+
'-c',
2322
'''
23+
from os.path import relpath
2424
import cysignals
25-
import os
26-
print(os.path.dirname(cysignals.__file__))
27-
''',
28-
check: false
29-
)
30-
if cysignals_result.returncode() == 0
31-
cysignals_include_dir = [cysignals_result.stdout().strip()]
32-
else
33-
error('cysignals not found. Please install cysignals.')
34-
endif
35-
endif
36-
37-
# Get include directories for PARI
38-
pari_include_dirs = []
39-
pari_library_dirs = []
40-
41-
# Try to find PARI using pkg-config
42-
pari_dep = dependency('pari', required: false)
43-
44-
if not pari_dep.found()
45-
# Fallback: run a Python script to get PARI paths
46-
pari_paths_result = run_command(
47-
py.full_path(), '-c',
48-
'''
49-
import sys, json
50-
sys.path.insert(0, ".")
25+
path = cysignals.__file__.replace('__init__.py', '')
5126
try:
52-
from autogen.paths import include_dirs, library_dirs
53-
result = {"include_dirs": include_dirs(), "library_dirs": library_dirs()}
54-
print(json.dumps(result))
55-
except Exception as e:
56-
print(json.dumps({"include_dirs": [], "library_dirs": [], "error": str(e)}))
57-
''',
58-
check: true
59-
)
60-
61-
pari_json_str = pari_paths_result.stdout().strip()
62-
# For now, use common paths as fallback
63-
pari_include_dirs = ['/usr/include', '/usr/local/include']
64-
pari_library_dirs = ['/usr/lib', '/usr/local/lib', '/usr/lib/x86_64-linux-gnu']
65-
endif
66-
67-
# Include directories
68-
all_include_dirs = pari_include_dirs + cysignals_include_dir
69-
inc_dirs = include_directories(all_include_dirs)
27+
print(relpath(path))
28+
except Exception:
29+
print(path)
30+
'''.strip(),
31+
],
32+
check: true,
33+
).stdout().strip()
34+
cysignals = declare_dependency(include_directories: inc_cysignals)
35+
# Cannot be found via pkg-config
36+
pari = cc.find_library('pari', required: true)
7037

7138
# Run code generation step
7239
code_gen_result = run_command(
7340
py.full_path(), '-c',
7441
'''
7542
import sys
7643
sys.path.insert(0, ".")
77-
try:
78-
from autogen import rebuild
79-
rebuild(force=True)
80-
print("Code generation successful")
81-
except Exception as e:
82-
print("Code generation failed: " + str(e))
83-
import traceback
84-
traceback.print_exc()
44+
from autogen import rebuild
45+
rebuild(force=True)
46+
print("Code generation successful")
8547
''',
86-
check: false
48+
check: true
8749
)
8850

89-
if code_gen_result.returncode() != 0
90-
warning('Code generation may have failed: ' + code_gen_result.stdout() + code_gen_result.stderr())
91-
endif
92-
93-
# Define the source files
94-
cython_sources = [
95-
'cypari2/closure.pyx',
96-
'cypari2/stack.pyx',
97-
'cypari2/custom_block.pyx',
98-
'cypari2/convert.pyx',
99-
'cypari2/string_utils.pyx',
100-
'cypari2/handle_error.pyx',
101-
'cypari2/gen.pyx',
102-
'cypari2/pari_instance.pyx'
103-
]
104-
105-
# Create targets for each Cython source file
106-
py_sources = []
107-
foreach src : cython_sources
108-
basename = src.split('/')[1].split('.')[0]
109-
c_file = custom_target(basename + '_c',
110-
input: src,
111-
output: basename + '.c',
112-
command: [
113-
cython,
114-
'-3',
115-
'--capi-reexport-cincludes',
116-
'-I', meson.current_source_dir() / 'cypari2',
117-
'@INPUT@',
118-
'-o', '@OUTPUT@'
119-
]
120-
)
121-
122-
py_ext = py.extension_module(
123-
basename,
124-
c_file,
125-
include_directories: [inc_dirs, 'cypari2'],
126-
dependencies: [cysignals_dep, pari_dep],
127-
link_args: ['-lpari'],
128-
install: true,
129-
subdir: 'cypari2'
130-
)
131-
py_sources += py_ext
132-
endforeach
133-
134-
# Install Python package files
135-
python_sources = [
136-
'cypari2/__init__.py',
137-
]
138-
139-
py.install_sources(
140-
python_sources,
141-
subdir: 'cypari2'
142-
)
143-
144-
# Install package data files
145-
package_data = [
146-
'cypari2/closure.pxd',
147-
'cypari2/convert.pxd',
148-
'cypari2/gen.pxd',
149-
'cypari2/handle_error.pxd',
150-
'cypari2/pari_instance.pxd',
151-
'cypari2/paridecl.pxd',
152-
'cypari2/paripriv.pxd',
153-
'cypari2/pycore_long.pxd',
154-
'cypari2/stack.pxd',
155-
'cypari2/string_utils.pxd',
156-
'cypari2/types.pxd',
157-
'cypari2/cypari.h',
158-
'cypari2/pycore_long.h',
159-
]
160-
161-
# Check if auto-generated files exist and install them
162-
auto_files = [
163-
'cypari2/auto_paridecl.pxd',
164-
'cypari2/auto_gen.pxi',
165-
'cypari2/auto_instance.pxi',
166-
]
167-
168-
foreach f : auto_files
169-
if import('fs').is_file(f)
170-
package_data += f
171-
endif
172-
endforeach
173-
174-
py.install_sources(
175-
package_data,
176-
subdir: 'cypari2',
177-
preserve_path: false
178-
)
51+
subdir('cypari2')

pari.tgz

Whitespace-only changes.

pyproject.toml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
[build-system]
2-
requires = [
3-
"meson-python>=0.15.0",
4-
"Cython>=3.0",
5-
"cysignals>=1.11.3",
6-
"meson>=1.1.0",
7-
"ninja",
8-
"pkg-config",
9-
]
2+
requires = ["meson-python>=0.15.0", "cython>=3.0", "cysignals>=1.11.3"]
103
build-backend = "mesonpy"
114

125
[project]
136
name = "cypari2"
147
description = "A Python interface to the number theory library PARI/GP"
158
authors = [
16-
{name = "Luca De Feo, Vincent Delecroix, Jeroen Demeyer, Vincent Klein"},
9+
{ name = "Luca De Feo, Vincent Delecroix, Jeroen Demeyer, Vincent Klein" },
1710
]
1811
maintainers = [
19-
{name = "SageMath developers", email = "[email protected]"},
20-
]
21-
dependencies = [
22-
"cysignals>=1.11.3",
12+
{ name = "SageMath developers", email = "[email protected]" },
2313
]
14+
dependencies = ["cysignals>=1.11.3"]
2415
requires-python = ">=3.9"
2516
readme = "README.rst"
26-
license = {text = "GNU General Public License, version 2 or later"}
17+
license = { text = "GNU General Public License, version 2 or later" }
2718
keywords = ["PARI/GP number theory"]
28-
dynamic = [
29-
"version",
30-
]
19+
dynamic = ["version"]
3120

3221
[project.urls]
3322
Homepage = "https://github.com/sagemath/cypari2"
34-
35-

0 commit comments

Comments
 (0)