xref: /DragonBoot/build-scripts/dragon_boot_build/src/cfiles/arch/mod.rs (revision 0ec3a34a58ffc0a9c51a23a7ee5e7d803a0060cd)
1*0ec3a34aSLoGin use std::path::PathBuf;
2*0ec3a34aSLoGin 
3*0ec3a34aSLoGin use cc::Build;
4*0ec3a34aSLoGin 
5*0ec3a34aSLoGin use crate::utils::cargo_handler::{CargoHandler, TargetArch};
6*0ec3a34aSLoGin 
7*0ec3a34aSLoGin pub mod riscv64;
8*0ec3a34aSLoGin 
9*0ec3a34aSLoGin pub(super) trait CFilesArch {
10*0ec3a34aSLoGin     /// 设置架构相关的宏定义
setup_defines(&self, c: &mut Build)11*0ec3a34aSLoGin     fn setup_defines(&self, c: &mut Build);
12*0ec3a34aSLoGin     /// 设置架构相关的全局包含目录
setup_global_include_dir(&self, c: &mut Build)13*0ec3a34aSLoGin     fn setup_global_include_dir(&self, c: &mut Build);
14*0ec3a34aSLoGin     /// 设置需要编译的架构相关的文件
setup_files(&self, c: &mut Build, files: &mut Vec<PathBuf>)15*0ec3a34aSLoGin     fn setup_files(&self, c: &mut Build, files: &mut Vec<PathBuf>);
16*0ec3a34aSLoGin 
17*0ec3a34aSLoGin     /// 设置架构相关的全局编译标志
setup_global_flags(&self, c: &mut Build)18*0ec3a34aSLoGin     fn setup_global_flags(&self, c: &mut Build);
19*0ec3a34aSLoGin }
20*0ec3a34aSLoGin 
21*0ec3a34aSLoGin /// 获取当前的架构;
current_cfiles_arch() -> &'static dyn CFilesArch22*0ec3a34aSLoGin pub(super) fn current_cfiles_arch() -> &'static dyn CFilesArch {
23*0ec3a34aSLoGin     let arch = CargoHandler::target_arch();
24*0ec3a34aSLoGin     match arch {
25*0ec3a34aSLoGin         TargetArch::Riscv64 => &riscv64::RiscV64CFilesArch,
26*0ec3a34aSLoGin         _ => panic!("Unsupported arch: {:?}", arch),
27*0ec3a34aSLoGin     }
28*0ec3a34aSLoGin }
29