ninjabackend: start adjusting for differences between rustc and rustdoc

Add functions to RustCompiler() to account for differences
between rustc and "rustdoc --test": rustdoc always generates
a binary, does not support -g, and does not need --emit.

Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pull/13013/merge
Paolo Bonzini 6 months ago committed by Eli Schwartz
parent 39d5ffc27f
commit a19df7da15
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 4
      mesonbuild/backend/ninjabackend.py
  2. 26
      mesonbuild/compilers/rust.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')

@ -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 []

Loading…
Cancel
Save