1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -319,9 +319,9 @@ than building it.
319
319
&& ( build. config . optimized_compiler_builtins ( * target)
320
320
|| build. config . rust_std_features . contains ( "compiler-builtins-c" ) )
321
321
{
322
- let is_gcc = is_gcc_compiler ( build. cc ( * target) , build) ;
323
- if is_gcc {
324
- panic ! ( "GCC does not support building c code for bare wasm" ) ;
322
+ let is_clang = is_clang_compiler ( build. cc ( * target) , build) ;
323
+ if !is_clang {
324
+ panic ! ( "only clang supports building c code for wasm targets " ) ;
325
325
}
326
326
}
327
327
@@ -388,7 +388,15 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
388
388
}
389
389
}
390
390
391
- fn is_gcc_compiler ( path : PathBuf , build : & Build ) -> bool {
392
- let cc_output = command ( & path) . arg ( "--version" ) . run_capture_stdout ( build) . stdout ( ) ;
393
- cc_output. contains ( "GCC" )
391
+ /// checks if the compiler at `path` is clang by looking at defined macros
392
+ fn is_clang_compiler ( path : PathBuf , build : & Build ) -> bool {
393
+ let cc_output = command ( & path)
394
+ . arg ( "-E" ) // preprocess only
395
+ . arg ( "-dM" ) // dump defines
396
+ . arg ( "-x" )
397
+ . arg ( "c" )
398
+ . arg ( "/dev/null" )
399
+ . run_capture_stdout ( build)
400
+ . stdout ( ) ;
401
+ cc_output. contains ( "#define __clang__ 1" )
394
402
}
0 commit comments