@@ -98,7 +98,7 @@ mod c {
98
98
99
99
use std:: collections:: { BTreeMap , HashSet } ;
100
100
use std:: env;
101
- use std:: fs:: File ;
101
+ use std:: fs:: { self , File } ;
102
102
use std:: io:: Write ;
103
103
use std:: path:: { Path , PathBuf } ;
104
104
@@ -190,6 +190,21 @@ mod c {
190
190
cfg. define ( "VISIBILITY_HIDDEN" , None ) ;
191
191
}
192
192
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
+
193
208
let mut sources = Sources :: new ( ) ;
194
209
sources. extend ( & [
195
210
( "__absvdi2" , "absvdi2.c" ) ,
0 commit comments