aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Rust-module.md4
-rw-r--r--docs/markdown/snippets/rust_bindegen_extra_args.md3
-rw-r--r--mesonbuild/modules/rust.py11
-rw-r--r--test cases/rust/9 unit tests/meson.build10
-rw-r--r--test cases/rust/9 unit tests/test3.rs7
5 files changed, 28 insertions, 7 deletions
diff --git a/docs/markdown/Rust-module.md b/docs/markdown/Rust-module.md
index 30a6345..d3891bf 100644
--- a/docs/markdown/Rust-module.md
+++ b/docs/markdown/Rust-module.md
@@ -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)
diff --git a/docs/markdown/snippets/rust_bindegen_extra_args.md b/docs/markdown/snippets/rust_bindegen_extra_args.md
new file mode 100644
index 0000000..209d0bc
--- /dev/null
+++ b/docs/markdown/snippets/rust_bindegen_extra_args.md
@@ -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.
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py
index faca9c0..92b0470 100644
--- a/mesonbuild/modules/rust.py
+++ b/mesonbuild/modules/rust.py
@@ -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']
diff --git a/test cases/rust/9 unit tests/meson.build b/test cases/rust/9 unit tests/meson.build
index 9096014..94cc400 100644
--- a/test cases/rust/9 unit tests/meson.build
+++ b/test cases/rust/9 unit tests/meson.build
@@ -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"'])
diff --git a/test cases/rust/9 unit tests/test3.rs b/test cases/rust/9 unit tests/test3.rs
index ccb5f98..6d538a0 100644
--- a/test cases/rust/9 unit tests/test3.rs
+++ b/test cases/rust/9 unit tests/test3.rs
@@ -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);