1 use std::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, c: &mut cc::Build) { 16 c.include("src/arch/riscv64/include"); 17 } 18 19 fn setup_files(&self, _c: &mut cc::Build, files: &mut Vec<std::path::PathBuf>) { 20 files.push(PathBuf::from("src/arch/riscv64/boot/head.S")); 21 files.append(&mut FileUtils::list_all_files( 22 &arch_path("asm"), 23 Some("c"), 24 true, 25 )); 26 } 27 28 fn setup_global_flags(&self, c: &mut cc::Build) { 29 // 在这里设置编译器,不然的话vscode的rust-analyzer会报错 30 c.compiler("riscv64-unknown-elf-gcc"); 31 // // c.flag("-march=rv64imafdc"); 32 // c.no_default_flags(true); 33 c.flag("-mcmodel=medany"); 34 c.flag("-mabi=lp64"); 35 c.flag("-march=rv64imac"); 36 } 37 } 38 39 fn arch_path(relative_path: &str) -> PathBuf { 40 PathBuf::from(format!("{}/{}", ARCH_DIR_RISCV64, relative_path)) 41 } 42