forked from stm32-rs/stm32l0xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
70 lines (54 loc) · 2.1 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
69
70
use std::env;
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let mut feature_count = 0;
if cfg!(feature = "stm32l0x1") {
feature_count += 1;
}
if cfg!(feature = "stm32l0x2") {
feature_count += 1;
}
if cfg!(feature = "stm32l0x3") {
feature_count += 1;
}
if feature_count != 1 {
panic!("\n\nMust select exactly one package for linker script generation!\nChoices: 'stm32l0x1' or 'stm32l0x2' or 'stm32l0x3'\nAlternatively, pick the mcu-feature that matches your MCU, for example 'mcu-STM32L071KBTx'\n\n");
}
if !cfg!(feature = "disable-linker-script") {
let linker = if cfg!(feature = "stm32l0x1") {
include_bytes!("memory_l0x1.x").as_ref()
} else if cfg!(feature = "stm32l0x2") {
include_bytes!("memory_l0x2.x").as_ref()
} else if cfg!(feature = "stm32l0x3") {
include_bytes!("memory_l0x3.x").as_ref()
} else {
unreachable!();
};
File::create(out.join("memory.x"))
.unwrap()
.write_all(linker)
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=memory_l0x1.x");
println!("cargo:rerun-if-changed=memory_l0x2.x");
println!("cargo:rerun-if-changed=memory_l0x3.x");
}
println!("cargo:rerun-if-changed=build.rs");
// Copy the binary blob required by the Flash API somewhere the linker can
// find it, and tell Cargo to link it.
let blob_name = "flash";
let blob_file = format!("lib{}.a", blob_name);
let blob_path = format!("flash-code/{}", blob_file);
fs::copy(
&blob_path,
out.join(format!("{}", blob_file)),
)
.expect("Failed to copy binary blob for Flash API");
println!("cargo:rustc-link-lib=static={}", blob_name);
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed={}", blob_path);
}