forked from 0xA54/wex-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
63 lines (56 loc) · 2.2 KB
/
build.rs
File metadata and controls
63 lines (56 loc) · 2.2 KB
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
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
download_cyw43_firmware();
// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}
fn download_cyw43_firmware() {
let download_folder = "cyw43-firmware";
let url_base = "https://github.com/embassy-rs/embassy/raw/refs/heads/main/cyw43-firmware";
let file_names = [
"43439A0.bin",
"43439A0_btfw.bin",
"43439A0_clm.bin",
"LICENSE-permissive-binary-license-1.0.txt",
"README.md",
];
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={}", download_folder);
std::fs::create_dir_all(download_folder).expect("Failed to create download directory");
// download each file into the folder "cyw43-firmware"
for file in file_names {
let url = format!("{}/{}", url_base, file);
// only fetch if it doesn't exist
if std::path::Path::new(download_folder).join(file).exists() {
continue;
}
match reqwest::blocking::get(&url) {
Ok(response) => {
let content = response.bytes().expect("Failed to read file content");
let file_path = PathBuf::from(download_folder).join(file);
std::fs::write(file_path, &content).expect("Failed to write file");
}
Err(err) => panic!(
"Failed to download the cyw43 firmware from {}: {}, required for pi-pico-w example",
url, err
),
}
}
}