modules/rust: Add a keyword argument to pass extra args to the rust compiler

This may be necessary to, for example, stop rustc complaining about
unused functions
pull/11902/head
Dylan Baker 2 years ago
parent c5b16ab8b9
commit 5d16bd5308
  1. 4
      docs/markdown/Rust-module.md
  2. 3
      docs/markdown/snippets/rust_bindegen_extra_args.md
  3. 11
      mesonbuild/modules/rust.py
  4. 10
      test cases/rust/9 unit tests/meson.build
  5. 7
      test cases/rust/9 unit tests/test3.rs

@ -18,7 +18,7 @@ like Meson, rather than Meson work more like rust.
## Functions
### test(name: string, target: library | executable, dependencies: []Dependency, link_with: []targets)
### test(name: string, target: library | executable, dependencies: []Dependency, link_with: []targets, rust_args: []string)
This function creates a new rust unittest target from an existing rust
based target, which may be a library or executable. It does this by
@ -35,6 +35,8 @@ argument.
*(since 1.2.0)* the link_with argument can be used to pass additional build
targets to link with
*(since 1.2.0)* the `rust_args` keyword argument can be ussed to pass extra
arguments to the Rust compiler.
### bindgen(*, input: string | BuildTarget | [](string | BuildTarget), output: string, include_directories: [](include_directories | string), c_args: []string, args: []string, dependencies: []Dependency)

@ -0,0 +1,3 @@
## rust.bindgen allows passing extra arguments to rustc
This may be necessary to pass extra `cfg`s or to change warning levels.

@ -40,6 +40,7 @@ if T.TYPE_CHECKING:
dependencies: T.List[T.Union[Dependency, ExternalLibrary]]
is_parallel: bool
link_with: T.List[LibTypes]
rust_args: T.List[str]
class FuncBindgen(TypedDict):
@ -71,6 +72,13 @@ class RustModule(ExtensionModule):
*TEST_KWS,
DEPENDENCIES_KW,
LINK_WITH_KW.evolve(since='1.2.0'),
KwargInfo(
'rust_args',
ContainerTypeInfo(list, str),
listify=True,
default=[],
since='1.2.0',
),
KwargInfo('is_parallel', bool, default=False),
)
def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: FuncTest) -> ModuleReturnValue:
@ -148,7 +156,8 @@ class RustModule(ExtensionModule):
new_target_kwargs = base_target.kwargs.copy()
# Don't mutate the shallow copied list, instead replace it with a new
# one
new_target_kwargs['rust_args'] = new_target_kwargs.get('rust_args', []) + ['--test']
new_target_kwargs['rust_args'] = \
new_target_kwargs.get('rust_args', []) + kwargs['rust_args'] + ['--test']
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']

@ -31,17 +31,17 @@ test(
suite : ['foo'],
)
exe = executable('rust_exe', ['test2.rs', 'test.rs'])
exe = executable('rust_exe', ['test2.rs', 'test.rs'], build_by_default : false)
rust = import('unstable-rust')
rust.test('rust_test_from_exe', exe, should_fail : true)
lib = static_library('rust_static', ['test.rs'])
lib = static_library('rust_static', ['test.rs'], build_by_default : false)
rust.test('rust_test_from_static', lib, args: ['--skip', 'test_add_intentional_fail'])
lib = shared_library('rust_shared', ['test.rs'])
lib = shared_library('rust_shared', ['test.rs'], build_by_default : false)
rust.test('rust_test_from_shared', lib, args: ['--skip', 'test_add_intentional_fail'])
helper = static_library('helper', 'helper.rs')
lib = static_library('rust_link_with', 'test3.rs')
rust.test('rust_test_link_with', lib, link_with : helper)
lib = static_library('rust_link_with', 'test3.rs', build_by_default : false)
rust.test('rust_test_link_with', lib, link_with : helper, rust_args : ['--cfg', 'broken="false"'])

@ -8,6 +8,13 @@ mod tests {
use super::*;
// This is an intentinally broken test that should be turned off by extra rust arguments
#[cfg(not(broken = "false"))]
#[test]
fn test_broken() {
assert_eq!(0, 5);
}
#[test]
fn test_add_sub() {
let x = helper::subtract(6, 5);

Loading…
Cancel
Save