1# Copyright © 2022 Collabora, Ltd. 2# SPDX-License-Identifier: MIT 3nak_rust_args = [ 4 '-Aclippy::identity_op', 5 '-Aclippy::len_zero', 6 '-Aclippy::manual_range_contains', 7 # normally this is a good one, but we use it where the "better" code is worse 8 '-Aclippy::needless_range_loop', 9 '-Aclippy::redundant_field_names', 10 '-Aclippy::upper_case_acronyms', 11 '-Aclippy::vec_box', 12 '-Aclippy::write_with_newline', 13 # warns about public function might dereference a raw pointer, but nothing is 14 # actually public here 15 '-Aclippy::not_unsafe_ptr_arg_deref', 16 '-Anon_snake_case', 17] 18 19dep_paste = dependency('paste', 20 version : '>= 1.0.14', 21 fallback : ['paste', 'dep_paste'], 22 required : true, 23) 24 25libnak_c_files = files( 26 'nak.h', 27 'nak_nir.c', 28 'nak_nir_lower_cf.c', 29 'nak_nir_lower_fs_inputs.c', 30 'nak_nir_lower_gs_intrinsics.c', 31 'nak_nir_lower_non_uniform_ldcx.c', 32 'nak_nir_lower_scan_reduce.c', 33 'nak_nir_lower_tex.c', 34 'nak_nir_lower_vtg_io.c', 35 'nak_nir_split_64bit_conversions.c', 36 'nak_memstream.c', 37) 38 39_libacorn_rs = static_library( 40 'acorn', 41 files('acorn/lib.rs'), 42 gnu_symbol_visibility : 'hidden', 43 rust_abi : 'rust', 44 rust_args : nak_rust_args, 45) 46 47idep_acorn_rs = declare_dependency( 48 link_with : _libacorn_rs, 49) 50 51_libbitview_rs = static_library( 52 'bitview', 53 files('bitview/lib.rs'), 54 gnu_symbol_visibility : 'hidden', 55 rust_abi : 'rust', 56 rust_args : nak_rust_args, 57) 58 59idep_bitview_rs = declare_dependency( 60 link_with : _libbitview_rs, 61) 62 63libnak_deps = [ 64 idep_mesautil, 65 idep_nir_headers, 66 idep_nvidia_headers, 67] 68 69_nak_bindings_rs = rust.bindgen( 70 input : ['nak_bindings.h'], 71 output : 'nak_bindings.rs', 72 c_args : [ 73 pre_args, 74 ], 75 args : [ 76 compiler_rs_bindgen_blocklist, 77 '--raw-line', '#![allow(non_camel_case_types)]', 78 '--raw-line', '#![allow(non_snake_case)]', 79 '--raw-line', '#![allow(non_upper_case_globals)]', 80 '--raw-line', 'use compiler::bindings::*;', 81 '--allowlist-type', 'drm.*', 82 '--allowlist-type', 'nak_.*', 83 '--allowlist-type', 'nouveau_ws_.*', 84 '--allowlist-var', 'DRM_.*', 85 '--allowlist-var', 'NVIDIA_VENDOR_ID', 86 '--allowlist-function', 'drm.*', 87 '--allowlist-function', 'nak_.*', 88 '--allowlist-function', 'nouveau_ws_.*', 89 '--no-prepend-enum-name', 90 ], 91 dependencies : [ 92 dep_libdrm, 93 idep_nouveau_ws, 94 libnak_deps, 95 ], 96) 97 98_libnak_bindings_rs = static_library( 99 'nak_bindings', 100 _nak_bindings_rs, 101 gnu_symbol_visibility : 'hidden', 102 dependencies : [ 103 idep_compiler_rs, 104 ], 105 rust_abi : 'rust', 106) 107 108_libnak_ir_proc_rs = rust.proc_macro( 109 'nak_ir_proc', 110 files('nak/ir_proc.rs'), 111 dependencies : [idep_compiler_proc_rs], 112) 113 114_libnak_rs = static_library( 115 'nak_rs', 116 files('nak/lib.rs'), 117 gnu_symbol_visibility : 'hidden', 118 rust_abi : 'c', 119 rust_args : [ 120 nak_rust_args, 121 # Otherwise, rustc trips up on -pthread 122 '-Clink-arg=-Wno-unused-command-line-argument', 123 ], 124 dependencies : [ 125 dep_paste, 126 idep_compiler_rs, 127 idep_nvidia_headers_rs, 128 ], 129 link_with : [ 130 _libbitview_rs, 131 _libnak_bindings_rs, 132 _libnak_ir_proc_rs, 133 ], 134) 135 136# TODO: Linking Rust executables (such as unit tests) doesn't play nicely 137# with the sanitizers because meson doesn't know to pass -fsanitize to the 138# Rust linker. See also https://github.com/mesonbuild/meson/issues/11741 139if with_tests and get_option('b_sanitize') == 'none' 140 rust.test( 141 'nak', 142 _libnak_rs, 143 args : [ 144 # Don't run HW tests by default 145 '--skip', 'hw_tests::', 146 ], 147 suite : ['nouveau'], 148 dependencies : [ 149 dep_libdrm, 150 idep_nouveau_ws, 151 idep_compiler.partial_dependency(link_args : true, links : true), 152 idep_mesautil.partial_dependency(link_args : true, links : true), 153 idep_nv_push_rs, 154 ], 155 # This is needed to ensure we link against glibc 156 # See also https://gitlab.freedesktop.org/mesa/mesa/-/issues/11632 157 rust_args: ['-C', 'default-linker-libraries'], 158 link_with: [ 159 _libacorn_rs, 160 ], 161 ) 162endif 163 164nak_nir_algebraic_c = custom_target( 165 'nak_nir_algebraic.c', 166 input : 'nak_nir_algebraic.py', 167 output : 'nak_nir_algebraic.c', 168 command : [ 169 prog_python, '@INPUT@', 170 '-p', dir_compiler_nir, 171 '--out', '@OUTPUT@', 172 ], 173 depend_files : nir_algebraic_depends, 174) 175 176_libnak = static_library( 177 'nak', 178 [libnak_c_files, nak_nir_algebraic_c], 179 include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium], 180 dependencies : libnak_deps, 181 link_with : [_libnak_rs], 182 c_args : [no_override_init_args], 183 gnu_symbol_visibility : 'hidden', 184) 185 186idep_nak = declare_dependency( 187 include_directories : include_directories('.'), 188 link_with : _libnak, 189) 190