You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
970 B
34 lines
970 B
4 years ago
|
use std::io::{Result, Write};
|
||
|
use std::fs::{File, read_dir};
|
||
|
|
||
|
fn main() {
|
||
|
println!("cargo:rerun-if-changed=../user");
|
||
|
insert_app_data().unwrap();
|
||
|
}
|
||
|
|
||
|
static TARGET_PATH: &'static str = "../user/target/riscv64gc-unknown-none-elf/release/";
|
||
|
|
||
|
fn insert_app_data() -> Result<()> {
|
||
|
let mut f = File::create("src/link_app.S").unwrap();
|
||
|
let apps: Vec<_> = read_dir("../user/src/bin")
|
||
|
.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();
|
||
|
|
||
|
for (idx, app_with_extension) in apps.iter().enumerate() {
|
||
|
writeln!(f, r#"
|
||
|
.section .data
|
||
|
.global app_{0}_start
|
||
|
.global app_{0}_end
|
||
|
app_{0}_start:
|
||
|
.incbin "{2}{1}"
|
||
|
app_{0}_end:
|
||
|
"#, idx, app_with_extension, TARGET_PATH)?;
|
||
|
}
|
||
|
Ok(())
|
||
|
}
|