Skip to content

Commit f918fee

Browse files
committed
rust: add link_whole to rust.test and rust.doctest
QEMU needs it in its integration tests (in order to run global constructors), and therefore in rust.doctest too. With this change I could do: # Rust executables do not support objects, so add an intermediate step. rust_qemu_api_objs = static_library( 'rust_qemu_api_objs', objects: [libqom.extract_all_objects(recursive: false), libhwcore.extract_all_objects(recursive: false)]) rust.doctest('rust-qemu-api-doc', _qemu_api_rs, dependencies: [qemu_api, qemu_api_macros], link_with: libqemuutil, link_whole: [rust_qemu_api_objs], suite: ['doc', 'rust']) followed by "meson test --suite doc". For completeness, add it to rust.test as well. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent ec5bdce commit f918fee

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/markdown/Rust-module.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ It also takes the following keyword arguments:
3838

3939
- `dependencies`: a list of test-only Dependencies
4040
- `link_with`: a list of additional build Targets to link with (*since 1.2.0*)
41+
- `link_whole`: a list of additional build Targets to link with in their entirety (*since 1.8.0*)
4142
- `rust_args`: a list of extra arguments passed to the Rust compiler (*since 1.2.0*)
4243

4344
This function also accepts all of the keyword arguments accepted by the
@@ -59,6 +60,7 @@ It also takes the following keyword arguments:
5960

6061
- `dependencies`: a list of test-only Dependencies
6162
- `link_with`: a list of additional build Targets to link with
63+
- `link_whole`: a list of additional build Targets to link with in their entirety
6264
- `rust_args`: a list of extra arguments passed to the Rust compiler
6365

6466
The target is linked automatically into the doctests.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## `rust.test` now supports `link_whole`
2+
3+
The `test` function in the `rust` module now supports the `link_whole`
4+
keyword argument in addition to `link_with` and `dependencies`.

mesonbuild/modules/rust.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
CustomTarget, InvalidArguments, Jar, StructuredSources, SharedLibrary, StaticLibrary)
1616
from ..compilers.compilers import are_asserts_disabled_for_subproject, lang_suffixes
1717
from ..interpreter.type_checking import (
18-
DEPENDENCIES_KW, LINK_WITH_KW, SHARED_LIB_KWS, TEST_KWS, TEST_KWS_NO_ARGS, OUTPUT_KW,
19-
INCLUDE_DIRECTORIES, SOURCES_VARARGS, NoneType, in_set_validator
18+
DEPENDENCIES_KW, LINK_WITH_KW, LINK_WHOLE_KW, SHARED_LIB_KWS, TEST_KWS, TEST_KWS_NO_ARGS,
19+
OUTPUT_KW, INCLUDE_DIRECTORIES, SOURCES_VARARGS, NoneType, in_set_validator
2020
)
2121
from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs, permittedKwargs
2222
from ..interpreter.interpreterobjects import Doctest
@@ -44,6 +44,7 @@ class FuncRustTest(_kwargs.BaseTest, T.Generic[ArgsType]):
4444
dependencies: T.List[T.Union[Dependency, ExternalLibrary]]
4545
is_parallel: bool
4646
link_with: T.List[LibTypes]
47+
link_whole: T.List[LibTypes]
4748
rust_args: T.List[str]
4849

4950
FuncTest = FuncRustTest[_kwargs.TestArgs]
@@ -147,6 +148,8 @@ def test_common(self, funcname: str, state: ModuleState, args: T.Tuple[str, Buil
147148
"""
148149
if any(isinstance(t, Jar) for t in kwargs.get('link_with', [])):
149150
raise InvalidArguments('Rust tests cannot link with Jar targets')
151+
if any(isinstance(t, Jar) for t in kwargs.get('link_whole', [])):
152+
raise InvalidArguments('Rust tests cannot link with Jar targets')
150153

151154
name = args[0]
152155
base_target: BuildTarget = args[1]
@@ -181,6 +184,7 @@ def test_common(self, funcname: str, state: ModuleState, args: T.Tuple[str, Buil
181184
new_target_kwargs['install'] = False
182185
new_target_kwargs['dependencies'] = new_target_kwargs.get('dependencies', []) + kwargs['dependencies']
183186
new_target_kwargs['link_with'] = new_target_kwargs.get('link_with', []) + kwargs['link_with']
187+
new_target_kwargs['link_whole'] = new_target_kwargs.get('link_whole', []) + kwargs['link_whole']
184188
del new_target_kwargs['rust_crate_type']
185189
for kw in ['pic', 'prelink', 'rust_abi', 'version', 'soversion', 'darwin_versions']:
186190
if kw in new_target_kwargs:
@@ -207,6 +211,7 @@ def test_common(self, funcname: str, state: ModuleState, args: T.Tuple[str, Buil
207211
*TEST_KWS,
208212
DEPENDENCIES_KW,
209213
LINK_WITH_KW.evolve(since='1.2.0'),
214+
LINK_WHOLE_KW.evolve(since='1.8.0'),
210215
*RUST_TEST_KWS,
211216
)
212217
def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: FuncTest) -> ModuleReturnValue:
@@ -224,6 +229,7 @@ def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: Func
224229
*TEST_KWS_NO_ARGS,
225230
DEPENDENCIES_KW,
226231
LINK_WITH_KW,
232+
LINK_WHOLE_KW,
227233
*RUST_TEST_KWS,
228234
KwargInfo(
229235
'args',

0 commit comments

Comments
 (0)