File tree Expand file tree Collapse file tree 2 files changed +23
-11
lines changed
Expand file tree Collapse file tree 2 files changed +23
-11
lines changed Original file line number Diff line number Diff line change 1+ use std:: env;
2+
13fn main ( ) {
24 built:: write_built_file ( ) . expect ( "Failed to acquire build-time information" ) ;
5+
6+ set_linker_script ( ) ;
7+ }
8+
9+ fn set_linker_script ( ) {
10+ let cfg_target_arch = env:: var ( "CARGO_CFG_TARGET_ARCH" ) . unwrap ( ) ;
11+ let cfg_feature = env:: var ( "CARGO_CFG_FEATURE" ) . unwrap ( ) ;
12+
13+ let linker_script = match cfg_target_arch. as_str ( ) {
14+ "aarch64" if cfg_feature. contains ( "elf" ) => "link.ld" ,
15+ "riscv64" if cfg_feature. contains ( "sbi" ) => "link.ld" ,
16+ "x86_64" if cfg_feature. contains ( "linux" ) => "platform/linux/link.ld" ,
17+ "x86_64" if cfg_feature. contains ( "multiboot" ) => "platform/multiboot/link.ld" ,
18+ _ => return ,
19+ } ;
20+
21+ let linker_script = format_args ! ( "src/arch/{cfg_target_arch}/{linker_script}" ) ;
22+ println ! ( "cargo:rerun-if-changed={linker_script}" ) ;
23+ println ! ( "cargo:rustc-link-arg=-T{linker_script}" ) ;
324}
Original file line number Diff line number Diff line change @@ -74,17 +74,8 @@ impl Target {
7474
7575 pub fn rustflags ( & self ) -> & ' static [ & ' static str ] {
7676 match self {
77- Self :: X86_64Linux => & [
78- "-Clink-arg=-Tsrc/arch/x86_64/platform/linux/link.ld" ,
79- "-Crelocation-model=static" ,
80- ] ,
81- Self :: X86_64Multiboot => & [
82- "-Clink-arg=-Tsrc/arch/x86_64/platform/multiboot/link.ld" ,
83- "-Crelocation-model=static" ,
84- ] ,
85- Self :: X86_64Uefi => & [ ] ,
86- Self :: Aarch64Elf | Self :: Aarch64BeElf => & [ "-Clink-arg=-Tsrc/arch/aarch64/link.ld" ] ,
87- Self :: Riscv64Sbi => & [ "-Clink-arg=-Tsrc/arch/riscv64/link.ld" ] ,
77+ Self :: X86_64Linux | Self :: X86_64Multiboot => & [ "-Crelocation-model=static" ] ,
78+ _ => & [ ] ,
8879 }
8980 }
9081
You can’t perform that action at this time.
0 commit comments