@@ -311,6 +311,33 @@ impl TargetTriple {
311
311
pub fn from_host_or_build ( ) -> Self {
312
312
Self :: from_host ( ) . unwrap_or_else ( Self :: from_build)
313
313
}
314
+
315
+ pub fn can_run ( & self , other : & TargetTriple ) -> Result < bool > {
316
+ // Most trivial shortcut of all
317
+ if self == other {
318
+ return Ok ( true ) ;
319
+ }
320
+ // Otherwise we need to parse things
321
+ let partial_self = PartialTargetTriple :: new ( & self . 0 )
322
+ . ok_or_else ( || anyhow ! ( format!( "Unable to parse target triple: {}" , self . 0 ) ) ) ?;
323
+ let partial_other = PartialTargetTriple :: new ( & other. 0 )
324
+ . ok_or_else ( || anyhow ! ( format!( "Unable to parse target triple: {}" , other. 0 ) ) ) ?;
325
+ // First obvious check is OS, if that doesn't match there's no chance
326
+ let ret = if partial_self. os != partial_other. os {
327
+ false
328
+ } else if partial_self. os . as_deref ( ) == Some ( "pc-windows" ) {
329
+ // Windows is a special case here, we know we can run 32bit on 64bit
330
+ // and we know we can run gnu and msvc on the same system
331
+ // We don't immediately assume we can cross between x86 and aarch64 though
332
+ ( partial_self. arch == partial_other. arch )
333
+ || ( partial_self. arch . as_deref ( ) == Some ( "x86_64" )
334
+ && partial_other. arch . as_deref ( ) == Some ( "i686" ) )
335
+ } else {
336
+ // For other OSes, for now, we assume other toolchains won't run
337
+ false
338
+ } ;
339
+ Ok ( ret)
340
+ }
314
341
}
315
342
316
343
impl std:: convert:: TryFrom < PartialTargetTriple > for TargetTriple {
0 commit comments