-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
47 lines (36 loc) · 1.33 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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
fn var(s: &str) -> String { std::env::var(s).unwrap() }
fn cwd() -> std::path::PathBuf { std::env::current_dir().unwrap() }
fn assemble_and_link<P: AsRef<std::path::Path>>(s: P) {
let s = s.as_ref();
cc::Build::new()
// CC doesn't know the thumbv4t-none-eabi target.
.compiler("arm-none-eabi-gcc")
.archiver("arm-none-eabi-ar")
.no_default_flags(true)
.include("gba-minrt/rt")
.flag("-xassembler")
.flag("-mcpu=arm7tdmi")
.flag("-mthumb-interwork")
.file(&s)
.compile("minrt");
println!("cargo:rerun-if-changed={}", s.display());
}
const MINRT_PATH: &str = "gba-minrt/rt";
fn main() {
let crt0 = format!("{}/rsrt0.s", MINRT_PATH);
let ld = format!("{}/rom.ld", MINRT_PATH);
let out = var("OUT_DIR");
assemble_and_link(crt0);
std::fs::copy(
&ld,
format!("{}/link.x", &out)).unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={}", &ld);
println!("cargo:rustc-link-search={}", &out);
println!("cargo:rustc-link-search={}/{}", cwd().display(), MINRT_PATH);
}