-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathbuild.rs
More file actions
59 lines (49 loc) · 2.13 KB
/
build.rs
File metadata and controls
59 lines (49 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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 and ARM, link in the startup library.
if target.starts_with("riscv") || target.starts_with("arm") {
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");
let linker_file_path = if target.starts_with("arm") {
PathBuf::from("src/arch/arm/link.x")
} else {
PathBuf::from("link.x")
};
// Put the linker script somewhere the linker can find it
fs::File::create(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=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");
}
}