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 {
setup_defines(&self, c: &mut cc::Build)10 fn setup_defines(&self, c: &mut cc::Build) {
11 c.define("__riscv64__", None);
12 c.define("__riscv", None);
13 }
14
setup_global_include_dir(&self, _c: &mut cc::Build)15 fn setup_global_include_dir(&self, _c: &mut cc::Build) {}
16
setup_files(&self, _c: &mut cc::Build, files: &mut Vec<std::path::PathBuf>)17 fn setup_files(&self, _c: &mut cc::Build, files: &mut Vec<std::path::PathBuf>) {
18 files.append(&mut FileUtils::list_all_files(
19 &arch_path(""),
20 Some("S"),
21 true,
22 ));
23 }
24
setup_global_flags(&self, c: &mut cc::Build)25 fn setup_global_flags(&self, c: &mut cc::Build) {
26 // 在这里设置编译器,不然的话vscode的rust-analyzer会报错
27 c.compiler("riscv64-unknown-elf-gcc");
28 // // c.flag("-march=rv64imafdc");
29 // c.no_default_flags(true);
30 c.flag("-mcmodel=medany");
31 c.flag("-mabi=lp64");
32 c.flag("-march=rv64imac");
33 }
34 }
35
arch_path(relative_path: &str) -> PathBuf36 fn arch_path(relative_path: &str) -> PathBuf {
37 PathBuf::from(format!("{}/{}", ARCH_DIR_RISCV64, relative_path))
38 }
39