diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-10-16 18:34:03 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-10-16 13:33:02 -0700 |
| commit | 2c1dc736eb62ef6b3922f846785101cd3d2b2972 (patch) | |
| tree | a980baa15094a3fd9b0033ae2e22481a3f548a73 /mesonbuild | |
| parent | 9f83bbb0b680b51776ec9f6ac341f03465203f0b (diff) | |
| download | meson-2c1dc736eb62ef6b3922f846785101cd3d2b2972.tar.gz | |
rust: work around unintuitive behavior of -l:-bundle
When a Rust target depends on an intermediate Rust library (.rlib) which
itself has a dependency on a native static library, Meson's generated
rustc command line failed to collect and propagate the search paths for
these indirect native dependencies, leading to a linker error:
error: linking with `cc` failed: exit status: 1
= note: rust-lld: error: unable to find library -l:libf.a
collect2: error: ld returned 1 exit status
The root cause is that the intermediate .rlib's metadata correctly
stores the requirement to link the native library (via the -l flag),
but it does not store the library's search path (the -L flag); the
responsibility for providing the search path is therefore deferred
to the final link command.
Ensures that search paths for all transitive dependencies are collected,
allowing the final linker invocation to find and correctly link the
required native libraries.
Reported-by: Martin Kletzander <nert.pinx@gmail.com>
Fixes: 018d22482 ("ninjabackend: unify conversion from path to -L/-l", 2025-10-08)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild')
| -rw-r--r-- | mesonbuild/backend/ninjabackend.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 3fd82a85b..50917aeef 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2079,11 +2079,17 @@ class NinjaBackend(backends.Backend): external_deps = target.external_deps.copy() target_deps = target.get_dependencies() for d in target_deps: + # rlibs only store -l flags, not -L; help out rustc and always + # add the -L flag, in case it's needed to find non-bundled + # dependencies of an rlib. At this point we don't have + # information on whether this is a direct dependency (which + # might use -Clink-arg= below) or an indirect one, so always + # add to linkdirs. + 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 |
