2021-01-25 13:54:00 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020 Sean Cross <sean@xobs.io>
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
2020-03-10 04:04:17 +00:00
|
|
|
// 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 name = env::var("CARGO_PKG_NAME").unwrap();
|
|
|
|
|
|
2020-06-03 07:34:55 +00:00
|
|
|
let target_os = target.split('-').nth(2).unwrap_or("none");
|
|
|
|
|
|
|
|
|
|
// 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.
|
2021-08-18 10:14:24 +00:00
|
|
|
if target_os == "none" || target_os == "xous" {
|
2020-06-03 07:34:55 +00:00
|
|
|
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.
|
2020-03-10 04:04:17 +00:00
|
|
|
if target.starts_with("riscv") {
|
|
|
|
|
fs::copy(
|
|
|
|
|
format!("bin/{}.a", target),
|
|
|
|
|
out_dir.join(format!("lib{}.a", name)),
|
2020-06-03 07:34:55 +00:00
|
|
|
)
|
|
|
|
|
.unwrap();
|
2020-03-10 04:04:17 +00:00
|
|
|
|
|
|
|
|
println!("cargo:rustc-link-lib=static={}", name);
|
|
|
|
|
println!("cargo:rustc-link-search={}", out_dir.display());
|
|
|
|
|
println!("cargo:rerun-if-changed=bin/{}.a", target);
|
2022-01-14 07:31:36 +00:00
|
|
|
println!("cargo:rustc-link-arg=-Tlink.x");
|
2020-03-10 04:04:17 +00:00
|
|
|
|
2020-06-03 07:34:55 +00:00
|
|
|
// 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");
|
2022-01-17 16:32:12 +00:00
|
|
|
println!("cargo:rustc-link-arg=-Map=kernel.map");
|
2020-06-03 07:34:55 +00:00
|
|
|
}
|
2020-03-10 04:04:17 +00:00
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
2021-06-21 12:05:24 +00:00
|
|
|
|
|
|
|
|
// CI sets this variable. This changes how the panic handler works.
|
|
|
|
|
println!("cargo:rerun-if-env-changed=CI");
|
|
|
|
|
if option_env!("CI").is_some() {
|
2022-05-26 15:53:33 +00:00
|
|
|
println!("cargo:rustc-cfg=ci");
|
2021-06-21 12:05:24 +00:00
|
|
|
}
|
2020-03-10 04:04:17 +00:00
|
|
|
}
|