-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathmain.rs
40 lines (31 loc) · 1.34 KB
/
main.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
use gen_target_info::{get_target_specs_from_json, write_target_tuple_mapping, RustcTargetSpecs};
use std::{fs::File, io::Write as _};
const PRELUDE: &str = r#"//! This file is generated code. Please edit the generator
//! in dev-tools/gen-target-info if you need to make changes.
"#;
fn generate_riscv_arch_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
let mut riscv_target_mapping = target_specs
.0
.iter()
.filter_map(|(target, target_spec)| {
let arch = target.split_once('-').unwrap().0;
(arch.contains("riscv") && arch != target_spec.arch)
.then_some((arch, &*target_spec.arch))
})
.collect::<Vec<_>>();
riscv_target_mapping.sort_unstable_by_key(|(arch, _)| &**arch);
riscv_target_mapping.dedup();
write_target_tuple_mapping(f, "RISCV_ARCH_MAPPING", &riscv_target_mapping);
}
fn main() {
let target_specs = get_target_specs_from_json();
// Open file to write to
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let path = format!("{manifest_dir}/../../src/target_info.rs");
let mut f = File::create(path).expect("failed to create src/target_info.rs");
f.write_all(PRELUDE.as_bytes()).unwrap();
// Start generating
generate_riscv_arch_mapping(&mut f, &target_specs);
// Flush the data onto disk
f.flush().unwrap();
}