forked from rust-osdev/bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
68 lines (62 loc) · 1.85 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
use std::{env, fs, path::Path};
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("concat.rs");
let combinations = [
(1, 8),
(1, 9),
(2, 1),
(2, 2),
(4, 3),
(16, 7),
(23, 8),
(31, 9),
(40, 9),
(49, 9),
(58, 10),
(68, 10),
(78, 1),
(79, 9),
(88, 9),
(97, 9),
(106, 9),
(115, 9),
];
let mut code = String::new();
for (i, j) in combinations {
code += &format!(
"pub const fn concat_{i}_{j}(a: [u8; {i}], b: [u8; {j}]) -> [u8; {i} + {j}] {{
[{a}, {b}]
}}",
i = i,
j = j,
a = (0..i)
.map(|idx| format!("a[{idx}]"))
.collect::<Vec<_>>()
.join(","),
b = (0..j)
.map(|idx| format!("b[{idx}]"))
.collect::<Vec<_>>()
.join(","),
);
}
fs::write(dest_path, code).unwrap();
println!("cargo:rerun-if-changed=build.rs");
let version_major: u16 = env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap();
let version_minor: u16 = env!("CARGO_PKG_VERSION_MINOR").parse().unwrap();
let version_patch: u16 = env!("CARGO_PKG_VERSION_PATCH").parse().unwrap();
let pre_release: bool = !env!("CARGO_PKG_VERSION_PRE").is_empty();
fs::write(
Path::new(&out_dir).join("version_info.rs"),
format!(
"
pub const VERSION_MAJOR: u16 = {version_major};
pub const VERSION_MINOR: u16 = {version_minor};
pub const VERSION_PATCH: u16 = {version_patch};
pub const VERSION_PRE: bool = {pre_release};
"
),
)
.unwrap();
println!("cargo:rerun-if-changed=Cargo.toml");
}