aboutsummaryrefslogtreecommitdiff
path: root/test cases/rust/4 polyglot/meson.build
blob: b2fd8f913a61457cfdbf31fa1ccba323d3048c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
project('rust and c polyglot executable', 'c', 'rust')

if host_machine.system() == 'darwin'
  error('MESON_SKIP_TEST: does not work right on macos, please fix!')
endif

cc = meson.get_compiler('c')

# Test all combinations of crate and target types.
# - 'clib' gets translated to `rust_abi: 'c'` instead.
# - '' gets translated to no kwargs.
allowed_map = {
  'static_library': ['rlib', 'staticlib', 'lib', 'clib', ''],
  'shared_library': ['dylib', 'cdylib', 'lib', 'proc-macro', 'clib', ''],
  'both_libraries': ['lib', 'clib', ''],
}
foreach crate_type : ['lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro', 'clib', '', 'invalid']
  foreach target_type, allowed : allowed_map
    name = f'stuff_@crate_type@_@target_type@'.underscorify()
    src = crate_type == 'proc-macro' ? 'proc.rs' : 'stuff.rs'
    if crate_type not in allowed
      # Note: in the both_libraries() case it is possible that the static part
      # is still being built because the shared part raised an error but we
      # don't rollback correctly.
      testcase expect_error('(Crate type .* invalid for .*)|(.*must be one of.*not invalid)', how: 're')
        build_target(name, src,
          target_type: target_type,
          rust_crate_type: crate_type,
          install: true)
      endtestcase
      continue
    endif
    rust_kwargs = {}
    if crate_type == 'clib'
      rust_kwargs = {'rust_abi': 'c'}
    elif crate_type != ''
      rust_kwargs = {'rust_crate_type': crate_type}
    endif
    l = build_target(name, src,
      target_type: target_type,
      kwargs: rust_kwargs,
      install: true)
    if crate_type in ['cdylib', 'staticlib', 'clib']
      e = executable(f'prog-@name@', 'prog.c',
        link_with: l,
        rust_dependency_map: {name: 'stuff'},
        install: true)
      test(f'polyglottest-@name@', e)
    else
      testcase expect_error('Try to link Rust ABI library .*', how: 're')
        executable(f'prog-@name@', 'prog.c', link_with: l)
      endtestcase
    endif
  endforeach
endforeach