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 ' ,
7
7
)
8
8
9
- # Import Python module
9
+ # Python module
10
+ # https://mesonbuild.com/Python-module.html
10
11
py = import (' python' ).find_installation(pure : false )
11
12
12
- # Add dependencies
13
- cython = find_program (' cython' , required : true )
13
+ # Compilers
14
+ cc = meson .get_compiler(' c' )
15
+ cython = meson .get_compiler(' cython' )
14
16
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' ,
23
22
'''
23
+ from os.path import relpath
24
24
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', '')
51
26
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 )
70
37
71
38
# Run code generation step
72
39
code_gen_result = run_command (
73
40
py.full_path(), ' -c' ,
74
41
'''
75
42
import sys
76
43
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")
85
47
''' ,
86
- check : false
48
+ check : true
87
49
)
88
50
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' )
0 commit comments