forked from theseus-os/Theseus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
80 lines (66 loc) · 2.6 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
extern crate cc;
use std::{env, fs, fs::DirEntry}; //, path::Path};
// // include src/header directories that don't start with '_'
// fn include_dir(d: &DirEntry) -> bool {
// d.metadata().map(|m| m.is_dir()).unwrap_or(false)
// && d.path()
// .iter()
// .nth(2)
// .map_or(false, |c| c.to_str().map_or(false, |x| !x.starts_with("_")))
// }
// fn generate_bindings(cbindgen_config_path: &Path) {
// let relative_path = cbindgen_config_path
// .strip_prefix("src/header")
// .ok()
// .and_then(|p| p.parent())
// .and_then(|p| p.to_str())
// .unwrap()
// .replace("_", "/");
// let header_path = Path::new("target/include")
// .join(&relative_path)
// .with_extension("h");
// let mod_path = cbindgen_config_path.with_file_name("mod.rs");
// let config = cbindgen::Config::from_file(cbindgen_config_path).unwrap();
// cbindgen::Builder::new()
// .with_config(config)
// .with_src(mod_path)
// .generate()
// .expect("Unable to generate bindings")
// .write_to_file(header_path);
// }
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
eprintln!("crate_dir: {:?}", crate_dir);
let mut c_build = cc::Build::new();
c_build
.no_default_flags(true)
.flag("-nostdinc")
.flag("-nostdlib")
.flag("-nostartfiles")
.flag("-mno-red-zone")
.flag("-mcmodel=large")
.flag("-static-libgcc")
.flag("-z max-page-size=4096")
// Theseus's loader/linker expects all sections to be kept separate
// or merged by its own partial relinking script.
.flag("-ffunction-sections")
.flag("-fdata-sections")
// disable PLT, Procedure Linkage Table, a type of relocation entry Theseus doesn't yet support
.flag("-fno-plt")
.use_plt(false)
// disable PIC, which disables usage of the GOT (Global Offset Table), a type of relocation entry Theseus doesn't yet support
.flag("-fno-pic")
.pic(false)
.static_flag(false)
.include(&format!("{}/include", crate_dir))
.flag("-fno-stack-protector")
.flag("-Wno-expansion-to-defined")
.files(
fs::read_dir("src/c_wrappers")
.expect("src/c_wrappers directory missing")
.map(|res| res.expect("read_dir error").path()),
);
eprintln!("c_build: {:#?}", c_build);
eprintln!("c_build tool: {:#?}", c_build.get_compiler());
c_build.compile("tlibc_c");
}