diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-09-12 15:27:00 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-10-08 10:51:48 -0700 |
| commit | 018d224821f91c1d352e71b59e35e6f2fe64b119 (patch) | |
| tree | 81cfd89697b550b5eefaa45479e7623efecd909f /mesonbuild | |
| parent | 400f0325074c4ede26d99742885ecbcf2f108b08 (diff) | |
| download | meson-018d224821f91c1d352e71b59e35e6f2fe64b119.tar.gz | |
ninjabackend: unify conversion from path to -L/-l
When Meson cannot use -Clink-arg=, it has to split the path into a -L
option (to add to the search directory) and a -l option (to actually
link). Furthermore, if rustc does not support verbatim, Meson needs to
undo the addition of "lib" and the extension.
Do both tasks in the same place and with the same logic, instead of
treating internal and external libraries differently.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild')
| -rw-r--r-- | mesonbuild/backend/ninjabackend.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 2f40ede4a..4e8af9545 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2038,18 +2038,24 @@ class NinjaBackend(backends.Backend): except (KeyError, AttributeError): pass - if mesonlib.version_compare(rustc.version, '>= 1.67.0'): - verbatim = '+verbatim' - else: - verbatim = '' + has_verbatim = mesonlib.version_compare(rustc.version, '>= 1.67.0') def _link_library(libname: str, static: bool, bundle: bool = False) -> None: type_ = 'static' if static else 'dylib' modifiers = [] + # Except with -Clink-arg, search is limited to the -L search paths + dir_, libname = os.path.split(libname) + linkdirs.add(dir_) if not bundle and static: modifiers.append('-bundle') - if verbatim: - modifiers.append(verbatim) + if has_verbatim: + modifiers.append('+verbatim') + else: + # undo the effects of -l without verbatim + libname, ext = os.path.splitext(libname) + if libname.startswith('lib'): + libname = libname[3:] + if modifiers: type_ += ':' + ','.join(modifiers) args.append(f'-l{type_}={libname}') @@ -2062,11 +2068,11 @@ class NinjaBackend(backends.Backend): external_deps = target.external_deps.copy() target_deps = target.get_dependencies() for d in target_deps: - linkdirs.add(d.subdir) deps.append(self.get_dependency_filename(d)) if isinstance(d, build.StaticLibrary): external_deps.extend(d.external_deps) if d.uses_rust_abi(): + linkdirs.add(d.subdir) if d not in itertools.chain(target.link_targets, target.link_whole_targets): # Indirect Rust ABI dependency, we only need its path in linkdirs. continue @@ -2094,8 +2100,7 @@ class NinjaBackend(backends.Backend): link_whole = d in target.link_whole_targets if isinstance(target, build.StaticLibrary) or (isinstance(target, build.Executable) and rustc.get_crt_static()): static = isinstance(d, build.StaticLibrary) - libname = os.path.basename(lib) if verbatim else d.name - _link_library(libname, static, bundle=link_whole) + _link_library(lib, static, bundle=link_whole) elif link_whole: link_whole_args = rustc.linker.get_link_whole_for([lib]) args += [f'-Clink-arg={a}' for a in link_whole_args] @@ -2111,18 +2116,14 @@ class NinjaBackend(backends.Backend): args.append(a) continue elif is_library(a): - dir_, lib = os.path.split(a) - linkdirs.add(dir_) - if isinstance(target, build.StaticLibrary): - if not verbatim: - lib, ext = os.path.splitext(lib) - if lib.startswith('lib'): - lib = lib[3:] static = a.endswith(('.a', '.lib')) - _link_library(lib, static) + _link_library(a, static) continue + dir_, _ = os.path.split(lib) + linkdirs.add(dir_) + args.append(f'-Clink-arg={a}') for d in linkdirs: |
