Files
moss-kernel/build.rs
Andrew Mackenzie b142fb74ec Merge pull request #227 from andrewdavidmackenzie/master
Rework uname to avoid hardcoded datetime and add unit tests

Restructure `uname` so that:
- there is an internal function that does the main logic and can be tested by unit tests
- Generate an env var in build.rs that is the actual build datetime timestamp
- Avoid hardcoded date in the version string
- Use the timestamp in the building of `uname` response, so the data is the actual build time
- add a simple unit test for the sysname field
- add more complex test for the version field that checks the date formatting (not exhaustively)

NOTE: The build timestamp can be used by any other function, syscall or part of the code if required.
2026-02-20 14:23:59 -08:00

29 lines
1.1 KiB
Rust

use std::path::PathBuf;
use time::OffsetDateTime;
use time::macros::format_description;
fn main() {
let linker_script = match std::env::var("CARGO_CFG_TARGET_ARCH") {
Ok(arch) if arch == "aarch64" => PathBuf::from("./src/arch/arm64/boot/linker.ld"),
Ok(arch) => {
println!("Unsupported arch: {arch}");
std::process::exit(1);
}
Err(_) => unreachable!("Cargo should always set the arch"),
};
println!("cargo::rerun-if-changed={}", linker_script.display());
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}");
}