summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-11-08 16:21:00 +0100
committerDylan Baker <dylan@pnwbakers.com>2025-11-12 14:56:22 -0800
commite9c6262d1d46a20b909562827a4312aca86a29f2 (patch)
tree9d188f4ec74f2d77dd7f46716dae14c65525d21b /mesonbuild
parent572c6986b886bec90ce21adde9d15d4b12a22909 (diff)
downloadmeson-e9c6262d1d46a20b909562827a4312aca86a29f2.tar.gz
rust: add full set of linker argument functions to RustCompiler
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers/rust.py58
1 files changed, 44 insertions, 14 deletions
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index 54b917f7a..acd1344c6 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -65,6 +65,15 @@ def get_rustup_run_and_args(exelist: T.List[str]) -> T.Optional[T.Tuple[T.List[s
except StopIteration:
return None
+def rustc_link_args(args: T.List[str]) -> T.List[str]:
+ if not args:
+ return args
+ rustc_args: T.List[str] = []
+ for arg in args:
+ rustc_args.append('-C')
+ rustc_args.append(f'link-arg={arg}')
+ return rustc_args
+
class RustCompiler(Compiler):
# rustc doesn't invoke the compiler itself, it doesn't need a LINKER_PREFIX
@@ -98,7 +107,7 @@ class RustCompiler(Compiler):
is_cross=is_cross, full_version=full_version,
linker=linker)
self.rustup_run_and_args: T.Optional[T.Tuple[T.List[str], T.List[str]]] = get_rustup_run_and_args(exelist)
- self.base_options.update({OptionKey(o) for o in ['b_colorout', 'b_ndebug']})
+ self.base_options.update({OptionKey(o) for o in ['b_colorout', 'b_ndebug', 'b_pgo']})
if isinstance(self.linker, VisualStudioLikeLinkerMixin):
self.base_options.add(OptionKey('b_vscrt'))
self.native_static_libs: T.List[str] = []
@@ -254,12 +263,7 @@ class RustCompiler(Compiler):
target: BuildTarget, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
# add rustc's sysroot to account for rustup installations
args, to_remove = super().build_rpath_args(env, build_dir, from_dir, target, [self.get_target_libdir()])
-
- rustc_rpath_args = []
- for arg in args:
- rustc_rpath_args.append('-C')
- rustc_rpath_args.append(f'link-arg={arg}')
- return rustc_rpath_args, to_remove
+ return rustc_link_args(args), to_remove
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
build_dir: str) -> T.List[str]:
@@ -333,13 +337,9 @@ class RustCompiler(Compiler):
return [f'--color={colortype}']
raise MesonException(f'Invalid color type for rust {colortype}')
+ @functools.lru_cache(maxsize=None)
def get_linker_always_args(self) -> T.List[str]:
- args: T.List[str] = []
- # Rust is super annoying, calling -C link-arg foo does not work, it has
- # to be -C link-arg=foo
- for a in super().get_linker_always_args():
- args.extend(['-C', f'link-arg={a}'])
- return args
+ return rustc_link_args(super().get_linker_always_args())
def get_embed_bitcode_args(self, bitcode: bool, lto: bool) -> T.List[str]:
if bitcode:
@@ -354,6 +354,36 @@ class RustCompiler(Compiler):
rustc_lto = 'lto=thin' if mode == 'thin' else 'lto'
return ['-C', rustc_lto]
+ def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
+ thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ # no need to specify anything because the rustc command line
+ # includes the result of get_lto_compile_args()
+ return []
+
+ def get_lto_obj_cache_path(self, path: str) -> T.List[str]:
+ return rustc_link_args(super().get_lto_obj_cache_path(path))
+
+ def get_profile_generate_args(self) -> T.List[str]:
+ return ['-C', 'profile-generate']
+
+ def get_profile_use_args(self) -> T.List[str]:
+ return ['-C', 'profile-use']
+
+ @functools.lru_cache(maxsize=None)
+ def get_asneeded_args(self) -> T.List[str]:
+ return rustc_link_args(super().get_asneeded_args())
+
+ def bitcode_args(self) -> T.List[str]:
+ return ['-C', 'embed-bitcode=yes']
+
+ @functools.lru_cache(maxsize=None)
+ def headerpad_args(self) -> T.List[str]:
+ return rustc_link_args(super().headerpad_args())
+
+ @functools.lru_cache(maxsize=None)
+ def get_allow_undefined_link_args(self) -> T.List[str]:
+ return rustc_link_args(super().get_allow_undefined_link_args())
+
def get_werror_args(self) -> T.List[str]:
# Use -D warnings, which makes every warning not explicitly allowed an
# error
@@ -399,7 +429,7 @@ class RustCompiler(Compiler):
return self.compiles('fn main() { std::process::exit(0) }\n', env, extra_args=args, mode=CompileCheckMode.COMPILE)
def has_multi_link_arguments(self, args: T.List[str], env: Environment) -> T.Tuple[bool, bool]:
- args = self.linker.fatal_warnings() + args
+ args = rustc_link_args(self.linker.fatal_warnings()) + args
return self.compiles('fn main() { std::process::exit(0) }\n', env, extra_args=args, mode=CompileCheckMode.LINK)
@functools.lru_cache(maxsize=None)