@ -84,6 +84,7 @@ class RustCompiler(Compiler):
pc , stdo , stde = Popen_safe_logged ( cmdlist , cwd = work_dir )
if pc . returncode != 0 :
raise EnvironmentException ( f ' Rust compiler { self . name_string ( ) } cannot compile programs. ' )
self . _native_static_libs ( work_dir , source_name )
if environment . need_exe_wrapper ( self . for_machine ) :
if not environment . has_exe_wrapper ( ) :
# Can't check if the binaries run so we have to assume they do
@ -95,18 +96,22 @@ class RustCompiler(Compiler):
pe . wait ( )
if pe . returncode != 0 :
raise EnvironmentException ( f ' Executables created by Rust compiler { self . name_string ( ) } are not runnable. ' )
def _native_static_libs ( self , work_dir : str , source_name : str ) - > None :
# Get libraries needed to link with a Rust staticlib
cmdlist = self . exelist + [ ' --crate-type ' , ' staticlib ' , ' --print ' , ' native-static-libs ' , source_name ]
p , stdo , stde = Popen_safe_logged ( cmdlist , cwd = work_dir )
if p . returncode == 0 :
match = re . search ( ' native-static-libs: (.*)$ ' , stde , re . MULTILINE )
if match :
# Exclude some well known libraries that we don't need because they
# are always part of C/C++ linkers. Rustc probably should not print
# them, pkg-config for example never specify them.
# FIXME: https://github.com/rust-lang/rust/issues/55120
exclude = { ' -lc ' , ' -lgcc_s ' , ' -lkernel32 ' , ' -ladvapi32 ' }
self . native_static_libs = [ i for i in match . group ( 1 ) . split ( ) if i not in exclude ]
if p . returncode != 0 :
raise EnvironmentException ( ' Rust compiler cannot compile staticlib. ' )
match = re . search ( ' native-static-libs: (.*)$ ' , stde , re . MULTILINE )
if not match :
raise EnvironmentException ( ' Failed to find native-static-libs in Rust compiler output. ' )
# Exclude some well known libraries that we don't need because they
# are always part of C/C++ linkers. Rustc probably should not print
# them, pkg-config for example never specify them.
# FIXME: https://github.com/rust-lang/rust/issues/55120
exclude = { ' -lc ' , ' -lgcc_s ' , ' -lkernel32 ' , ' -ladvapi32 ' }
self . native_static_libs = [ i for i in match . group ( 1 ) . split ( ) if i not in exclude ]
def get_dependency_gen_args ( self , outtarget : str , outfile : str ) - > T . List [ str ] :
return [ ' --dep-info ' , outfile ]