Skip to content

Commit ebd25b4

Browse files
bonzinidcbaker
authored andcommitted
rust: query linker in addition to compiler for verbatim support
Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 2a6a7a9 commit ebd25b4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,8 +2038,6 @@ def get_rust_compiler_deps_and_args(self, target: build.BuildTarget, rustc: Comp
20382038
except (KeyError, AttributeError):
20392039
pass
20402040

2041-
has_verbatim = mesonlib.version_compare(rustc.version, '>= 1.67.0')
2042-
20432041
def _link_library(libname: str, static: bool, bundle: bool = False) -> None:
20442042
orig_libname = libname
20452043
type_ = 'static' if static else 'dylib'
@@ -2049,7 +2047,7 @@ def _link_library(libname: str, static: bool, bundle: bool = False) -> None:
20492047
linkdirs.add(dir_)
20502048
if not bundle and static:
20512049
modifiers.append('-bundle')
2052-
if has_verbatim:
2050+
if rustc.has_verbatim():
20532051
modifiers.append('+verbatim')
20542052
else:
20552053
# undo the effects of -l without verbatim

mesonbuild/compilers/rust.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import typing as T
1212

1313
from .. import options
14-
from ..mesonlib import EnvironmentException, MesonException, Popen_safe_logged
14+
from ..mesonlib import EnvironmentException, MesonException, Popen_safe_logged, version_compare
1515
from ..options import OptionKey
1616
from .compilers import Compiler, CompileCheckMode, clike_debug_args
1717

@@ -194,6 +194,20 @@ def get_cfgs(self) -> T.List[str]:
194194
def get_crt_static(self) -> bool:
195195
return 'target_feature="crt-static"' in self.get_cfgs()
196196

197+
@functools.lru_cache(maxsize=None)
198+
def has_verbatim(self) -> bool:
199+
if version_compare(self.version, '< 1.67.0'):
200+
return False
201+
# GNU ld support '-l:PATH'
202+
if 'ld.' in self.linker.id:
203+
return True
204+
# -l:+verbatim does not work (yet?) with MSVC link or Apple ld64
205+
# (https://github.com/rust-lang/rust/pull/138753). For ld64, it
206+
# works together with -l:+whole_archive because -force_load (the macOS
207+
# equivalent of --whole-archive), receives the full path to the library
208+
# being linked. However, Meson uses "bundle", not "whole_archive".
209+
return False
210+
197211
def get_debug_args(self, is_debug: bool) -> T.List[str]:
198212
return clike_debug_args[is_debug]
199213

0 commit comments

Comments
 (0)