xref: /aosp_15_r20/external/mesa3d/src/compiler/rust/meson.build (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1# Copyright © 2024 Igalia S.L.
2# SPDX-License-Identifier: MIT
3
4_compiler_rs_sources = [
5  'as_slice.rs',
6  'bitset.rs',
7  'cfg.rs',
8  'nir.rs',
9]
10
11bindgen_version = find_program('bindgen').version()
12
13if bindgen_version == 'unknown'
14  error('Failed to detect bindgen version. If you are using bindgen 0.69.0, ' +
15        'please either update to 0.69.1 or downgrade to 0.68.1. You can ' +
16        'install the latest version for your user with ' +
17        '`cargo install bindgen-cli`.')
18endif
19
20if bindgen_version.version_compare('< 0.65')
21  error('NAK requires bindgen 0.65 or newer. If your distribution does not ' +
22        'ship a recent enough version, you can install the latest version ' +
23        'for your user with `cargo install bindgen-cli`.')
24endif
25
26_compiler_binding_types = [
27  'exec_list',
28  'exec_node',
29  'float_controls',
30  'gc_ctx',
31  'gl_access_qualifier',
32  'gl_frag_result',
33  'gl_interp_mode',
34  'gl_shader_stage',
35  'gl_subgroup_size',
36  'gl_system_value',
37  'gl_tess_spacing',
38  'gl_varying_slot',
39  'gl_vert_attrib',
40  'glsl_type',
41  'nir_.*',
42  'mesa_scope',
43  'mesa_prim',
44  'pipe_shader_type',
45  'shader_info',
46  'tess_primitive_mode',
47]
48
49_compiler_bindgen_args = [
50  '--raw-line', '#![allow(non_camel_case_types)]',
51  '--raw-line', '#![allow(non_snake_case)]',
52  '--raw-line', '#![allow(non_upper_case_globals)]',
53  '--allowlist-var', 'nir_.*_infos',
54  '--allowlist-function', 'glsl_.*',
55  '--allowlist-function', '_mesa_shader_stage_to_string',
56  '--allowlist-function', 'nir_.*',
57  '--no-prepend-enum-name',
58]
59
60foreach type : _compiler_binding_types
61  _compiler_bindgen_args += ['--allowlist-type', type]
62endforeach
63
64_compiler_bindings_rs = rust.bindgen(
65  input : ['bindings.h'],
66  output : 'bindings.rs',
67  c_args : [
68    pre_args,
69  ],
70  args : _compiler_bindgen_args,
71  dependencies : [
72    idep_nir_headers,
73  ],
74)
75
76compiler_rs_bindgen_blocklist = []
77foreach type : _compiler_binding_types
78  compiler_rs_bindgen_blocklist += ['--blocklist-type', type]
79endforeach
80
81_compiler_rs_sources = structured_sources([
82  # lib.rs has to go first
83  'lib.rs',
84  _compiler_bindings_rs,
85  _compiler_rs_sources,
86])
87
88_libcompiler_rs = static_library(
89  'compiler',
90  _compiler_rs_sources,
91  gnu_symbol_visibility : 'hidden',
92  rust_abi : 'rust',
93)
94
95idep_compiler_rs = declare_dependency(
96  link_with : _libcompiler_rs,
97)
98
99dep_syn = dependency('syn',
100  version : '>= 2.0.15',
101  fallback : ['syn', 'dep_syn'],
102  required : true,
103)
104
105_libcompiler_proc_rs = static_library(
106  'compiler_proc',
107  'proc/lib.rs',
108  gnu_symbol_visibility : 'hidden',
109  dependencies : [dep_syn],
110  rust_abi : 'rust',
111  native : true,
112)
113
114idep_compiler_proc_rs = declare_dependency(
115  link_with : _libcompiler_proc_rs,
116)
117