Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
38 lines (35 loc) · 1.56 KB
/
Copy pathbuild.rs
File metadata and controls
38 lines (35 loc) · 1.56 KB
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
use time::OffsetDateTime;
use time::macros::format_description;
fn main() {
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let linker_script = match std::env::var("CARGO_CFG_TARGET_ARCH") {
Ok(arch) if arch == "aarch64" => {
let src = "./src/arch/arm64/boot/linker.ld";
let dst = out_dir.join("linker_preprocessed.ld");
// Run CPP: -E (preprocess), -P (no line markers), -x c (treat as C)
std::process::Command::new("cc")
.args(["-E", "-P", "-x", "c", src, "-o"])
.arg(&dst)
.status().unwrap();
dst
},
Ok(arch) => {
println!("Unsupported arch: {arch}");
std::process::exit(1);
}
Err(_) => unreachable!("Cargo should always set the arch"),
};
println!("cargo::rerun-if-changed=./src/arch/arm64/boot/linker.ld");
println!("cargo::rerun-if-changed=./src/arch/arm64/boot/linux-kernel-image-header-vars.h");
println!("cargo::rustc-link-arg=-T{}", linker_script.display());
// Set an environment variable with the date and time of the build
let now = OffsetDateTime::now_utc();
let format = format_description!(
"[weekday repr:short] [month repr:short] [day] [hour]:[minute]:[second] UTC [year]"
);
let timestamp = now.format(&format).unwrap();
#[cfg(feature = "smp")]
println!("cargo:rustc-env=MOSS_VERSION=#1 Moss SMP {timestamp}");
#[cfg(not(feature = "smp"))]
println!("cargo:rustc-env=MOSS_VERSION=#1 Moss {timestamp}");
}