1# Copyright © 2022 Collabora, Ltd. 2# SPDX-License-Identifier: MIT 3if meson.version().version_compare('< 1.3.0') 4 error('NVK requires meson 1.3.0 or newer') 5endif 6 7add_languages('rust', required: true) 8rust = import('rust') 9 10rc = meson.get_compiler('rust') 11if rc.version().version_compare('< 1.73.0') 12 error('NAK requires Rust 1.73.0') 13endif 14 15nak_rust_args = [ 16 '-Aclippy::identity_op', 17 '-Aclippy::len_zero', 18 '-Aclippy::manual_range_contains', 19 # normally this is a good one, but we use it where the "better" code is worse 20 '-Aclippy::needless_range_loop', 21 '-Aclippy::redundant_field_names', 22 '-Aclippy::upper_case_acronyms', 23 '-Aclippy::vec_box', 24 '-Aclippy::write_with_newline', 25 '-Anon_snake_case', 26] 27 28dep_syn = dependency('syn', 29 version : '>= 2.0.15', 30 fallback : ['syn', 'dep_syn'], 31 required : true, 32) 33 34libnak_c_files = files( 35 'nak.h', 36 'nak_nir.c', 37 'nak_nir_add_barriers.c', 38 'nak_nir_lower_scan_reduce.c', 39 'nak_nir_lower_tex.c', 40 'nak_nir_lower_vtg_io.c', 41 'nak_nir_lower_gs_intrinsics.c', 42 'nak_memstream.c', 43) 44 45_libbitview_rs = static_library( 46 'bitview', 47 files('bitview/lib.rs'), 48 gnu_symbol_visibility : 'hidden', 49 rust_abi : 'rust', 50 rust_args : nak_rust_args, 51) 52 53libnak_deps = [ 54 idep_mesautil, 55 idep_nir_headers, 56 idep_nvidia_headers, 57] 58 59nak_bindings_rs = rust.bindgen( 60 input : ['nak_bindings.h'], 61 output : 'nak_bindings.rs', 62 c_args : [ 63 pre_args, 64 ], 65 args : [ 66 '--raw-line', '#![allow(non_camel_case_types)]', 67 '--raw-line', '#![allow(non_snake_case)]', 68 '--raw-line', '#![allow(non_upper_case_globals)]', 69 '--allowlist-type', 'exec_list', 70 '--allowlist-type', 'exec_node', 71 '--allowlist-type', 'float_controls', 72 '--allowlist-type', 'gl_access_qualifier', 73 '--allowlist-type', 'gl_frag_result', 74 '--allowlist-type', 'gl_interp_mode', 75 '--allowlist-type', 'gl_shader_stage', 76 '--allowlist-type', 'gl_system_value', 77 '--allowlist-type', 'gl_tess_spacing', 78 '--allowlist-type', 'gl_varying_slot', 79 '--allowlist-type', 'gl_vert_attrib', 80 '--allowlist-type', 'nak_.*', 81 '--allowlist-type', 'nir_.*', 82 '--allowlist-type', 'mesa_scope', 83 '--allowlist-type', 'mesa_prim', 84 '--allowlist-type', 'tess_primitive_mode', 85 '--allowlist-var', 'nir_.*_infos', 86 '--allowlist-function', '_mesa_shader_stage_to_string', 87 '--allowlist-function', 'nak_.*', 88 '--allowlist-function', 'nir_.*', 89 '--allowlist-function', 'glsl_.*', 90 '--no-prepend-enum-name', 91 ], 92 dependencies : libnak_deps, 93) 94 95libnak_bindings_gen = static_library( 96 'nak_bindings', 97 nak_bindings_rs, 98 gnu_symbol_visibility : 'hidden', 99 rust_abi : 'rust', 100) 101 102_libnak_ir_proc_rs = rust.proc_macro( 103 'nak_ir_proc', 104 files('nak/ir_proc.rs'), 105 dependencies : [dep_syn], 106) 107 108_libnak_rs = static_library( 109 'nak_rs', 110 files('nak/lib.rs'), 111 gnu_symbol_visibility : 'hidden', 112 rust_abi : 'c', 113 rust_args : nak_rust_args, 114 link_with: [_libbitview_rs, libnak_bindings_gen, _libnak_ir_proc_rs], 115) 116 117nak_nir_algebraic_c = custom_target( 118 'nak_nir_algebraic.c', 119 input : 'nak_nir_algebraic.py', 120 output : 'nak_nir_algebraic.c', 121 command : [ 122 prog_python, '@INPUT@', 123 '-p', dir_compiler_nir, 124 '--out', '@OUTPUT@', 125 ], 126 depend_files : nir_algebraic_depends, 127) 128 129_libnak = static_library( 130 'nak', 131 [libnak_c_files, nak_nir_algebraic_c], 132 include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium], 133 dependencies : libnak_deps, 134 link_with : [_libnak_rs], 135 c_args : [no_override_init_args], 136 gnu_symbol_visibility : 'hidden', 137) 138 139if with_tools.contains('nouveau') 140 executable( 141 'nvfuzz', 142 files('nvfuzz/main.rs'), 143 rust_crate_type : 'bin', 144 link_with: [_libbitview_rs], 145 install : true 146 ) 147endif 148 149idep_nak = declare_dependency( 150 include_directories : include_directories('.'), 151 link_with : _libnak, 152) 153