27 lines
1.1 KiB
Rust
27 lines
1.1 KiB
Rust
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let ld = std::path::Path::new("linker.ld").canonicalize().unwrap();
|
|
println!("cargo:rustc-link-arg=-T{}", ld.display());
|
|
println!("cargo:rerun-if-changed=linker.ld");
|
|
|
|
// Init and storage are packed into the kernel image: they are what
|
|
// reads the disk, so they cannot come from it. `make build` builds them
|
|
// first; without them the image boots to "init missing".
|
|
let manifest = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
|
|
let bins = manifest.join("../../target/riscv64gc-unknown-none-elf/release");
|
|
let out = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
|
for (var, bin) in [("KOS_INIT_ELF", "init"), ("KOS_STORAGE_ELF", "storage-qemu")] {
|
|
let path = bins.join(bin);
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
let path = if path.is_file() {
|
|
path
|
|
} else {
|
|
let empty = out.join(bin);
|
|
std::fs::write(&empty, []).unwrap();
|
|
empty
|
|
};
|
|
println!("cargo:rustc-env={}={}", var, path.display());
|
|
}
|
|
}
|