File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments