summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2025-03-17 00:20:11 +0100
committerEli Schwartz <eschwartz93@gmail.com>2025-04-16 13:02:28 -0400
commite574889f68c5a9c6d94344db731405809843ed37 (patch)
tree46ff6cbdbccc5178076b12a3854d598eccfbed7f
parentce7e1876303071672b5e4b3f1182668bb43d68bd (diff)
downloadmeson-e574889f68c5a9c6d94344db731405809843ed37.tar.gz
ninjabackend: ensure that native static libraries use Unix-style naming
Depending on the target/linker, rustc --print native-static-libs may output MSVC-style names. Converting these to Unix-style is safe, as the list contains only native static libraries. Fixes linking with C targets built with clang on x86_64-pc-windows-msvc target. Fixes: #14366
-rw-r--r--mesonbuild/backend/ninjabackend.py10
-rw-r--r--mesonbuild/build.py3
2 files changed, 11 insertions, 2 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 8627960e8..d7de98799 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -3647,7 +3647,15 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
for d in target.get_dependencies():
if isinstance(d, build.StaticLibrary):
for dep in d.get_external_deps():
- commands.extend_preserving_lflags(linker.get_dependency_link_args(dep))
+ link_args = linker.get_dependency_link_args(dep)
+ # Ensure that native static libraries use Unix-style naming if necessary.
+ # Depending on the target/linker, rustc --print native-static-libs may
+ # output MSVC-style names. Converting these to Unix-style is safe, as the
+ # list contains only native static libraries.
+ if dep.name == '_rust_native_static_libs' and linker.get_argument_syntax() != 'msvc':
+ from ..linkers.linkers import VisualStudioLikeLinker
+ link_args = VisualStudioLikeLinker.native_args_to_unix(link_args)
+ commands.extend_preserving_lflags(link_args)
# Add link args specific to this BuildTarget type that must not be overridden by dependencies
commands += self.get_target_type_link_args_post_dependencies(target, linker)
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index e94f75faa..0e8fb59e4 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -2173,7 +2173,8 @@ class StaticLibrary(BuildTarget):
rustc = self.compilers['rust']
d = dependencies.InternalDependency('undefined', [], [],
rustc.native_static_libs,
- [], [], [], [], [], {}, [], [], [])
+ [], [], [], [], [], {}, [], [], [],
+ '_rust_native_static_libs')
self.external_deps.append(d)
# By default a static library is named libfoo.a even on Windows because
# MSVC does not have a consistent convention for what static libraries