Skip to content

Commit b1472e7

Browse files
authored
Merge pull request #506 from nicholasbishop/bishop-fix-stdlib-inc
2 parents 8399451 + c10cfb3 commit b1472e7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

build.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)