-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
76 lines (71 loc) · 2.29 KB
/
build.rs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::env::var;
use std::fs;
use std::io::{Result, Write};
use std::path::Path;
struct ConfigPlatform {
platform: &'static str,
vm0_image_path: &'static str,
max_core_num: usize,
}
impl ConfigPlatform {
fn gen_config_rs(&self) -> Result<Vec<u8>> {
let mut output = vec![];
writeln!(
output,
"pub const {variable}: {var_type} = {value};",
variable = stringify!(CORE_NUM),
var_type = stringify!(usize),
value = self.max_core_num
)?;
Ok(output)
}
}
const fn get_config() -> ConfigPlatform {
if cfg!(feature = "tx2") {
ConfigPlatform {
platform: "tx2",
vm0_image_path: "image/L4T",
max_core_num: 4,
}
} else if cfg!(feature = "pi4") {
ConfigPlatform {
platform: "pi4",
vm0_image_path: "image/Image_pi4_5.4.83_tlb",
max_core_num: 4,
}
} else if cfg!(feature = "qemu") {
ConfigPlatform {
platform: "qemu",
vm0_image_path: "image/Image_vanilla",
max_core_num: 8,
}
} else {
panic!("Unsupported platform!");
}
}
fn main() -> Result<()> {
// set the linker script
let arch = var("CARGO_CFG_TARGET_ARCH").unwrap();
println!("cargo:rustc-link-arg=-Tlinkers/{arch}.ld");
let config = get_config();
println!("cargo:rustc-link-arg=--defsym=TEXT_START={}", env!("TEXT_START"));
// set config file
let out_dir = var("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir).join("config.rs");
println!("Generating config file: {}", out_path.display());
let config_rs = config.gen_config_rs()?;
fs::write(out_path, config_rs)?;
// set envs
let build_time = chrono::offset::Local::now().format("%Y-%m-%d %H:%M:%S %Z");
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
let hostname = gethostname::gethostname();
println!("cargo:rustc-env=HOSTNAME={}", hostname.into_string().unwrap());
built::write_built_file().expect("Failed to acquire build-time information");
println!(
"cargo:rustc-env=VM0_IMAGE_PATH={}/{}",
env!("CARGO_MANIFEST_DIR"),
config.vm0_image_path
);
println!("cargo:rustc-env=PLATFORM={}", config.platform.to_uppercase());
Ok(())
}