summaryrefslogtreecommitdiff
path: root/src/rust/meson.build
blob: 51775ab2aa4870eeabb5dcc4b9059c8f99744589 (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
subdir('.cargo')
subdir('tor_rust')

tor_rust_deps = []

# manually copied from rustc --print native-static-libs
if host_machine.system() == 'windows'
  foreach lib : ['advapi32', 'ws2_32', 'userenv', 'shell32', 'gcc_eh', 'pthread']
    tor_rust_deps += cc.find_library(lib)
  endforeach
endif

tor_rust = declare_dependency(
  # work around meson declare_dependency dependencies bug
  link_args: ['-Wl,--whole-archive', libtor_rust.full_path(), '-Wl,--no-whole-archive'],
  sources: [libtor_rust, 'asan.c'],
  dependencies: tor_rust_deps
)

cargo_test_args = ['test', '--all', '--all-features',
  '--manifest-path', meson.source_root() + '/src/rust/Cargo.toml']

if get_option('buildtype') == 'release'
  cargo_test_args += '--release'
endif

if get_option('fragile_hardening')
  warning('skipping doctests because rustdoc is not compatible with ASAN (https://github.com/rust-lang/rust/issues/43031)')
  cargo_test_args += '--lib'
endif

cargo_test_env = environment()

# used in build.rs
cargo_test_env.set('abs_top_builddir', meson.build_root())
cargo_test_env.set('ASAN_OPTIONS', 'detect_odr_violation=1')

# https://github.com/rust-lang/cargo/issues/3366
if host_machine.system() == 'windows'
  ld_library_path_var = 'PATH'
elif host_machine.system() == 'darwin'
  ld_library_path_var = 'DYLD_LIBRARY_PATH'
else
  ld_library_path_var = 'LD_LIBRARY_PATH'
endif
cargo_test_env.prepend(ld_library_path_var, meson.build_root() + '/src/or')

test('test_rust', cargo, args: cargo_test_args, env: cargo_test_env,
  workdir: meson.build_root() + '/src/rust',
  timeout: 300)