Debian Codegraph @

test cases/rust/4 polyglot/meson.build

raw
1 project('rust and c polyglot executable', 'c', 'rust')
2
3 cc = meson.get_compiler('c')
4
5 # Test all combinations of crate and target types.
6 # - 'clib' gets translated to `rust_abi: 'c'` instead.
7 # - '' gets translated to no kwargs.
8 allowed_map = {
9 'static_library': ['rlib', 'staticlib', 'lib', 'clib', ''],
10 'shared_library': ['dylib', 'cdylib', 'lib', 'proc-macro', 'clib', ''],
11 'both_libraries': ['lib', 'clib', ''],
12 }
13 foreach crate_type : ['lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro', 'clib', '', 'invalid']
14 foreach target_type, allowed : allowed_map
15 name = f'stuff_@crate_type@_@target_type@'.underscorify()
16 src = crate_type == 'proc-macro' ? 'proc.rs' : 'stuff.rs'
17 if crate_type not in allowed
18 # Note: in the both_libraries() case it is possible that the static part
19 # is still being built because the shared part raised an error but we
20 # don't rollback correctly.
21 testcase expect_error('(Crate type .* must be .*)|(.*must be one of.*not invalid)', how: 're')
22 build_target(name, src,
23 target_type: target_type,
24 rust_crate_type: crate_type,
25 install: true)
26 endtestcase
27 continue
28 endif
29 rust_kwargs = {}
30 if crate_type == 'clib'
31 rust_kwargs = {'rust_abi': 'c'}
32 elif crate_type != ''
33 rust_kwargs = {'rust_crate_type': crate_type}
34 endif
35 l = build_target(name, src,
36 target_type: target_type,
37 kwargs: rust_kwargs,
38 install: true)
39 if crate_type in ['cdylib', 'staticlib', 'clib']
40 e = executable(f'prog-@name@', 'prog.c',
41 link_with: l,
42 rust_dependency_map: {name: 'stuff'},
43 install: true)
44 test(f'polyglottest-@name@', e)
45 else
46 testcase expect_error('Try to link Rust ABI library .*', how: 're')
47 executable(f'prog-@name@', 'prog.c', link_with: l)
48 endtestcase
49 endif
50 endforeach
51 endforeach