@@ -1401,12 +1401,7 @@ def link(self, targets):
1401
1401
msg = f"Can't link non-PIC static library { t .name !r} into shared library { self .name !r} . "
1402
1402
msg += "Use the 'pic' option to static_library to build with PIC."
1403
1403
raise InvalidArguments (msg )
1404
- if self .for_machine is not t .for_machine :
1405
- msg = f'Tried to mix libraries for machines { self .for_machine } and { t .for_machine } in target { self .name !r} '
1406
- if self .environment .is_cross_build ():
1407
- raise InvalidArguments (msg + ' This is not possible in a cross build.' )
1408
- else :
1409
- mlog .warning (msg + ' This will fail in cross build.' )
1404
+ self .check_can_link_together (t )
1410
1405
self .link_targets .append (t )
1411
1406
1412
1407
def link_whole (self , targets , promoted : bool = False ):
@@ -1422,12 +1417,7 @@ def link_whole(self, targets, promoted: bool = False):
1422
1417
msg = f"Can't link non-PIC static library { t .name !r} into shared library { self .name !r} . "
1423
1418
msg += "Use the 'pic' option to static_library to build with PIC."
1424
1419
raise InvalidArguments (msg )
1425
- if self .for_machine is not t .for_machine :
1426
- msg = f'Tried to mix libraries for machines { self .for_machine } and { t .for_machine } in target { self .name !r} '
1427
- if self .environment .is_cross_build ():
1428
- raise InvalidArguments (msg + ' This is not possible in a cross build.' )
1429
- else :
1430
- mlog .warning (msg + ' This will fail in cross build.' )
1420
+ self .check_can_link_together (t )
1431
1421
if isinstance (self , StaticLibrary ) and not self .uses_rust ():
1432
1422
# When we're a static library and we link_whole: to another static
1433
1423
# library, we need to add that target's objects to ourselves.
@@ -1473,6 +1463,16 @@ def check_can_extract_objects(self, t: T.Union[Target, CustomTargetIndex], origi
1473
1463
f' and thus has to include objects from { t .name !r} to be usable.' )
1474
1464
raise InvalidArguments (m )
1475
1465
1466
+ def check_can_link_together (self , t : BuildTargetTypes ) -> None :
1467
+ if self .for_machine is not t .for_machine :
1468
+ msg = f'Tried to mix libraries for machines { self .for_machine } and { t .for_machine } in target { self .name !r} '
1469
+ if self .environment .is_cross_build ():
1470
+ raise InvalidArguments (msg + ' This is not possible in a cross build.' )
1471
+ else :
1472
+ mlog .warning (msg + ' This will fail in cross build.' )
1473
+ if not self .uses_rust () and isinstance (t , BuildTarget ) and t .uses_rust_abi ():
1474
+ raise InvalidArguments (f'Try to link Rust ABI library { t .name !r} with a non-Rust target { self .name !r} ' )
1475
+
1476
1476
def add_pch (self , language : str , pchlist : T .List [str ]) -> None :
1477
1477
if not pchlist :
1478
1478
return
@@ -1638,6 +1638,9 @@ def get_used_stdlib_args(self, link_language: str) -> T.List[str]:
1638
1638
def uses_rust (self ) -> bool :
1639
1639
return 'rust' in self .compilers
1640
1640
1641
+ def uses_rust_abi (self ) -> bool :
1642
+ return self .uses_rust () and self .rust_crate_type in {'dylib' , 'rlib' , 'proc-macro' }
1643
+
1641
1644
def uses_fortran (self ) -> bool :
1642
1645
return 'fortran' in self .compilers
1643
1646
0 commit comments