Skip to content

Commit

Permalink
ninjabackend: generate command line for rust doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
bonzini committed Dec 6, 2024
1 parent 43e61b0 commit e720e7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1963,14 +1963,14 @@ def generate_rust_sources(self, target: build.BuildTarget) -> T.Tuple[T.List[str

return orderdeps, main_rust_file

def get_rust_compiler_args(self, target: build.BuildTarget, rustc: Compiler,
def get_rust_compiler_args(self, target: build.BuildTarget, rustc: Compiler, src_crate_type: str,
depfile: T.Optional[str] = None) -> T.List[str]:
base_proxy = target.get_options()
# Compiler args for compiling this target
args = compilers.get_base_compile_args(base_proxy, rustc, self.environment)

target_name = self.get_target_filename(target)
args.extend(['--crate-type', target.rust_crate_type])
args.extend(['--crate-type', src_crate_type])

# If we're dynamically linking, add those arguments
if target.rust_crate_type in {'bin', 'dylib'}:
Expand Down Expand Up @@ -2125,7 +2125,7 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
args = rustc.compiler_args()

depfile = os.path.join(self.get_target_private_dir(target), target.name + '.d')
args += self.get_rust_compiler_args(target, rustc, depfile)
args += self.get_rust_compiler_args(target, rustc, target.rust_crate_type, depfile)

deps, project_deps, deps_args = self.get_rust_compiler_deps_and_args(target, rustc)
args += deps_args
Expand Down Expand Up @@ -2155,6 +2155,17 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
self.generate_shsym(target)
self.create_target_source_introspection(target, rustc, args, [main_rust_file], [])

if target.doctests:
from ..compilers.rust import RustCompiler
assert isinstance(rustc, RustCompiler)
assert target.doctests.target is not None
rustdoc = rustc.get_rustdoc(self.environment)
args = rustdoc.get_exe_args()
args += self.get_rust_compiler_args(target.doctests.target, rustdoc, target.rust_crate_type)
_, _, deps_args = self.get_rust_compiler_deps_and_args(target.doctests.target, rustdoc)
args += deps_args
target.doctests.cmd_args[0:0] = args.to_native() + [main_rust_file]

@staticmethod
def get_rule_suffix(for_machine: MachineChoice) -> str:
return PerMachine('_FOR_BUILD', '')[for_machine]
Expand Down
8 changes: 8 additions & 0 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ def get_rust_tool(self, name: str, env: Environment) -> T.List[str]:

return exelist + args

@functools.lru_cache(maxsize=None)
def get_rustdoc(self, env: 'Environment') -> T.Optional[RustdocTestCompiler]:
exelist = self.get_rust_tool('rustdoc', env)
if not exelist:
return None

return RustdocTestCompiler(exelist, self.version, self.for_machine,
self.is_cross, self.info, linker=self.linker)

class ClippyRustCompiler(RustCompiler):

Expand Down

0 comments on commit e720e7c

Please sign in to comment.