mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-04-01 09:00:18 +02:00
61 lines
2.1 KiB
Rust
61 lines
2.1 KiB
Rust
//! SPDX-License-Identifier: MIT OR Apache-2.0
|
|
//!
|
|
//! Copyright (c) 2021-2024 The rp-rs Developers
|
|
//! Copyright (c) 2021 rp-rs organization
|
|
//! Copyright (c) 2025 Raspberry Pi Ltd.
|
|
//!
|
|
//! Set up linker scripts
|
|
|
|
use std::fs::{File, read_to_string};
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
|
|
use regex::Regex;
|
|
|
|
fn main() {
|
|
println!("cargo::rustc-check-cfg=cfg(rp2040)");
|
|
println!("cargo::rustc-check-cfg=cfg(rp2350)");
|
|
|
|
let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
|
println!("cargo:rustc-link-search={}", out.display());
|
|
|
|
println!("cargo:rerun-if-changed=.pico-rs");
|
|
let contents = read_to_string(".pico-rs")
|
|
.map(|s| s.trim().to_string().to_lowercase())
|
|
.unwrap_or_else(|_| String::new());
|
|
|
|
let target;
|
|
if contents == "rp2040" {
|
|
target = "thumbv6m-none-eabi";
|
|
let memory_x = include_bytes!("rp2040.x");
|
|
let mut file = File::create(out.join("memory.x")).unwrap();
|
|
file.write_all(memory_x).unwrap();
|
|
println!("cargo::rustc-cfg=rp2040");
|
|
println!("cargo:rerun-if-changed=rp2040.x");
|
|
} else {
|
|
if contents.contains("riscv") {
|
|
target = "riscv32imac-unknown-none-elf";
|
|
} else {
|
|
target = "thumbv8m.main-none-eabihf";
|
|
}
|
|
let memory_x = include_bytes!("rp2350.x");
|
|
let mut file = File::create(out.join("memory.x")).unwrap();
|
|
file.write_all(memory_x).unwrap();
|
|
println!("cargo::rustc-cfg=rp2350");
|
|
println!("cargo:rerun-if-changed=rp2350.x");
|
|
}
|
|
|
|
let re = Regex::new(r"target = .*").unwrap();
|
|
let config_toml = include_str!(".cargo/config.toml");
|
|
let result = re.replace(config_toml, format!("target = \"{}\"", target));
|
|
let mut file = File::create(".cargo/config.toml").unwrap();
|
|
file.write_all(result.as_bytes()).unwrap();
|
|
|
|
let rp2350_riscv_x = include_bytes!("rp2350_riscv.x");
|
|
let mut file = File::create(out.join("rp2350_riscv.x")).unwrap();
|
|
file.write_all(rp2350_riscv_x).unwrap();
|
|
println!("cargo:rerun-if-changed=rp2350_riscv.x");
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
}
|