Skip to content

Commit e574889

Browse files
kasper93eli-schwartz
authored andcommitted
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
1 parent ce7e187 commit e574889

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3647,7 +3647,15 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.
36473647
for d in target.get_dependencies():
36483648
if isinstance(d, build.StaticLibrary):
36493649
for dep in d.get_external_deps():
3650-
commands.extend_preserving_lflags(linker.get_dependency_link_args(dep))
3650+
link_args = linker.get_dependency_link_args(dep)
3651+
# Ensure that native static libraries use Unix-style naming if necessary.
3652+
# Depending on the target/linker, rustc --print native-static-libs may
3653+
# output MSVC-style names. Converting these to Unix-style is safe, as the
3654+
# list contains only native static libraries.
3655+
if dep.name == '_rust_native_static_libs' and linker.get_argument_syntax() != 'msvc':
3656+
from ..linkers.linkers import VisualStudioLikeLinker
3657+
link_args = VisualStudioLikeLinker.native_args_to_unix(link_args)
3658+
commands.extend_preserving_lflags(link_args)
36513659

36523660
# Add link args specific to this BuildTarget type that must not be overridden by dependencies
36533661
commands += self.get_target_type_link_args_post_dependencies(target, linker)

mesonbuild/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,8 @@ def post_init(self) -> None:
21732173
rustc = self.compilers['rust']
21742174
d = dependencies.InternalDependency('undefined', [], [],
21752175
rustc.native_static_libs,
2176-
[], [], [], [], [], {}, [], [], [])
2176+
[], [], [], [], [], {}, [], [], [],
2177+
'_rust_native_static_libs')
21772178
self.external_deps.append(d)
21782179
# By default a static library is named libfoo.a even on Windows because
21792180
# MSVC does not have a consistent convention for what static libraries

0 commit comments

Comments
 (0)