-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
51 lines (41 loc) · 1.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
//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::{self};
use std::path::PathBuf;
#[derive(Debug)]
enum Error {
Env(env::VarError),
Io(io::Error),
}
impl From<env::VarError> for Error {
fn from(error: env::VarError) -> Self {
Self::Env(error)
}
}
impl From<io::Error> for Error {
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
fn main() -> Result<(), Error> {
let mut config = prost_build::Config::new();
config.btree_map(&["."]);
config
.compile_protos(&["src/messages.proto"], &["src/"])
.unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rerun-if-changed=src/messages.proto");
let out_dir = env::var("OUT_DIR")?;
let out_dir = PathBuf::from(out_dir);
let memory_x = include_bytes!("memory.x").as_ref();
File::create(out_dir.join("memory.x"))?.write_all(memory_x)?;
// Tell Cargo where to find the file.
println!("cargo:rustc-link-search={}", out_dir.display());
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
Ok(())
}