summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-11-20 13:42:14 +0100
committerEli Schwartz <eschwartz93@gmail.com>2025-02-03 20:01:37 -0500
commita19df7da15848b7b01dfe3cf8f88211529b9143b (patch)
tree149cc00436c972a2bb4ffd96d93c152ec63d3cf6
parent39d5ffc27fe0dae50b0be10ed23cf54e05a6c38b (diff)
downloadmeson-a19df7da15848b7b01dfe3cf8f88211529b9143b.tar.gz
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>
-rw-r--r--mesonbuild/backend/ninjabackend.py4
-rw-r--r--mesonbuild/compilers/rust.py26
2 files changed, 24 insertions, 6 deletions
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 []