diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2024-11-20 00:33:45 +0100 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-02-03 20:01:37 -0500 |
| commit | 103501c2741f9ff919bc04a17cb057ace150526c (patch) | |
| tree | c97757a892e1c5ff25d95c0cea05f55316a29df5 /mesonbuild/backend | |
| parent | 4276f1d482095ea003ec39de0fd17ab16dab4b95 (diff) | |
| download | meson-103501c2741f9ff919bc04a17cb057ace150526c.tar.gz | |
ninjabackend: unify building rpath args
Implement RustCompiler.build_rpath_args, so that more code can
be shared between non-Rust and Rust targets. Then, RustCompiler
can override it to convert the arguments to "-C link-arg=" and
add the rustup sysroot.
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/backend')
| -rw-r--r-- | mesonbuild/backend/ninjabackend.py | 60 |
1 files changed, 20 insertions, 40 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 21ca38c0d..4aadb12cb 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2123,29 +2123,7 @@ class NinjaBackend(backends.Backend): args += ['-C', 'prefer-dynamic'] if isinstance(target, build.SharedLibrary) or has_shared_deps: - # build the usual rpath arguments as well... - - # Set runtime-paths so we can run executables without needing to set - # LD_LIBRARY_PATH, etc in the environment. Doesn't work on Windows. - if has_path_sep(target.name): - # Target names really should not have slashes in them, but - # unfortunately we did not check for that and some downstream projects - # now have them. Once slashes are forbidden, remove this bit. - target_slashname_workaround_dir = os.path.join(os.path.dirname(target.name), - self.get_target_dir(target)) - else: - target_slashname_workaround_dir = self.get_target_dir(target) - rpath_args, target.rpath_dirs_to_remove = ( - rustc.build_rpath_args(self.environment, - self.environment.get_build_dir(), - target_slashname_workaround_dir, - self.determine_rpath_dirs(target), - target.build_rpath, - target.install_rpath)) - # ... but then add rustc's sysroot to account for rustup - # installations - for rpath_arg in rpath_args: - args += ['-C', 'link-arg=' + rpath_arg + ':' + rustc.get_target_libdir()] + args += self.get_build_rpath_args(target, rustc) proc_macro_dylib_path = None if cratetype == 'proc-macro': @@ -3486,6 +3464,24 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) self.add_build(elem) return obj_list + def get_build_rpath_args(self, target: build.BuildTarget, linker: T.Union[Compiler, StaticLinker]) -> T.List[str]: + if has_path_sep(target.name): + # Target names really should not have slashes in them, but + # unfortunately we did not check for that and some downstream projects + # now have them. Once slashes are forbidden, remove this bit. + target_slashname_workaround_dir = os.path.join(os.path.dirname(target.name), + self.get_target_dir(target)) + else: + target_slashname_workaround_dir = self.get_target_dir(target) + (rpath_args, target.rpath_dirs_to_remove) = ( + linker.build_rpath_args(self.environment, + self.environment.get_build_dir(), + target_slashname_workaround_dir, + self.determine_rpath_dirs(target), + target.build_rpath, + target.install_rpath)) + return rpath_args + def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.Union['Compiler', 'StaticLinker'], extra_args=None, stdlib_args=None): extra_args = extra_args if extra_args is not None else [] stdlib_args = stdlib_args if stdlib_args is not None else [] @@ -3551,23 +3547,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) # Set runtime-paths so we can run executables without needing to set # LD_LIBRARY_PATH, etc in the environment. Doesn't work on Windows. - if has_path_sep(target.name): - # Target names really should not have slashes in them, but - # unfortunately we did not check for that and some downstream projects - # now have them. Once slashes are forbidden, remove this bit. - target_slashname_workaround_dir = os.path.join( - os.path.dirname(target.name), - self.get_target_dir(target)) - else: - target_slashname_workaround_dir = self.get_target_dir(target) - (rpath_args, target.rpath_dirs_to_remove) = ( - linker.build_rpath_args(self.environment, - self.environment.get_build_dir(), - target_slashname_workaround_dir, - self.determine_rpath_dirs(target), - target.build_rpath, - target.install_rpath)) - commands += rpath_args + commands += self.get_build_rpath_args(target, linker) # Add link args to link to all internal libraries (link_with:) and # internal dependencies needed by this target. |
