• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright ©
2# SPDX-License-Identifier: MIT
3
4libmesa_rust_util_files = files(
5  'util/lib.rs',
6  'util/assert.rs',
7  'util/bitset.rs',
8  'util/feature.rs',
9  'util/properties.rs',
10  'util/ptr.rs',
11  'util/string.rs',
12)
13
14libmesa_rust_files = files(
15  'mesa/lib.rs',
16  'mesa/compiler.rs',
17  'mesa/compiler/clc.rs',
18  'mesa/compiler/clc/spirv.rs',
19  'mesa/compiler/nir.rs',
20  'mesa/pipe.rs',
21  'mesa/pipe/context.rs',
22  'mesa/pipe/device.rs',
23  'mesa/pipe/fence.rs',
24  'mesa/pipe/screen.rs',
25  'mesa/pipe/transfer.rs',
26  'mesa/util.rs',
27  'mesa/util/disk_cache.rs',
28)
29
30rusticl_proc_macros_files = files(
31  'proc/lib.rs',
32)
33
34rusticl_files = files(
35  'lib.rs',
36  'api.rs',
37  'api/context.rs',
38  'api/device.rs',
39  'api/event.rs',
40  'api/icd.rs',
41  'api/kernel.rs',
42  'api/memory.rs',
43  'api/platform.rs',
44  'api/program.rs',
45  'api/queue.rs',
46  'api/types.rs',
47  'api/util.rs',
48  'core.rs',
49  'core/context.rs',
50  'core/device.rs',
51  'core/format.rs',
52  'core/kernel.rs',
53  'core/memory.rs',
54  'core/platform.rs',
55  'core/program.rs',
56  'core/queue.rs',
57  'core/util.rs',
58  'core/version.rs',
59  'core/gl.rs',
60)
61
62rusticl_args = [
63  # we want unsafe blocks inside unsafe functions
64  '-Dunsafe_op_in_unsafe_fn',
65  # we error on all clippy warnings unless they are disabled
66  '-Dclippy::all',
67  # we want to add asserts in control flow
68  '-Aclippy::assertions_on_constants',
69  # warns on Arc<_> as keys
70  '-Aclippy::mutable_key_type',
71  '-Aclippy::not_unsafe_ptr_arg_deref',
72  # dunno, kind of looks nicier being explicit
73  '-Aclippy::redundant_field_names',
74  '-Aclippy::too_many_arguments',
75  '-Aclippy::type_complexity',
76]
77
78rusticl_drivers_enable = get_option('gallium-rusticl-enable-drivers')
79foreach driver : rusticl_drivers_enable
80  rusticl_args += [
81    '--cfg', 'rusticl_enable_' + driver,
82  ]
83endforeach
84
85if with_platform_x11
86  rusticl_args += [
87    '--cfg', 'glx',
88  ]
89endif
90
91rusticl_gen_args = [
92  # can't do anything about it anyway
93  '-Aclippy::all',
94  '-Aimproper_ctypes',
95  # Some bindgen versions assume `unsafe_op_in_unsafe_fn`
96  '-Aunused_unsafe',
97  '-Anon_camel_case_types',
98  '-Anon_snake_case',
99  '-Anon_upper_case_globals',
100]
101
102rusticl_bindgen_args = [
103  '--no-convert-floats',
104  '--default-enum-style', 'rust',
105  '--with-derive-partialeq',
106  '--with-derive-eq',
107  '--with-derive-partialord',
108  '--with-derive-ord',
109  '--with-derive-hash',
110  '--with-derive-default',
111  '--anon-fields-prefix', 'anon_',
112]
113
114rusticl_bindgen_c_args = [
115  '-fno-builtin-malloc',
116]
117
118cl_c_args = [
119  '-DCL_USE_DEPRECATED_OPENCL_1_0_APIS',
120  '-DCL_USE_DEPRECATED_OPENCL_1_1_APIS',
121  '-DCL_USE_DEPRECATED_OPENCL_1_2_APIS',
122  '-DCL_USE_DEPRECATED_OPENCL_2_0_APIS',
123  '-DCL_USE_DEPRECATED_OPENCL_2_1_APIS',
124  '-DCL_USE_DEPRECATED_OPENCL_2_2_APIS',
125  '-DCL_TARGET_OPENCL_VERSION=300',
126]
127
128rusticl_opencl_bindings_rs = rust.bindgen(
129  input : [
130    'rusticl_opencl_bindings.h',
131    opencl_headers,
132  ],
133  output : 'rusticl_opencl_bindings.rs',
134  include_directories : [
135    inc_include,
136  ],
137  dependencies : [
138    dep_x11,
139  ],
140  c_args : [
141    rusticl_bindgen_c_args,
142    pre_args,
143    cl_c_args,
144  ],
145  args : [
146    rusticl_bindgen_args,
147    '--disable-header-comment',
148    '--ignore-functions',
149    # needed because bindgen adds *mut void fields...
150    '--raw-line', 'unsafe impl std::marker::Sync for _cl_icd_dispatch {}',
151    # _cl_image_desc contains a pointer to _cl_mem
152    '--raw-line', 'unsafe impl std::marker::Send for _cl_image_desc {}',
153    '--raw-line', 'unsafe impl std::marker::Sync for _cl_image_desc {}',
154    '--allowlist-type', 'cl_.*',
155    '--blocklist-type', '(__)?cl_.*[2348(16)]',
156    '--allowlist-type', 'cl.*_fn',
157    '--allowlist-var', 'CL_.*',
158    # needed for gl_sharing extension
159    '--allowlist-var', 'GL_.*',
160    '--allowlist-var', 'MESA_GLINTEROP_.*',
161    '--allowlist-type', 'PFNEGLGETPROCADDRESSPROC',
162    '--allowlist-type', 'PFNGLXGETPROCADDRESSPROC',
163    '--allowlist-type', 'PFNMESAGLINTEROP.*',
164    # some info types need to be strongly typed so we can implement various get_infos
165    '--new-type-alias-deref', 'cl_(mem|image|pipe|gl_texture)_info',
166    '--new-type-alias-deref', 'cl_kernel_(arg|work_group)_info',
167    '--new-type-alias-deref', 'cl_(event|profiling)_info',
168    # turn gl interop enums into constfields so we can compare with rust types
169    '--constified-enum', 'MESA_GLINTEROP_.*',
170  ],
171)
172
173rusticl_opencl_gen = static_library(
174  'rusticl_opencl_gen',
175  rusticl_opencl_bindings_rs,
176  gnu_symbol_visibility : 'hidden',
177  rust_abi : 'rust',
178  rust_args : [
179    rusticl_gen_args,
180  ],
181)
182
183rusticl_llvm_bindings_rs = rust.bindgen(
184  input : 'rusticl_llvm_bindings.hpp',
185  output : 'rusticl_llvm_bindings.rs',
186  c_args : [
187    rusticl_bindgen_c_args,
188    pre_args,
189  ],
190  dependencies : [
191    dep_clang,
192    dep_llvm,
193    dep_llvmspirvlib,
194  ],
195  args : [
196    # we want to limit what to generate bindings for
197    '--generate', 'constructors,functions,types',
198    # and all types will be opaque
199    '--opaque-type', '.*',
200    # LLVM/Clang/Translator stuff, only used for build-id
201    # also only use functions from very basic header files, otherwise bindgen might crash :')
202    '--allowlist-function', 'clang::getClangFullVersion',
203    '--allowlist-function', 'llvm::LLVMContext::LLVMContext',
204    '--allowlist-function', 'llvm::writeSpirv',
205  ],
206)
207
208rusticl_llvm_gen = static_library(
209  'rusticl_llvm_gen',
210  rusticl_llvm_bindings_rs,
211  gnu_symbol_visibility : 'hidden',
212  rust_abi : 'rust',
213  rust_args : [
214    rusticl_gen_args,
215  ],
216)
217
218rusticl_libc_bindings_rs = rust.bindgen(
219  input : 'rusticl_libc_bindings.h',
220  output : 'rusticl_libc_bindings.rs',
221  dependencies: [
222    dep_valgrind,
223  ],
224  c_args : [
225    rusticl_bindgen_c_args,
226    pre_args,
227  ],
228  args : [
229    rusticl_bindgen_args,
230    '--allowlist-function',     'close',
231    '--allowlist-function',     'dlsym',
232    '--allowlist-function',     'free',
233    '--allowlist-function',     'malloc',
234  ]
235)
236
237_idep_mesa_bindings = declare_dependency(
238  sources : spirv_info,
239)
240
241rusticl_mesa_bindings = rust.bindgen(
242  input : 'rusticl_mesa_bindings.h',
243  output : 'rusticl_mesa_bindings.rs',
244  output_inline_wrapper : 'rusticl_mesa_bindings.c',
245  include_directories : [
246    inc_gallium,
247    inc_gallium_aux,
248    inc_include,
249    inc_src,
250  ],
251  dependencies: [
252    _idep_mesa_bindings,
253    idep_nir_headers,
254    dep_valgrind,
255  ],
256  c_args : [
257    rusticl_bindgen_c_args,
258    pre_args,
259  ],
260  args : [
261    rusticl_bindgen_args,
262
263    # we want that for mesa
264    '--use-array-pointers-in-arguments',
265
266    # mesa utils
267    '--allowlist-function',     'blob_.*',
268    '--allowlist-function',     'disk_cache_.*',
269    '--allowlist-type',         'float_controls',
270    '--allowlist-function',     'mesa_.*',
271    '--allowlist-var',          'OS_.*',
272    '--allowlist-function',     'rz?alloc_.*',
273    '--allowlist-function',     'SHA1.*',
274    '--allowlist-var',          'SHA1_.*',
275    '--allowlist-function',     'u_.*',
276    '--allowlist-function',     'util_format_.*',
277
278    # CL API
279    '--allowlist-type',         'cl_sampler_.*_mode',
280    '--constified-enum-module', 'cl_sampler_.*_mode',
281
282    # clc
283    '--allowlist-function',     'clc_.*',
284    '--allowlist-type',         'clc_kernel_arg_access_qualifier',
285    '--bitfield-enum',          'clc_kernel_arg_access_qualifier',
286    '--allowlist-type',         'clc_kernel_arg_type_qualifier',
287    '--bitfield-enum',          'clc_kernel_arg_type_qualifier',
288
289    # gl
290    '--allowlist-type',         'gl_access_qualifier',
291    '--bitfield-enum',          'gl_access_qualifier',
292    '--allowlist-function',     'glsl_.*',
293
294    # nir and spirv
295    '--allowlist-function',     'nir_.*',
296    '--allowlist-var',          'nir_debug',
297    '--allowlist-var',          'NIR_DEBUG_.*',
298    '--bitfield-enum',          'nir_lower_int64_options',
299    '--bitfield-enum',          'nir_opt_if_options',
300    '--bitfield-enum',          'nir_variable_mode',
301    '--allowlist-function',     'should_.*_nir',
302    '--allowlist-function',     'spirv_.*',
303
304    # gallium
305    '--allowlist-function',     'pipe_.*',
306    '--allowlist-var',          'PIPE_.*',
307    '--allowlist-type',         'pipe_endian',
308    '--bitfield-enum',          'pipe_map_flags',
309    '--allowlist-type',         'pipe_query_type',
310    '--constified-enum-module', 'pipe_query_type',
311    '--allowlist-type',         'pipe_resource_usage',
312    '--bitfield-enum',          'pipe_resource_usage',
313    '--allowlist-type',         'pipe_tex_filter',
314    '--constified-enum-module', 'pipe_tex_filter',
315    '--allowlist-type',         'pipe_tex_wrap',
316    '--constified-enum-module', 'pipe_tex_wrap',
317
318    # rusticl C functions
319    '--allowlist-function',     'rusticl_.*',
320    '--allowlist-function',     'std(err|out)_ptr',
321
322    # winsys
323    '--allowlist-var',          'WINSYS_HANDLE_TYPE_.*',
324  ],
325)
326
327rusticl_c = static_library(
328  'rusticl_c',
329  [
330    'rusticl_nir.c',
331    'rusticl_nir.h',
332    'rusticl_system_bindings.c',
333    'rusticl_system_bindings.h',
334    rusticl_mesa_bindings[1],
335    'rusticl_mesa_bindings.h',
336    sha1_h,
337  ],
338  gnu_symbol_visibility : 'hidden',
339  include_directories : [
340    fs.relative_to(meson.project_build_root(), meson.current_source_dir()),
341    inc_gallium,
342    inc_gallium_aux,
343    inc_include,
344    inc_nir,
345    inc_src,
346  ],
347  c_args : [
348    pre_args,
349    cl_c_args,
350    cc.get_supported_arguments('-Wno-missing-prototypes'),
351  ],
352  dependencies: [
353    idep_nir_headers,
354    dep_valgrind,
355  ],
356)
357
358idep_rusticl_gen = declare_dependency(
359  sources: [
360    rusticl_opencl_bindings_rs,
361  ],
362)
363
364libmesa_rust_gen = static_library(
365  'mesa_rust_gen',
366  rusticl_mesa_bindings[0],
367  gnu_symbol_visibility : 'hidden',
368  link_with: [
369    libgallium,
370  ],
371  dependencies: [
372    idep_mesaclc,
373  ],
374  rust_abi : 'rust',
375  rust_args : [
376    rusticl_gen_args,
377  ],
378)
379
380libc_rust_gen = static_library(
381  'libc_rust_gen',
382  rusticl_libc_bindings_rs,
383  gnu_symbol_visibility : 'hidden',
384  rust_abi : 'rust',
385  rust_args : [
386    rusticl_gen_args,
387  ],
388)
389
390libmesa_rust_util = static_library(
391  'mesa_rust_util',
392  [libmesa_rust_util_files],
393  gnu_symbol_visibility : 'hidden',
394  rust_abi : 'rust',
395  rust_args : [
396    rusticl_args,
397  ],
398)
399
400libmesa_rust = static_library(
401  'mesa_rust',
402  [libmesa_rust_files],
403  gnu_symbol_visibility : 'hidden',
404  rust_abi : 'rust',
405  rust_args : [
406    rusticl_args,
407  ],
408  link_with : [
409    libc_rust_gen,
410    libmesa_rust_gen,
411    libmesa_rust_util,
412    rusticl_c,
413  ]
414)
415
416rusticl_proc_macros = rust.proc_macro(
417  'rusticl_proc_macros',
418  [rusticl_proc_macros_files],
419  rust_args : [
420    rusticl_args,
421  ],
422)
423
424librusticl = static_library(
425  'rusticl',
426  [rusticl_files],
427  gnu_symbol_visibility : 'hidden',
428  rust_abi : 'c',
429  rust_args : [
430    rusticl_args,
431  ],
432  link_with : [
433    libc_rust_gen,
434    libmesa_rust,
435    libmesa_rust_gen,
436    libmesa_rust_util,
437    rusticl_llvm_gen,
438    rusticl_opencl_gen,
439    rusticl_proc_macros,
440  ],
441  dependencies : [
442    idep_rusticl_gen,
443  ],
444)
445