@@ -1968,7 +1968,7 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
19681968 # have to hope that the default cases of +whole-archive are sufficient.
19691969 # See: https://github.com/rust-lang/rust/issues/99429
19701970 if mesonlib .version_compare (rustc .version , '>= 1.63.0' ):
1971- whole_archive = '+whole-archive,-bundle '
1971+ whole_archive = '+whole-archive'
19721972 else :
19731973 whole_archive = ''
19741974
@@ -1978,6 +1978,15 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
19781978 else :
19791979 verbatim = ''
19801980
1981+ def add_native_library (libname : str , static : bool , modifiers : T .Optional [T .List [str ]] = None ):
1982+ _type = 'static' if static else 'dylib'
1983+ modifiers = modifiers or []
1984+ if static and target .is_internal ():
1985+ modifiers .append ('-bundle' )
1986+ if modifiers :
1987+ _type += ':' + ',' .join (modifiers )
1988+ args .extend (['-l' , f'{ _type } ={ libname } ' ])
1989+
19811990 linkdirs = mesonlib .OrderedSet ()
19821991 external_deps = target .external_deps .copy ()
19831992 target_deps = target .get_dependencies ()
@@ -2034,10 +2043,8 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
20342043 need_link = False
20352044
20362045 if need_link :
2037- _type = 'static' if isinstance (d , build .StaticLibrary ) else 'dylib'
2038- if modifiers :
2039- _type += ':' + ',' .join (modifiers )
2040- args += ['-l' , f'{ _type } ={ os .path .basename (lib )} ' ]
2046+ static = isinstance (d , build .StaticLibrary )
2047+ add_native_library (os .path .basename (lib ), static , modifiers )
20412048
20422049 for e in external_deps :
20432050 for a in e .get_link_args ():
@@ -2050,13 +2057,13 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
20502057 lib , ext = os .path .splitext (lib )
20512058 if lib .startswith ('lib' ):
20522059 lib = lib [3 :]
2053- _type = 'static' if a .endswith (('.a' , '.lib' )) else 'dylib'
2054- args . extend ([ '-l' , f' { _type } = { lib } ' ] )
2060+ static = a .endswith (('.a' , '.lib' ))
2061+ add_native_library ( lib , static )
20552062 elif a .startswith ('-L' ):
20562063 args .append (a )
20572064 elif a .startswith ('-l' ):
2058- _type = 'static' if e . static else 'dylib'
2059- args . extend ([ '-l' , f' { _type } = { a [2 :]} ' ] )
2065+ static = a . endswith (( '.a' , '.lib' ))
2066+ add_native_library ( a [2 :], e . static )
20602067 for d in linkdirs :
20612068 if d == '' :
20622069 d = '.'
0 commit comments