-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
49 lines (42 loc) · 1.59 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
use std::fs;
use std::io::Write;
use std::process::Command;
extern crate svd2rust;
fn main() {
println!("cargo:rerun-if-changed=5a-75e_6.0.svd");
let svd = String::from_utf8(include_bytes!("5a-75e_6.0.svd").to_vec())
.expect("svd file wasn't valid utf8");
// Generate config for riscv target
let mut config = svd2rust::Config::default();
config.target = svd2rust::Target::RISCV;
// Generate the svd file to a string in RAM
let pac_file = svd2rust::generate(&svd, &config).expect("couldn't generate file with svd2rust");
// This appears to be what they do inside svd2rust:main.rs
let lib_rs = pac_file.lib_rs.replace("] ", "]\n");
// These strings are generated by svd2rust. Remove them to silence warnings.
let bad_strings = [
"# ! [ deny ( legacy_directory_ownership ) ]",
"# ! [ deny ( plugin_as_library ) ]",
"# ! [ deny ( safe_extern_statics ) ]",
"# ! [ deny ( unions_with_drop_fields ) ]",
"#![no_main]",
"# ! [ no_std ]",
];
let mut out_file = fs::File::create("src/lib.rs").expect("couldn't open output file");
for line in lib_rs.lines() {
if bad_strings.contains(&line) {
println!("Found bad string, skipping");
continue;
}
out_file
.write(line.as_bytes())
.expect("couldn't write line to lib.rs");
out_file
.write(b"\n")
.expect("couldn't write line ending to lib.rs");
}
Command::new("rustfmt")
.arg("src/lib.rs")
.spawn()
.expect("Could not rustfmt sources");
}