Files
Embedded-Hacking/drivers/0x0c_multicore_rust/build.rs
2026-03-27 11:19:24 -04:00

61 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! SPDX-License-Identifier: MIT OR Apache-2.0
//!
//! Copyright (c) 20212024 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 f = File::create(out.join("memory.x")).unwrap();
f.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 f = File::create(out.join("memory.x")).unwrap();
f.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 f = File::create(".cargo/config.toml").unwrap();
f.write_all(result.as_bytes()).unwrap();
let rp2350_riscv_x = include_bytes!("rp2350_riscv.x");
let mut f = File::create(out.join("rp2350_riscv.x")).unwrap();
f.write_all(rp2350_riscv_x).unwrap();
println!("cargo:rerun-if-changed=rp2350_riscv.x");
println!("cargo:rerun-if-changed=build.rs");
}