Remove the need for a linker script and move multiboot to a feature

This commit is contained in:
Gwilym Inzani 2023-10-18 09:50:18 +01:00
parent 0e0cc6f909
commit eff075f50b
2 changed files with 16 additions and 1 deletions

View file

@ -10,6 +10,7 @@ repository = "https://github.com/agbrs/agb"
[features]
default = ["testing"]
testing = []
multiboot = []
[dependencies]
bitflags = "2"

View file

@ -1,5 +1,19 @@
fn main() {
use std::{env, error::Error, fs, path::PathBuf};
fn main() -> Result<(), Box<dyn Error>> {
let out = &PathBuf::from(env::var("OUT_DIR").unwrap());
let linker_script = if env::var("CARGO_FEATURE_MULTIBOOT").is_ok() {
include_bytes!("gba_mb.ld").as_slice()
} else {
include_bytes!("gba.ld").as_slice()
};
fs::write(out.join("gba.ld"), linker_script)?;
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=gba.ld");
println!("cargo:rerun-if-changed=gba_mb.ld");
println!("cargo:rerun-if-changed=build.rs");
Ok(())
}