forked from syswonder/ruxos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
42 lines (37 loc) · 1.58 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
/* Copyright (c) [2023] [Syswonder Community]
* [Rukos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
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(())
}