• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  'memstream.rs',
9  'nir_instr_printer.rs',
10  'nir.rs',
11  'smallvec.rs',
12]
13
14_compiler_binding_types = [
15  'exec_list',
16  'exec_node',
17  'float_controls',
18  'gc_ctx',
19  'gl_access_qualifier',
20  'gl_frag_result',
21  'gl_interp_mode',
22  'gl_shader_stage',
23  'gl_subgroup_size',
24  'gl_system_value',
25  'gl_tess_spacing',
26  'gl_varying_slot',
27  'gl_vert_attrib',
28  'glsl_type',
29  'nir_.*',
30  'mesa_scope',
31  'mesa_prim',
32  'pipe_shader_type',
33  'shader_info',
34  'tess_primitive_mode',
35]
36
37_compiler_bindgen_args = [
38  '--raw-line', '#![allow(non_camel_case_types)]',
39  '--raw-line', '#![allow(non_snake_case)]',
40  '--raw-line', '#![allow(non_upper_case_globals)]',
41  '--allowlist-var', 'nir_.*_infos',
42  '--allowlist-var', 'rust_.*',
43  '--allowlist-function', 'glsl_.*',
44  '--allowlist-function', '_mesa_shader_stage_to_string',
45  '--allowlist-function', 'nir_.*',
46  '--allowlist-function', 'compiler_rs.*',
47  '--allowlist-function', 'u_memstream.*',
48  '--allowlist-type', 'u_memstream',
49  '--no-prepend-enum-name',
50]
51
52foreach type : _compiler_binding_types
53  _compiler_bindgen_args += ['--allowlist-type', type]
54endforeach
55
56_libcompiler_c_sources = files('rust_helpers.c')
57
58_libcompiler_c = static_library(
59  'compiler_c_helpers',
60  [_libcompiler_c_sources],
61  include_directories : [inc_include, inc_util],
62  c_args : [no_override_init_args],
63  gnu_symbol_visibility : 'hidden',
64)
65
66_idep_libcompiler_c = declare_dependency(
67  include_directories: include_directories('.'),
68  link_with : _libcompiler_c,
69)
70
71_compiler_bindings_rs = rust.bindgen(
72  input : ['bindings.h'],
73  output : 'bindings.rs',
74  c_args : [
75    pre_args,
76  ],
77  args : _compiler_bindgen_args,
78  dependencies : [
79    idep_nir_headers,
80    idep_mesautil,
81  ],
82)
83
84compiler_rs_bindgen_blocklist = []
85foreach type : _compiler_binding_types
86  compiler_rs_bindgen_blocklist += ['--blocklist-type', type]
87endforeach
88
89_compiler_rs_sources = structured_sources([
90  # lib.rs has to go first
91  'lib.rs',
92  _compiler_bindings_rs,
93  _compiler_rs_sources,
94])
95
96_libcompiler_rs = static_library(
97  'compiler',
98  _compiler_rs_sources,
99  gnu_symbol_visibility : 'hidden',
100  rust_abi : 'rust',
101  dependencies: [_idep_libcompiler_c],
102)
103
104# TODO: Linking Rust executables (such as unit tests) doesn't play nicely
105# with the sanitizers because meson doesn't know to pass -fsanitize to the
106# Rust linker.  See also https://github.com/mesonbuild/meson/issues/11741
107if with_tests and get_option('b_sanitize') == 'none'
108  rust.test(
109    'compiler_test',
110    _libcompiler_rs,
111    suite : ['compiler', 'rs'],
112    dependencies : [
113      idep_mesautil.partial_dependency(link_args : true, links : true),
114    ],
115    # This is needed to ensure we link against glibc
116    # See also https://gitlab.freedesktop.org/mesa/mesa/-/issues/11632
117    rust_args: ['-C', 'default-linker-libraries'],
118  )
119endif
120
121idep_compiler_rs = declare_dependency(
122  link_with : _libcompiler_rs,
123)
124
125dep_syn = dependency('syn',
126  version : '>= 2.0.15',
127  fallback : ['syn', 'dep_syn'],
128  required : true,
129)
130
131_libcompiler_proc_rs = static_library(
132  'compiler_proc',
133  'proc/lib.rs',
134  gnu_symbol_visibility : 'hidden',
135  dependencies : [dep_syn],
136  rust_abi : 'rust',
137  native : true,
138)
139
140idep_compiler_proc_rs = declare_dependency(
141  link_with : _libcompiler_proc_rs,
142)
143