Skip to content

Commit bc039fa

Browse files
bonzinidcbaker
authored andcommitted
rust: let doctests pick objects from dependencies
If a depedency includes object files, they have to be added to the doctest. However, NinjaBackend was not running flatten_object_list on the doctest. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0bb366b commit bc039fa

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ..linkers import ArLikeLinker, RSPFileSyntax
3030
from ..mesonlib import (
3131
File, LibType, MachineChoice, MesonBugException, MesonException, OrderedSet, PerMachine,
32-
ProgressBar, quote_arg
32+
ProgressBar, quote_arg, unique_list
3333
)
3434
from ..mesonlib import get_compiler_for_source, has_path_sep, is_parent_path
3535
from ..options import OptionKey
@@ -2208,6 +2208,8 @@ 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+
o, _ = self.flatten_object_list(target.doctests.target)
2212+
obj_list = unique_list(obj_list + o)
22112213
# Rustc does not add files in the obj_list to Rust rlibs,
22122214
# and is added by Meson to all of the dependencies, including here.
22132215
_, _, deps_args = self.get_rust_compiler_deps_and_args(target.doctests.target, rustdoc, obj_list)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pub extern "C" fn c_func()
1515
}
1616

1717
/// ```
18-
/// use lib12::rust_func;
18+
/// #[cfg(not(nodep))] use lib12::rust_func;
19+
/// #[cfg(nodep)] use lib12_nodep::rust_func;
1920
/// rust_func();
2021
/// ```
2122
pub fn rust_func()

test cases/rust/27 objects/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ lib12_rlib = static_library('lib12', 'lib1-dylib.rs',
3333

3434
rust = import('rust')
3535
rust.doctest('rlib with dep', lib12_rlib)
36+
37+
lib12_rlib_nodep = static_library('lib12_nodep', 'lib1-dylib.rs')
38+
rust.doctest('rlib with dep in tests', lib12_rlib_nodep,
39+
rust_args: ['--cfg', 'nodep'],
40+
dependencies: dep2)

0 commit comments

Comments
 (0)