Description
Describe the bug
When b_sanitize
is set to address
, if use the Rust's module test method to generate a test from a Rust rlib
target, linking would fail because of missing all symbols from the asan library.
With Cargo, I can use build.rs to inject a link command cargo:rustc-link-lib=asan
based on an environment variable passed from meson.build. But with rust.test
, I tried to use an external dependency with only a link_args: '-lasan'
and got an exception.
Traceback (most recent call last):
File "/home/user/.local/lib/python3.8/site-packages/mesonbuild/mesonmain.py", line 271, in run
return msetup.run(['--reconfigure'] + args[2:])
File "/home/user/.local/lib/python3.8/site-packages/mesonbuild/msetup.py", line 310, in run
app.generate()
File "/home/user/.local/lib/python3.8/site-packages/mesonbuild/msetup.py", line 187, in generate
self._generate(env)
File "/home/user/.local/lib/python3.8/site-packages/mesonbuild/msetup.py", line 251, in _generate
intr.backend.generate()
File "/home/user/.local/lib/python3.8/site-packages/mesonbuild/backend/ninjabackend.py", line 615, in generate
self.generate_target(t)
File "/home/user/.local/lib/python3.8/site-packages/mesonbuild/backend/ninjabackend.py", line 824, in generate_target
self.generate_rust_target(target)
File "/home/user/.local/lib/python3.8/site-packages/mesonbuild/backend/ninjabackend.py", line 1990, in generate_rust_target
_type = 'static' if e.static else 'dylib'
AttributeError: 'InternalDependency' object has no attribute 'static'
To Reproduce
- Create a Rust library with
rust-crate-type
asrlib
and generate some unit tests. - Import
rust
module and userust.test()
to convert the rlib to a meson test. - Enable sanitizer with
meson setup builddir -Db_sanitize=address
- meson test would fail because of missing symbols from
asan
.
Now declare an external dependency with:
dep_asan = declare_dependency(link_args: '-lasan')
And add the dependency to the dependency list of the test target. For example:
rust = import('rust')
rust.test('myrlib', myrlib, dependencies: [dep_asan])
Run meson setup again and got the backtrace.
Expected behavior
There should be some way to allow Rust test to link with some extra libraries.
system parameters
Meson version: 1.0.2
Python: 3.8