xref: /DragonOS/build-scripts/kernel_build/src/cfiles/arch/mod.rs (revision 4dd4856f933be0b4624c7f7ffa9e3d0c8c218873)
1 use std::{collections::HashSet, 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     /// 设置架构相关的宏定义
14     fn setup_defines(&self, c: &mut Build);
15     /// 设置架构相关的全局包含目录
16     fn setup_global_include_dir(&self, c: &mut HashSet<PathBuf>);
17     /// 设置需要编译的架构相关的文件
18     fn setup_files(&self, c: &mut Build, files: &mut HashSet<PathBuf>);
19 
20     /// 设置架构相关的全局编译标志
21     fn setup_global_flags(&self, c: &mut Build);
22 }
23 
24 /// 获取当前的架构;
25 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