2021-10-19 13:36:41 +00:00
|
|
|
//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs
|
|
|
|
use std::env;
|
|
|
|
use std::fs::File;
|
2022-06-12 20:15:44 +00:00
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::io::{self};
|
2021-10-19 13:36:41 +00:00
|
|
|
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> {
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
println!("cargo:rerun-if-changed=memory.x");
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
2021-11-07 22:52:11 +00:00
|
|
|
println!("cargo:rustc-link-arg-bins=--nmagic");
|
|
|
|
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
|
|
|
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
|
|
|
|
2021-10-19 13:36:41 +00:00
|
|
|
Ok(())
|
|
|
|
}
|