-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.rs
33 lines (27 loc) · 1 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
// Ref: Sha Miao, rv32m1_ri5cy-example/build.rs
use std::env;
use std::fs;
use std::path::PathBuf;
const MISSING_CARGO_ENV: &str = "Missing environment variables provided by Cargo.";
/// Include `.a` files generated by assembly codes
fn include_a_files(out_dir: &str) {
let target = env::var("TARGET").expect(MISSING_CARGO_ENV);
let out_dir = PathBuf::from(out_dir);
let name = env::var("CARGO_PKG_NAME").expect(MISSING_CARGO_ENV);
if &target == "riscv32imac-unknown-none-elf" {
fs::copy(
format!("bin/{}.a", target),
out_dir.join(format!("lib{}.a", name)),
)
.unwrap();
println!("cargo:rustc-link-lib=static={}", name);
println!("cargo:rustc-link-search={}", out_dir.display());
println!("cargo:rerun-if-changed=bin/{}.a", target);
}
}
/// Build script for the crate.
fn main() {
let out_dir = env::var("OUT_DIR").expect(MISSING_CARGO_ENV);
include_a_files(&out_dir);
println!("cargo:rerun-if-changed=build.rs");
}