diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index cc3b9b3aa..73a809cd4 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2008,8 +2008,8 @@ class NinjaBackend(backends.Backend): # Rustc replaces - with _. spaces or dots are not allowed, so we replace them with underscores args += ['--crate-name', target.name.replace('-', '_').replace(' ', '_').replace('.', '_')] depfile = os.path.join(self.get_target_private_dir(target), target.name + '.d') - args += ['--emit', f'dep-info={depfile}'] - args += ['--emit', f'link'={target_name}'] + args += rustc.get_dependency_gen_args(target_name, depfile) + args += rustc.get_output_args(target_name) args += ['-C', 'metadata=' + target.get_id()] args += target.get_extra_args('rust') diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 09a1d24de..ee3155c88 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -170,7 +170,10 @@ class RustCompiler(Compiler): self.native_static_libs = [i for i in match.group(1).split() if i not in exclude] def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: - return ['--dep-info', outfile] + return ['--emit', f'dep-info={outfile}'] + + def get_output_args(self, outputname: str) -> T.List[str]: + return ['--emit', f'link={outputname}'] @functools.lru_cache(maxsize=None) def get_sysroot(self) -> str: @@ -222,9 +225,6 @@ class RustCompiler(Compiler): return parameter_list - def get_output_args(self, outputname: str) -> T.List[str]: - return ['-o', outputname] - @classmethod def use_linker_args(cls, linker: str, version: str) -> T.List[str]: return ['-C', f'linker={linker}'] @@ -324,3 +324,21 @@ class ClippyRustCompiler(RustCompiler): """ id = 'clippy-driver rustc' + + +class RustdocTestCompiler(RustCompiler): + + """We invoke Rustdoc to run doctests. Some of the flags + are different from rustc and some (e.g. --emit link) are + ignored.""" + + id = 'rustdoc --test' + + def get_debug_args(self, is_debug: bool) -> T.List[str]: + return [] + + def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: + return [] + + def get_output_args(self, outputname: str) -> T.List[str]: + return []