Skip to content

Commit

Permalink
rust: add link_whole to rust.test and rust.doctest
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bonzini committed Dec 19, 2024
1 parent c7f3350 commit 52e6b16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/markdown/Rust-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ It also takes the following keyword arguments:

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

This function also accepts all of the keyword arguments accepted by the
Expand All @@ -57,6 +58,7 @@ It also takes the following keyword arguments:

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

The target is linked automatically into the doctests.
Expand Down
4 changes: 4 additions & 0 deletions docs/markdown/snippets/rust-test-link-whole.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## `rust.test` now supports `link_whole`

The `test` function in the `rust` module now supports the `link_whole`
keyword argument in addition to `link_with` and `dependencies`.
10 changes: 8 additions & 2 deletions mesonbuild/modules/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from ..compilers.compilers import are_asserts_disabled, lang_suffixes
from ..compilers.rust import RustCompiler
from ..interpreter.type_checking import (
DEPENDENCIES_KW, LINK_WITH_KW, SHARED_LIB_KWS, TEST_KWS, TEST_KWS_NO_ARGS, OUTPUT_KW,
INCLUDE_DIRECTORIES, SOURCES_VARARGS, NoneType, in_set_validator
DEPENDENCIES_KW, LINK_WITH_KW, LINK_WHOLE_KW, SHARED_LIB_KWS, TEST_KWS, TEST_KWS_NO_ARGS,
OUTPUT_KW, INCLUDE_DIRECTORIES, SOURCES_VARARGS, NoneType, in_set_validator
)
from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs, permittedKwargs
from ..interpreter.interpreterobjects import Doctest
Expand All @@ -44,6 +44,7 @@ class FuncRustTest(_kwargs.BaseTest, T.Generic[ArgsType]):
dependencies: T.List[T.Union[Dependency, ExternalLibrary]]
is_parallel: bool
link_with: T.List[LibTypes]
link_whole: T.List[LibTypes]
rust_args: T.List[str]

FuncTest = FuncRustTest[_kwargs.TestArgs]
Expand Down Expand Up @@ -140,6 +141,8 @@ def test_common(self, funcname: str, state: ModuleState, args: T.Tuple[str, Buil
"""
if any(isinstance(t, Jar) for t in kwargs.get('link_with', [])):
raise InvalidArguments('Rust tests cannot link with Jar targets')
if any(isinstance(t, Jar) for t in kwargs.get('link_whole', [])):
raise InvalidArguments('Rust tests cannot link with Jar targets')

name = args[0]
base_target: BuildTarget = args[1]
Expand Down Expand Up @@ -174,6 +177,7 @@ def test_common(self, funcname: str, state: ModuleState, args: T.Tuple[str, Buil
new_target_kwargs['install'] = False
new_target_kwargs['dependencies'] = new_target_kwargs.get('dependencies', []) + kwargs['dependencies']
new_target_kwargs['link_with'] = new_target_kwargs.get('link_with', []) + kwargs['link_with']
new_target_kwargs['link_whole'] = new_target_kwargs.get('link_whole', []) + kwargs['link_whole']
del new_target_kwargs['rust_crate_type']
for kw in ['pic', 'prelink', 'rust_abi', 'version', 'soversion', 'darwin_versions']:
if kw in new_target_kwargs:
Expand All @@ -200,6 +204,7 @@ def test_common(self, funcname: str, state: ModuleState, args: T.Tuple[str, Buil
*TEST_KWS,
DEPENDENCIES_KW,
LINK_WITH_KW.evolve(since='1.2.0'),
LINK_WHOLE_KW.evolve(since='1.7.0'),
*RUST_TEST_KWS,
)
def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: FuncTest) -> ModuleReturnValue:
Expand All @@ -217,6 +222,7 @@ def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: Func
*TEST_KWS_NO_ARGS,
DEPENDENCIES_KW,
LINK_WITH_KW,
LINK_WHOLE_KW,
*RUST_TEST_KWS,
KwargInfo(
'args',
Expand Down

0 comments on commit 52e6b16

Please sign in to comment.