forked from arceos-org/arceos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
33 lines (29 loc) · 1.05 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
use std::io::Result;
fn main() {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let platform = axconfig::PLATFORM;
if platform != "dummy" {
gen_linker_script(&arch, platform).unwrap();
}
println!("cargo:rustc-cfg=platform=\"{}\"", platform);
println!("cargo:rustc-cfg=platform_family=\"{}\"", axconfig::FAMILY);
}
fn gen_linker_script(arch: &str, platform: &str) -> Result<()> {
let fname = format!("linker_{}.lds", platform);
let output_arch = if arch == "x86_64" {
"i386:x86-64"
} else if arch.contains("riscv") {
"riscv" // OUTPUT_ARCH of both riscv32/riscv64 is "riscv"
} else {
arch
};
let ld_content = std::fs::read_to_string("linker.lds.S")?;
let ld_content = ld_content.replace("%ARCH%", output_arch);
let ld_content = ld_content.replace(
"%KERNEL_BASE%",
&format!("{:#x}", axconfig::KERNEL_BASE_VADDR),
);
let ld_content = ld_content.replace("%SMP%", &format!("{}", axconfig::SMP));
std::fs::write(fname, ld_content)?;
Ok(())
}