Aluode/PerceptionLabPortable
0
1fs = import('fs')
2
3cython_args = []
4
5# Platform detection
6is_windows = host_machine.system() == 'windows'
7is_mingw = is_windows and cc.get_id() == 'gcc'
8
9# Adapted from Scipy. mingw is untested and not officially supported. If you
10# ever bump into issues when trying to compile for mingw, please open an issue
11# in the scikit-learn issue tracker
12if is_mingw
13 # For mingw-w64, link statically against the UCRT.
14 gcc_link_args = ['-lucrt', '-static']
15 add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
16 # Force gcc to float64 long doubles for compatibility with MSVC
17 # builds, for C only.
18 add_project_arguments('-mlong-double-64', language: 'c')
19endif
20
21# Only check build dependencies version when not cross-compiling, as running
22# Python interpreter can be tricky in cross-compilation settings. For more
23# details, see https://docs.scipy.org/doc/scipy/building/cross_compilation.html
24if not meson.is_cross_build()
25 if not py.version().version_compare('>=3.10')
26 error('scikit-learn requires Python>=3.10, got ' + py.version() + ' instead')
27 endif
28
29 cython_min_version = run_command(py, ['_min_dependencies.py', 'cython'], check: true).stdout().strip()
30 if not cython.version().version_compare('>=' + cython_min_version)
31 error('scikit-learn requires Cython>=' + cython_min_version + ', got ' + cython.version() + ' instead')
32 endif
33
34 numpy_version = run_command(py,
35 ['-c', 'import numpy; print(numpy.__version__)'], check: true).stdout().strip()
36 numpy_min_version = run_command(py, ['_min_dependencies.py', 'numpy'], check: true).stdout().strip()
37 if not numpy_version.version_compare('>=' + numpy_min_version)
38 error('scikit-learn requires numpy>=' + numpy_min_version + ', got ' + numpy_version + ' instead')
39 endif
40
41 scipy_version = run_command(py,
42 ['-c', 'import scipy; print(scipy.__version__)'], check: true).stdout().strip()
43 scipy_min_version = run_command(py, ['_min_dependencies.py', 'scipy'], check: true).stdout().strip()
44 if not scipy_version.version_compare('>=' + scipy_min_version)
45 error('scikit-learn requires scipy>=' + scipy_min_version + ', got ' + scipy_version + ' instead')
46 endif
47
48 # meson-python is required only when going through pip. Using meson directly
49 # should not check meson-python version.
50 meson_python_version_command_result = run_command(py,
51 ['-c', 'import importlib.metadata; print(importlib.metadata.version("meson-python"))'], check: false)
52 meson_python_installed = meson_python_version_command_result.returncode() == 0
53 if meson_python_installed
54 meson_python_version = meson_python_version_command_result.stdout().strip()
55 meson_python_min_version = run_command(py, ['_min_dependencies.py', 'meson-python'], check: true).stdout().strip()
56 if not meson_python_version.version_compare('>=' + meson_python_min_version)
57 error('scikit-learn requires meson-python>=' + meson_python_min_version + ', got ' + meson_python_version + ' instead')
58 endif
59 endif
60
61endif
62
63# Adapted from scipy, each project seems to have its own tweaks for this. One
64# day using dependency('numpy') will be a thing, see
65# https://github.com/mesonbuild/meson/issues/9598.
66# NumPy include directory - needed in all submodules
67# Relative paths are needed when for example a virtualenv is
68# placed inside the source tree; Meson rejects absolute paths to places inside
69# the source tree. The try-except is needed because when things are split
70# across drives on Windows, there is no relative path and an exception gets
71# raised. There may be other such cases, so add a catch-all and switch to
72# an absolute path.
73# For cross-compilation it is often not possible to run the Python interpreter
74# in order to retrieve numpy's include directory. It can be specified in the
75# cross file instead:
76# [properties]
77# numpy-include-dir = /abspath/to/host-pythons/site-packages/numpy/core/include
78#
79# This uses the path as is, and avoids running the interpreter.
80incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given')
81if incdir_numpy == 'not-given'
82 incdir_numpy = run_command(py,
83 [
84 '-c',
85 '''
86import os
87import numpy as np
88try:
89 incdir = os.path.relpath(np.get_include())
90except Exception:
91 incdir = np.get_include()
92print(incdir)
93'''
94 ],
95 check: true
96 ).stdout().strip()
97endif
98
99inc_np = include_directories(incdir_numpy)
100# Don't use the deprecated NumPy C API. Define this to a fixed version instead of
101# NPY_API_VERSION in order not to break compilation for released SciPy versions
102# when NumPy introduces a new deprecation.
103numpy_no_deprecated_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION']
104np_dep = declare_dependency(include_directories: inc_np, compile_args: numpy_no_deprecated_api)
105
106openmp_dep = dependency('OpenMP', language: 'c', required: false)
107
108if not openmp_dep.found()
109 warn_about_missing_openmp = true
110 # On Apple Clang avoid a misleading warning if compiler variables are set.
111 # See https://github.com/scikit-learn/scikit-learn/issues/28710 for more
112 # details. This may be removed if the OpenMP detection on Apple Clang improves,
113 # see https://github.com/mesonbuild/meson/issues/7435#issuecomment-2047585466.
114 if host_machine.system() == 'darwin' and cc.get_id() == 'clang'
115 compiler_env_vars_with_openmp = run_command(py,
116 [
117 '-c',
118 '''
119import os
120
121compiler_env_vars_to_check = ["CPPFLAGS", "CFLAGS", "CXXFLAGS"]
122
123compiler_env_vars_with_openmp = [
124 var for var in compiler_env_vars_to_check if "-fopenmp" in os.getenv(var, "")]
125print(compiler_env_vars_with_openmp)
126'''], check: true).stdout().strip()
127 warn_about_missing_openmp = compiler_env_vars_with_openmp == '[]'
128 endif
129 if warn_about_missing_openmp
130 warning(
131'''
132 ***********
133 * WARNING *
134 ***********
135
136It seems that scikit-learn cannot be built with OpenMP.
137
138- Make sure you have followed the installation instructions:
139
140 https://scikit-learn.org/dev/developers/advanced_installation.html
141
142- If your compiler supports OpenMP but you still see this
143 message, please submit a bug report at:
144
145 https://github.com/scikit-learn/scikit-learn/issues
146
147- The build will continue with OpenMP-based parallelism
148 disabled. Note however that some estimators will run in
149 sequential mode instead of leveraging thread-based
150 parallelism.
151
152 ***
153''')
154 else
155 warning(
156'''It looks like compiler environment variables were set to enable OpenMP support.
157Check the output of "import sklearn; sklearn.show_versions()" after the build
158to make sure that scikit-learn was actually built with OpenMP support.
159''')
160 endif
161endif
162
163# For now, we keep supporting SKLEARN_ENABLE_DEBUG_CYTHON_DIRECTIVES variable
164# (see how it is done in sklearn/_build_utils/__init__.py when building with
165# setuptools). Accessing environment variables in meson.build is discouraged,
166# so once we drop setuptools this functionality should be behind a meson option
167# or buildtype
168boundscheck = run_command(py,
169 [
170 '-c',
171 '''
172import os
173
174if os.environ.get("SKLEARN_ENABLE_DEBUG_CYTHON_DIRECTIVES", "0") != "0":
175 print(True)
176else:
177 print(False)
178 '''
179 ],
180 check: true
181 ).stdout().strip()
182
183cython_program = find_program(cython.cmd_array()[0])
184
185scikit_learn_cython_args = [
186 '-X language_level=3', '-X boundscheck=' + boundscheck, '-X wraparound=False',
187 '-X initializedcheck=False', '-X nonecheck=False', '-X cdivision=True',
188 '-X profile=False',
189 # Needed for cython imports across subpackages, e.g. cluster pyx that
190 # cimports metrics pxd
191 '--include-dir', meson.global_build_root(),
192]
193cython_args += scikit_learn_cython_args
194
195if cython.version().version_compare('>=3.1.0')
196 cython_shared_src = custom_target(
197 install: false,
198 output: '_cyutility.c',
199 command: [
200 cython_program, '-3', '--fast-fail',
201 '--generate-shared=' + meson.current_build_dir()/'_cyutility.c'
202 ],
203 )
204
205 py.extension_module('_cyutility',
206 cython_shared_src,
207 subdir: 'sklearn',
208 cython_args: cython_args,
209 install: true,
210 )
211
212 cython_args += ['--shared=sklearn._cyutility']
213endif
214
215cython_gen = generator(cython_program,
216 arguments : cython_args + ['@INPUT@', '--output-file', '@OUTPUT@'],
217 output : '@BASENAME@.c',
218)
219
220cython_gen_cpp = generator(cython_program,
221 arguments : cython_args + ['--cplus', '@INPUT@', '--output-file', '@OUTPUT@'],
222 output : '@BASENAME@.cpp',
223)
224
225# Write file in Meson build dir to be able to figure out from Python code
226# whether scikit-learn was built with Meson. Adapted from pandas
227# _version_meson.py.
228custom_target('write_built_with_meson_file',
229 output: '_built_with_meson.py',
230 command: [
231 py, '-c', 'with open("sklearn/_built_with_meson.py", "w") as f: f.write("")'
232 ],
233 install: true,
234 install_dir: py.get_install_dir() / 'sklearn'
235)
236
237extensions = ['_isotonic']
238
239py.extension_module(
240 '_isotonic',
241 cython_gen.process('_isotonic.pyx'),
242 cython_args: cython_args,
243 install: true,
244 subdir: 'sklearn',
245)
246
247# Need for Cython cimports across subpackages to work, i.e. avoid errors like
248# relative cimport from non-package directory is not allowed
249sklearn_root_cython_tree = [
250 fs.copyfile('__init__.py')
251]
252
253sklearn_dir = py.get_install_dir() / 'sklearn'
254
255# Subpackages are mostly in alphabetical order except to handle Cython
256# dependencies across subpackages
257subdir('__check_build')
258subdir('_loss')
259# utils needs to be early since plenty of other modules cimports utils .pxd
260subdir('utils')
261# metrics needs to be to be before cluster since cluster cimports metrics .pxd
262subdir('metrics')
263subdir('cluster')
264subdir('datasets')
265subdir('decomposition')
266subdir('ensemble')
267subdir('feature_extraction')
268subdir('linear_model')
269subdir('manifold')
270subdir('neighbors')
271subdir('preprocessing')
272subdir('svm')
273subdir('tree')
274 