xous-core/kernel/build.rs
Jean-Pierre De Jesus DIAZ 955fbc8788
xous: Use CARGO_CFG_TARGET_OS in build scripts.
This allows for a more reliable detection of target_os configuration
in build scripts. The target is inconsistent between some architectures,
notably armv7a is `armv7a-none-eabi` skipping the `unknown` (the vendor,
I guess) part. This happen with some of the unrelated Cortex-M targets
present, and others may also be.

Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2022-10-12 19:03:46 +02:00

56 lines
1.9 KiB
Rust

// SPDX-FileCopyrightText: 2020 Sean Cross <sean@xobs.io>
// SPDX-License-Identifier: Apache-2.0
// 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 target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let name = env::var("CARGO_PKG_NAME").unwrap();
// If we're not running on a desktop-class operating system, emit the "baremetal"
// config setting. This will enable software to do tasks such as
// managing memory.
if target_os == "none" || target_os == "xous" {
println!("Target {} is bare metal", target);
println!("cargo:rustc-cfg=baremetal");
} else {
println!("Target {} is NOT bare metal", target);
}
// For RISC-V, link in the startup library.
if target.starts_with("riscv") {
fs::copy(
format!("bin/{}.a", target),
out_dir.join(format!("lib{}.a", name)),
)
.unwrap();
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");
// Put the linker script somewhere the linker can find it
fs::File::create(out_dir.join("link.x"))
.unwrap()
.write_all(include_bytes!("link.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out_dir.display());
println!("cargo:rerun-if-changed=link.x");
println!("cargo:rustc-link-arg=-Map=kernel.map");
}
println!("cargo:rerun-if-changed=build.rs");
// CI sets this variable. This changes how the panic handler works.
println!("cargo:rerun-if-env-changed=CI");
if option_env!("CI").is_some() {
println!("cargo:rustc-cfg=ci");
}
}