Skip to content

Commit 97c4e9d

Browse files
bonzinieli-schwartz
authored andcommitted
ninjabackend: pass objects to doctests
Fix my misunderstanding of the code before commit aede231 ("ninjabackend: pass objects to generate_rust_target from non-Rust sources", 2025-07-29). Object files were added by get_rust_compiler_deps_and_args() to both the main target and the doctest command lines: objs, od = self.flatten_object_list(target) for o in objs: args.append(f'-Clink-arg={o}') deps.append(o) therefore they now need to be passed as the final argument of get_rust_compiler_deps_and_args() for both command lines as well. Failure to do so causes problems building doctests when the main target has objects as well. Add a regression test as well. Fixes: #14897 Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 14b7632 commit 97c4e9d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,10 +2208,9 @@ def generate_rust_target(self, target: build.BuildTarget, target_name: str, obj_
22082208
rustdoc = rustc.get_rustdoc(self.environment)
22092209
args = rustdoc.get_exe_args()
22102210
args += self.get_rust_compiler_args(target.doctests.target, rustdoc, target.rust_crate_type)
2211-
# There can be no non-Rust objects: the doctests are gathered from Rust
2212-
# sources and the tests are linked with the target (which is where the
2213-
# obj_list was linked into)
2214-
_, _, deps_args = self.get_rust_compiler_deps_and_args(target.doctests.target, rustdoc, [])
2211+
# Rustc does not add files in the obj_list to Rust rlibs,
2212+
# and is added by Meson to all of the dependencies, including here.
2213+
_, _, deps_args = self.get_rust_compiler_deps_and_args(target.doctests.target, rustdoc, obj_list)
22152214
args += deps_args
22162215
target.doctests.cmd_args = args.to_native() + [main_rust_file] + target.doctests.cmd_args
22172216

test cases/rust/27 objects/lib1-dylib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ pub extern "C" fn c_func()
1313
{
1414
unsafe { from_lib1(); }
1515
}
16+
17+
/// ```
18+
/// use lib12::rust_func;
19+
/// rust_func();
20+
/// ```
21+
pub fn rust_func()
22+
{
23+
unsafe { from_lib1(); }
24+
}

test cases/rust/27 objects/meson.build

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
project('staticlib group', 'c', 'rust', meson_version: '>=1.8.0')
1+
project('staticlib group', 'c', 'rust', meson_version: '>=1.8.0',
2+
default_options: ['rust_std=2021'])
23

34
lib1 = static_library('lib1', 'lib1.c')
45
dep1 = declare_dependency(objects: lib1.extract_all_objects(recursive: false))
@@ -26,3 +27,9 @@ lib12 = shared_library('dylib2objs_as_dep', 'lib1-dylib.rs',
2627
dependencies: dep2,
2728
rust_abi: 'c')
2829
executable('dylib_as_dep', 'main.rs', link_with: lib12)
30+
31+
lib12_rlib = static_library('lib12', 'lib1-dylib.rs',
32+
dependencies: dep2)
33+
34+
rust = import('rust')
35+
rust.doctest('rlib with dep', lib12_rlib)

0 commit comments

Comments
 (0)