1 use std::{collections::HashSet, path::PathBuf}; 2 3 use crate::{constant::ARCH_DIR_RISCV64, utils::FileUtils}; 4 5 use super::CFilesArch; 6 7 pub(super) struct RiscV64CFilesArch; 8 9 impl CFilesArch for RiscV64CFilesArch { 10 fn setup_defines(&self, c: &mut cc::Build) { 11 c.define("__riscv64__", None); 12 c.define("__riscv", None); 13 } 14 15 fn setup_global_include_dir(&self, include_dirs: &mut HashSet<PathBuf>) { 16 include_dirs.insert("src/arch/riscv64/include".into()); 17 } 18 19 fn setup_files(&self, _c: &mut cc::Build, files: &mut HashSet<PathBuf>) { 20 files.insert(PathBuf::from("src/arch/riscv64/asm/head.S")); 21 22 FileUtils::list_all_files(&arch_path("asm"), Some("c"), true) 23 .into_iter() 24 .for_each(|f| { 25 files.insert(f); 26 }); 27 } 28 29 fn setup_global_flags(&self, c: &mut cc::Build) { 30 // 在这里设置编译器,不然的话vscode的rust-analyzer会报错 31 c.compiler("riscv64-unknown-elf-gcc"); 32 // // c.flag("-march=rv64imafdc"); 33 // c.no_default_flags(true); 34 c.flag("-mcmodel=medany"); 35 36 c.flag("-mabi=lp64d"); 37 c.flag("-march=rv64gc"); 38 } 39 } 40 41 fn arch_path(relative_path: &str) -> PathBuf { 42 PathBuf::from(format!("{}/{}", ARCH_DIR_RISCV64, relative_path)) 43 } 44