Skip to content

Commit 1b3af0e

Browse files
committed
Update for extra-link-arg (rust-lang/cargo#8441)
1 parent 846e526 commit 1b3af0e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

gd32vf103-hal/build.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Ref: Sha Miao, rv32m1_ri5cy-example/build.rs
2+
3+
use std::env;
4+
use std::fs;
5+
use std::path::PathBuf;
6+
7+
const MISSING_CARGO_ENV: &str = "Missing environment variables provided by Cargo.";
8+
9+
/// Include `.a` files generated by assembly codes
10+
fn include_a_files(out_dir: &str) {
11+
let target = env::var("TARGET").expect(MISSING_CARGO_ENV);
12+
let out_dir = PathBuf::from(out_dir);
13+
let name = env::var("CARGO_PKG_NAME").expect(MISSING_CARGO_ENV);
14+
15+
if &target == "riscv32imac-unknown-none-elf" {
16+
fs::copy(
17+
format!("bin/{}.a", target),
18+
out_dir.join(format!("lib{}.a", name)),
19+
)
20+
.unwrap();
21+
22+
println!("cargo:rustc-link-lib=static={}", name);
23+
println!("cargo:rustc-link-search={}", out_dir.display());
24+
println!("cargo:rerun-if-changed=bin/{}.a", target);
25+
}
26+
}
27+
28+
fn linker_script() {
29+
println!("cargo:rustc-link-arg-bins=-Tmemory.x");
30+
println!("cargo:rustc-link-arg-bins=-Tlink.x");
31+
}
32+
33+
/// Build script for the crate.
34+
fn main() {
35+
let out_dir = env::var("OUT_DIR").expect(MISSING_CARGO_ENV);
36+
include_a_files(&out_dir);
37+
linker_script();
38+
println!("cargo:rerun-if-changed=build.rs");
39+
}

0 commit comments

Comments
 (0)