-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
54 lines (46 loc) · 1.84 KB
/
build.rs
File metadata and controls
54 lines (46 loc) · 1.84 KB
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
use std::env;
use std::path::{Path, PathBuf};
fn find_project_root(manifest_dir: &Path) -> PathBuf {
if let Ok(workspace_dir) = env::var("CARGO_WORKSPACE_DIR") {
return PathBuf::from(workspace_dir);
}
for ancestor in manifest_dir.ancestors() {
if ancestor.join("ramfs").join("lib").exists() {
return ancestor.to_path_buf();
}
}
manifest_dir.to_path_buf()
}
fn main() {
let target = env::var("TARGET").unwrap_or_default();
if target != "x86_64-mochios" {
return;
}
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let manifest_path = Path::new(&manifest_dir);
let project_root = find_project_root(manifest_path);
let libs_dir = project_root.join("ramfs").join("lib");
println!("cargo:rustc-link-search=native={}", libs_dir.display());
println!("cargo:rustc-link-arg={}/crt0.o", libs_dir.display());
println!("cargo:rustc-link-arg=-static");
println!("cargo:rustc-link-arg=-no-pie");
println!("cargo:rustc-link-arg=-T{}/linker.ld", manifest_dir);
println!("cargo:rustc-link-arg=--allow-multiple-definition");
println!("cargo:rustc-link-lib=static=c");
println!("cargo:rustc-link-lib=static=g");
println!("cargo:rustc-link-lib=static=m");
println!("cargo:rustc-link-lib=static=nosys");
let libgcc_s = libs_dir.join("libgcc_s.a");
let libg = libs_dir.join("libg.a");
if !libgcc_s.exists() && libg.exists() {
let tmp = libs_dir.join("libgcc_s.a.tmp");
let _ = std::fs::copy(&libg, &tmp);
let _ = std::fs::rename(&tmp, &libgcc_s);
}
println!("cargo:rustc-link-lib=static=gcc_s");
println!(
"cargo:rerun-if-changed={}",
manifest_path.join("linker.ld").display()
);
println!("cargo:rerun-if-changed={}", libs_dir.join("libc.a").display());
}