Debian Codegraph @

test cases/rust/12 bindgen/meson.build

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright © 2021-2024 Intel Corporation
3
4 project(
5 'rustmod bindgen',
6 ['c', 'cpp', 'rust'],
7 meson_version : '>= 0.63',
8 default_options : ['cpp_std=c++17'])
9
10 prog_bindgen = find_program('bindgen', required : false)
11 if not prog_bindgen.found()
12 error('MESON_SKIP_TEST bindgen not found')
13 endif
14
15 cc_id = meson.get_compiler('c').get_id()
16 compiler_specific_args = []
17 if cc_id == 'gcc'
18 compiler_specific_args = ['-fipa-pta']
19 elif cc_id == 'msvc'
20 compiler_specific_args = ['/fp:fast']
21 endif
22
23 add_project_arguments(['-DPROJECT_ARG', compiler_specific_args], language : 'c')
24 add_global_arguments(['-DGLOBAL_ARG', compiler_specific_args], language : 'c')
25
26 # This seems to happen on windows when libclang.dll is not in path or is not
27 # valid. We must try to process a header file for this to work.
28 #
29 # See https://github.com/rust-lang/rust-bindgen/issues/1797
30 result = run_command(prog_bindgen, 'include/other.h', check: false)
31 if result.returncode() != 0
32 error('MESON_SKIP_TEST bindgen does not seem to work')
33 endif
34
35 rust = import('unstable-rust')
36
37 # Check version, this case is obviously impossible
38 testcase expect_error('Program \'bindgen\' not found or not executable')
39 rust.bindgen(input : 'include/other.h', output : 'other.rs', bindgen_version : ['< 0.1', '> 10000'])
40 endtestcase
41
42 # This is to test the include_directories argument to bindgen
43 inc = include_directories('include')
44
45 c_lib = static_library('clib', 'src/source.c', include_directories : inc)
46
47 gen = rust.bindgen(
48 input : 'src/header.h',
49 output : 'header.rs',
50 include_directories : 'include',
51 )
52
53 # see: https://github.com/mesonbuild/meson/issues/8160
54 f = configure_file(
55 input : 'src/main.rs',
56 output : 'main.rs',
57 copy : true,
58 )
59
60 rust_bin = executable(
61 'rust_bin',
62 [f, gen],
63 link_with : c_lib,
64 )
65
66 test('main', rust_bin)
67
68 # Test a generated header
69 subdir('gen')
70 gen_rs = rust.bindgen(
71 input : [gen_h, gen2_h],
72 output : 'gen.rs',
73 )
74
75 f = configure_file(
76 input : 'src/main2.rs',
77 output : 'main2.rs',
78 copy : true,
79 )
80
81 rust_bin2 = executable(
82 'rust_bin2',
83 [f, gen_rs],
84 link_with : c_lib,
85 )
86
87 test('generated header', rust_bin2)
88
89 if prog_bindgen.version().version_compare('>= 0.65')
90 # Test generating a static inline wrapper
91 gen3 = rust.bindgen(
92 input : 'src/header3.h',
93 output : 'header3.rs',
94 output_inline_wrapper : 'header3.c',
95 include_directories : inc,
96 )
97 c_inline_wrapper = static_library('c_wrapper', gen3[1], include_directories: inc)
98
99 f = configure_file(
100 input : 'src/main3.rs',
101 output : 'main3.rs',
102 copy : true,
103 )
104
105 rust_bin3 = executable(
106 'rust_bin3',
107 [f, gen3[0]],
108 link_with : [
109 c_lib,
110 c_inline_wrapper,
111 ],
112 )
113
114 test('static inline wrapper', rust_bin3)
115 endif
116
117 subdir('sub')
118 subdir('dependencies')
119
120 gp = rust.bindgen(
121 input : 'src/global-project.h',
122 output : 'global-project.rs',
123 )
124
125 gp_lib = static_library('gp_lib', 'src/global.c')
126
127 gp_exe = executable(
128 'gp_exe',
129 structured_sources(['src/global.rs', gp]),
130 link_with : gp_lib,
131 )
132
133 test('global and project arguments', gp_exe)
134
135 cpp_lib_sources = files('src/impl.cpp')
136 cpp_lib = both_libraries('cpplib', cpp_lib_sources)
137 cpp_lib_static = static_library('cpplib-static', cpp_lib_sources)
138
139 cpp_bind = rust.bindgen(
140 input : 'src/header.hpp',
141 output : 'generated-cpp.rs',
142 )
143
144 # test passing various kinds of objects as dependencies
145
146 rust.bindgen(
147 input : ['src/header2.hpp', cpp_lib.get_static_lib()],
148 output : 'generated-cpp-static.rs')
149 rust.bindgen(
150 input : ['src/header3.hpp', cpp_lib_static.extract_objects(cpp_lib_sources)],
151 output : 'generated-cpp-objs.rs')
152 rust.bindgen(
153 input : ['src/header4.hpp', cpp_lib],
154 output : 'generated-cpp-both.rs')
155
156 cpp_exe = executable(
157 'cpp_exe',
158 structured_sources(['src/cpp.rs', cpp_bind]),
159 link_with : cpp_lib_static,
160 )
161 test('cpp', cpp_exe)