Skip to content

Commit a19df7d

Browse files
bonzinieli-schwartz
authored andcommitted
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 <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 39d5ffc commit a19df7d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,8 +2008,8 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
20082008
# Rustc replaces - with _. spaces or dots are not allowed, so we replace them with underscores
20092009
args += ['--crate-name', target.name.replace('-', '_').replace(' ', '_').replace('.', '_')]
20102010
depfile = os.path.join(self.get_target_private_dir(target), target.name + '.d')
2011-
args += ['--emit', f'dep-info={depfile}']
2012-
args += ['--emit', f'link'={target_name}']
2011+
args += rustc.get_dependency_gen_args(target_name, depfile)
2012+
args += rustc.get_output_args(target_name)
20132013
args += ['-C', 'metadata=' + target.get_id()]
20142014
args += target.get_extra_args('rust')
20152015

mesonbuild/compilers/rust.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ def _native_static_libs(self, work_dir: str, source_name: str) -> None:
170170
self.native_static_libs = [i for i in match.group(1).split() if i not in exclude]
171171

172172
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
173-
return ['--dep-info', outfile]
173+
return ['--emit', f'dep-info={outfile}']
174+
175+
def get_output_args(self, outputname: str) -> T.List[str]:
176+
return ['--emit', f'link={outputname}']
174177

175178
@functools.lru_cache(maxsize=None)
176179
def get_sysroot(self) -> str:
@@ -222,9 +225,6 @@ def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
222225

223226
return parameter_list
224227

225-
def get_output_args(self, outputname: str) -> T.List[str]:
226-
return ['-o', outputname]
227-
228228
@classmethod
229229
def use_linker_args(cls, linker: str, version: str) -> T.List[str]:
230230
return ['-C', f'linker={linker}']
@@ -324,3 +324,21 @@ class ClippyRustCompiler(RustCompiler):
324324
"""
325325

326326
id = 'clippy-driver rustc'
327+
328+
329+
class RustdocTestCompiler(RustCompiler):
330+
331+
"""We invoke Rustdoc to run doctests. Some of the flags
332+
are different from rustc and some (e.g. --emit link) are
333+
ignored."""
334+
335+
id = 'rustdoc --test'
336+
337+
def get_debug_args(self, is_debug: bool) -> T.List[str]:
338+
return []
339+
340+
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
341+
return []
342+
343+
def get_output_args(self, outputname: str) -> T.List[str]:
344+
return []

0 commit comments

Comments
 (0)