@@ -803,32 +803,39 @@ export namespace sdk {
803
803
) ;
804
804
}
805
805
806
- if ( foundCC instanceof tg . File ) {
807
- // Inspect the file to see which system it should run on.
808
- const metadata = await std . file . executableMetadata ( foundCC ) ;
809
- if ( metadata . format !== "elf" && metadata . format !== "mach-o" ) {
810
- throw new Error ( `Unexpected compiler format ${ metadata . format } .` ) ;
811
- }
812
- let detectedArch : string | undefined ;
813
- if ( metadata . format === "elf" ) {
814
- detectedArch = metadata . arch ;
815
- } else if ( metadata . format === "mach-o" ) {
816
- detectedArch = metadata . arches [ 0 ] ?? "aarch64" ;
817
- }
806
+ // If the file is a symlink, resolve it.
807
+ if ( foundCC instanceof tg . Symlink ) {
808
+ foundCC = await foundCC . resolve ( ) ;
809
+ }
810
+ tg . assert ( foundCC instanceof tg . File ) ;
811
+
812
+ // Inspect the file to see which system it should run on.
813
+ const metadata = await std . file . executableMetadata ( foundCC ) ;
814
+ let detectedArch : string | undefined ;
815
+ if ( metadata . format === "elf" ) {
816
+ detectedArch = metadata . arch ;
817
+ } else if ( metadata . format === "mach-o" ) {
818
+ detectedArch = metadata . arches [ 0 ] ?? "aarch64" ;
819
+ }
820
+ if ( metadata . format !== "shebang" ) {
818
821
const os = metadata . format === "elf" ? "linux" : "darwin" ;
819
822
const arch = detectedArch ?? "x86_64" ;
820
823
detectedHost = `${ arch } -${ os } ` ;
821
824
}
822
825
823
- // Actually run the compiler on the detected system to ask what host triple it's configured for.
824
- const output = await std . build `${ cmd } -dumpmachine > $OUTPUT`
825
- . bootstrap ( true )
826
- . env ( env_ )
827
- . host ( std . triple . archAndOs ( detectedHost ) )
828
- . then ( tg . File . expect ) ;
829
- const host = ( await output . text ( ) ) . trim ( ) ;
830
- std . triple . assert ( host ) ;
831
- return host ;
826
+ // For cross compilers, use the host detected. For host compilers, run the compiler on the detected system to ask what host triple it's configured for.
827
+ if ( isCross ) {
828
+ return detectedHost ;
829
+ } else {
830
+ const output = await std . build `${ cmd } -dumpmachine > $OUTPUT`
831
+ . bootstrap ( true )
832
+ . env ( env_ )
833
+ . host ( std . triple . archAndOs ( detectedHost ) )
834
+ . then ( tg . File . expect ) ;
835
+ const host = ( await output . text ( ) ) . trim ( ) ;
836
+ std . triple . assert ( host ) ;
837
+ return host ;
838
+ }
832
839
} ;
833
840
834
841
/** Retreive the full range of targets an SDK supports. */
0 commit comments