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