@@ -98,7 +98,7 @@ mod c {
9898
9999 use std:: collections:: { BTreeMap , HashSet } ;
100100 use std:: env;
101- use std:: fs:: File ;
101+ use std:: fs:: { self , File } ;
102102 use std:: io:: Write ;
103103 use std:: path:: { Path , PathBuf } ;
104104
@@ -190,6 +190,21 @@ mod c {
190190 cfg. define ( "VISIBILITY_HIDDEN" , None ) ;
191191 }
192192
193+ // int_util.c tries to include stdlib.h if `_WIN32` is defined,
194+ // which it is when compiling UEFI targets with clang. This is
195+ // at odds with compiling with `-ffreestanding`, as the header
196+ // may be incompatible or not present. Create a minimal stub
197+ // header to use instead.
198+ if target_os == "uefi" {
199+ let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
200+ let include_dir = out_dir. join ( "include" ) ;
201+ if !include_dir. exists ( ) {
202+ fs:: create_dir ( & include_dir) . unwrap ( ) ;
203+ }
204+ fs:: write ( include_dir. join ( "stdlib.h" ) , "#include <stddef.h>" ) . unwrap ( ) ;
205+ cfg. flag ( & format ! ( "-I{}" , include_dir. to_str( ) . unwrap( ) ) ) ;
206+ }
207+
193208 let mut sources = Sources :: new ( ) ;
194209 sources. extend ( & [
195210 ( "__absvdi2" , "absvdi2.c" ) ,
0 commit comments