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