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