2022-01-22 02:21:32 +04:00
|
|
|
use std::fs::{read_dir, File};
|
2020-11-18 14:29:53 +04:00
|
|
|
use std::io::{Result, Write};
|
|
|
|
|
|
|
|
fn main() {
|
2021-01-02 06:17:52 +04:00
|
|
|
println!("cargo:rerun-if-changed=../user/src/");
|
|
|
|
println!("cargo:rerun-if-changed={}", TARGET_PATH);
|
2020-11-18 14:29:53 +04:00
|
|
|
insert_app_data().unwrap();
|
|
|
|
}
|
|
|
|
|
2020-11-30 06:29:17 +04:00
|
|
|
static TARGET_PATH: &str = "../user/target/riscv64gc-unknown-none-elf/release/";
|
2020-11-18 14:29:53 +04:00
|
|
|
|
|
|
|
fn insert_app_data() -> Result<()> {
|
|
|
|
let mut f = File::create("src/link_app.S").unwrap();
|
2020-11-20 07:10:38 +04:00
|
|
|
let mut apps: Vec<_> = read_dir("../user/src/bin")
|
2020-11-18 14:29:53 +04:00
|
|
|
.unwrap()
|
|
|
|
.into_iter()
|
|
|
|
.map(|dir_entry| {
|
|
|
|
let mut name_with_ext = dir_entry.unwrap().file_name().into_string().unwrap();
|
|
|
|
name_with_ext.drain(name_with_ext.find('.').unwrap()..name_with_ext.len());
|
|
|
|
name_with_ext
|
|
|
|
})
|
|
|
|
.collect();
|
2020-11-20 07:10:38 +04:00
|
|
|
apps.sort();
|
2020-11-18 14:29:53 +04:00
|
|
|
|
2022-01-22 02:21:32 +04:00
|
|
|
writeln!(
|
|
|
|
f,
|
|
|
|
r#"
|
2021-02-13 21:00:46 +04:00
|
|
|
.align 3
|
2020-11-19 00:33:06 +04:00
|
|
|
.section .data
|
|
|
|
.global _num_app
|
|
|
|
_num_app:
|
2022-01-22 02:21:32 +04:00
|
|
|
.quad {}"#,
|
|
|
|
apps.len()
|
|
|
|
)?;
|
2020-11-19 00:33:06 +04:00
|
|
|
|
|
|
|
for i in 0..apps.len() {
|
2021-01-02 06:17:52 +04:00
|
|
|
writeln!(f, r#" .quad app_{}_start"#, i)?;
|
2020-11-19 00:33:06 +04:00
|
|
|
}
|
2021-01-02 06:17:52 +04:00
|
|
|
writeln!(f, r#" .quad app_{}_end"#, apps.len() - 1)?;
|
2020-11-19 00:33:06 +04:00
|
|
|
|
2020-11-19 14:01:16 +04:00
|
|
|
for (idx, app) in apps.iter().enumerate() {
|
|
|
|
println!("app_{}: {}", idx, app);
|
2022-01-22 02:21:32 +04:00
|
|
|
writeln!(
|
|
|
|
f,
|
|
|
|
r#"
|
2020-11-18 14:29:53 +04:00
|
|
|
.section .data
|
|
|
|
.global app_{0}_start
|
|
|
|
.global app_{0}_end
|
|
|
|
app_{0}_start:
|
2020-11-19 00:33:06 +04:00
|
|
|
.incbin "{2}{1}.bin"
|
2022-01-22 02:21:32 +04:00
|
|
|
app_{0}_end:"#,
|
|
|
|
idx, app, TARGET_PATH
|
|
|
|
)?;
|
2020-11-18 14:29:53 +04:00
|
|
|
}
|
|
|
|
Ok(())
|
2022-01-22 02:21:32 +04:00
|
|
|
}
|