1# Copyright © 2022 Collabora Ltd 2# SPDX-License-Identifier: MIT 3prog_cbindgen = find_program( 4 'cbindgen', 5 required : true, 6 native : true, 7 version : '>= 0.25' 8) 9 10dep_paste = dependency('paste', 11 version : '>= 1.0.14', 12 fallback : ['paste', 'dep_paste'], 13 required : true, 14) 15 16_nil_format_table = custom_target( 17 'nil_format_table', 18 input : files('nil_format_table_gen.py', 'nil_formats.csv'), 19 output : ['nil_format_table.h', 'nil_format_table.c'], 20 depends: u_format_gen_h, 21 command : [ 22 prog_python, '@INPUT0@', '--csv', '@INPUT1@', 23 '--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@', 24 ], 25) 26 27_libnil_format_table = static_library( 28 'libnil_format_table', 29 _nil_format_table, 30 include_directories : [inc_include, inc_src], 31 dependencies : [idep_nvidia_headers, idep_mesautil], 32 gnu_symbol_visibility: 'hidden', 33) 34 35_libnil_deps = [ 36 dep_paste, 37 idep_bitview_rs, 38 idep_nvidia_headers_rs, 39] 40 41_libnil_rust_args = [ 42 '-Aclippy::identity_op', 43 '-Aclippy::len_zero', 44 '-Aclippy::manual_range_contains', 45 # normally this is a good one, but we use it where the "better" code is worse 46 '-Aclippy::needless_range_loop', 47 '-Aclippy::redundant_field_names', 48 '-Aclippy::upper_case_acronyms', 49 '-Aclippy::vec_box', 50 '-Aclippy::write_with_newline', 51 '-Anon_snake_case', 52] 53 54_nil_bindings_rs = rust.bindgen( 55 input: ['nil_bindings.h', _nil_format_table], 56 output: 'nil_bindings.rs', 57 c_args: [ 58 pre_args, 59 ], 60 include_directories : [inc_include, inc_src, include_directories('.')], 61 args: [ 62 '--raw-line', '#![allow(non_camel_case_types)]', 63 '--raw-line', '#![allow(non_snake_case)]', 64 '--raw-line', '#![allow(non_upper_case_globals)]', 65 '--allowlist-function', 'util_format_description', 66 '--allowlist-function', 'util_format_get_blocksize', 67 '--allowlist-function', 'util_format_is_compressed', 68 '--allowlist-function', 'util_format_is_pure_integer', 69 '--allowlist-function', 'util_format_is_srgb', 70 '--allowlist-function', 'drm_format_mod_block_linear_2D', 71 '--allowlist-function', 'drm_mod_is_nvidia', 72 '--allowlist-type', 'nil_format_support_flags', 73 '--allowlist-type', 'nv_device_info', 74 '--allowlist-type', 'nv_device_type', 75 '--allowlist-type', 'pipe_format', 76 '--allowlist-type', 'pipe_swizzle', 77 '--allowlist-var', 'nil_format_table', 78 '--allowlist-var', 'drm_format_mod_invalid', 79 '--allowlist-var', 'drm_format_mod_linear', 80 '--no-prepend-enum-name', 81 ], 82 dependencies: _libnil_deps, 83) 84 85_libnil_rs_bindings = static_library( 86 'nil_rs_bindings', 87 _nil_bindings_rs, 88 gnu_symbol_visibility: 'hidden', 89 rust_abi: 'rust', 90) 91 92_libnil = static_library( 93 'libnil', 94 files('lib.rs'), 95 gnu_symbol_visibility: 'hidden', 96 rust_abi: 'c', 97 rust_args: _libnil_rust_args, 98 link_with: [_libnil_format_table, _libnil_rs_bindings], 99 dependencies: _libnil_deps, 100) 101 102_nil_h = custom_target( 103 'nil_h', 104 input : [files('cbindgen.toml'), 'lib.rs'], 105 output : ['nil.h'], 106 command : [ 107 prog_cbindgen, '-q', '--config', '@INPUT0@', '--lang', 'c', 108 '--output', '@OUTPUT0@', '--depfile', '@DEPFILE@', 109 '--', '@INPUT1@', 110 ], 111 depfile : 'nil.h.d', 112) 113 114idep_nil = declare_dependency( 115 include_directories : include_directories('.'), 116 link_with : _libnil, 117 sources : [_nil_h], 118) 119