arceos-helloworld 0.2.2

A simple helloworld crate (from crates.io) for ArceOS
use std::path::PathBuf;

fn main() {
    // The linker script is generated by axhal's build.rs at:
    //   target/<target_triple>/<profile>/linker_<platform>.lds
    // We can locate it relative to OUT_DIR:
    //   OUT_DIR = target/<triple>/<profile>/build/<pkg>-<hash>/out
    //   ../../.. from OUT_DIR = target/<triple>/<profile>/
    let out_dir = std::env::var("OUT_DIR").unwrap();
    let profile_dir = PathBuf::from(&out_dir).join("../../..");
    let profile_dir = std::fs::canonicalize(&profile_dir)
        .unwrap_or_else(|_| PathBuf::from(&out_dir).join("../../.."));

    let platform = "riscv64-qemu-virt";
    let lds_path = profile_dir.join(format!("linker_{platform}.lds"));

    println!("cargo:rustc-link-arg=-T{}", lds_path.display());
    println!("cargo:rustc-link-arg=-no-pie");
    println!("cargo:rustc-link-arg=-znostart-stop-gc");
}