-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
43 lines (34 loc) · 985 Bytes
/
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
use std::env;
use std::fs;
use std::path::Path;
use proc_macro2::TokenStream;
use quote::quote;
fn main() {
let croak = small_morse::encode("croak")
.map(|c| {
let duration = c.duration;
let on = c.state == small_morse::State::On;
quote! {
Morse { duration: #duration, on: #on }
}
})
.collect::<Vec<_>>();
let croak_len = croak.len();
let mut g = TokenStream::new();
g.extend(quote! {
#[derive(Copy, Clone)]
pub struct Morse {
pub duration: u8,
pub on: bool,
}
const CROAK_C: [Morse; #croak_len] = [
#(#croak),*
];
avr_progmem::progmem! {
pub static progmem CROAK: [Morse; #croak_len] = CROAK_C;
}
});
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("croak.rs");
fs::write(&dest_path, g.to_string()).unwrap();
}