xous-core/loader/build.rs
bunnie 1255bf12d9 FLAG DAY: fix all names to harmonize around 'bao1x'
The code base had evolved through several code names, interim
names, company names and chip names that alternatively did or did
not exist.

Baochip is the definitive name of the company, and the Baochip1x
(full part number BAO1X2S4F-WA) is the definitivey part number of
the SoC. For convenience, the part number is shortened to 'bao1x'
in most feature flags and variable references.

This commit fixes all of the odd names and removes some unmaintained
early targets.
2025-09-18 21:25:51 +08:00

52 lines
1.8 KiB
Rust

// NOTE: Adapted from cortex-m/build.rs
use std::env;
use std::fs;
use std::io::Write;
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let target = env::var("TARGET").unwrap();
let linker_file_path = if target.starts_with("riscv") {
println!("cargo:rustc-link-search={}", out_dir.display());
#[cfg(feature = "bao1x")]
let p = PathBuf::from("src/platform/bao1x/link.x");
#[cfg(not(any(feature = "bao1x")))]
let p = PathBuf::from("src/platform/precursor/link.x");
println!("cargo:rerun-if-changed={}", p.clone().into_os_string().into_string().unwrap());
println!("cargo:rustc-link-arg=-Tlink.x");
p
} else if target.starts_with("armv7a") {
let name = env::var("CARGO_PKG_NAME").unwrap();
fs::copy(format!("bin/{}.a", target), out_dir.join(format!("lib{}.a", name)))
.expect("copy arm assembly binary");
println!("cargo:rustc-link-lib=static={}", name);
println!("cargo:rustc-link-search={}", out_dir.display());
println!("cargo:rerun-if-changed=bin/{}.a", target);
println!("cargo:rustc-link-arg=-Tlink.x");
PathBuf::from("src/platform/atsama5d27/link.x")
} else {
unreachable!("unsupported target");
};
println!("{}", out_dir.join("link.x").display());
// Put the linker script somewhere the linker can find it
std::fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(out_dir.join("link.x"))
.unwrap()
.write_all(fs::read_to_string(linker_file_path).expect("linker file read").as_bytes())
.unwrap();
println!("cargo:rustc-link-search={}", out_dir.display());
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=link.x");
}