Next Generation WASM Microkernel Operating System
1// Copyright 2025 Jonas Kruckenberg
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8use std::env;
9use std::path::{Path, PathBuf};
10
11fn main() {
12 let workspace_root = env::var_os("__K23_CARGO_RUSTC_CURRENT_DIR").map(PathBuf::from);
13
14 println!("cargo::rerun-if-env-changed=KERNEL");
15 if let (Some(workspace_root), Some(kernel)) = (workspace_root, env::var_os("KERNEL")) {
16 let kernel = workspace_root.join(kernel);
17 println!("cargo::rerun-if-changed={}", kernel.display());
18 println!("cargo::rustc-env=KERNEL={}", kernel.display());
19 }
20
21 copy_linker_script();
22}
23
24fn copy_linker_script() {
25 use std::{fs::File, io::Write};
26
27 let out_dir = env::var("OUT_DIR").unwrap();
28 let dest_path = Path::new(&out_dir);
29 let mut f = File::create(dest_path.join("link.ld")).unwrap();
30 f.write_all(include_bytes!("./riscv64-qemu.ld")).unwrap();
31
32 println!("cargo:rustc-link-search={}", dest_path.display());
33 println!("cargo:rustc-link-arg=-Tlink.ld");
34}