mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-13 20:01:04 +00:00
@@ -1,7 +1,11 @@
|
||||
use std::{env, fs, io::Read, path::Path, process::Command};
|
||||
|
||||
#[cfg(not(feature = "riscv-64"))]
|
||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv32.a";
|
||||
#[cfg(feature = "riscv-64")]
|
||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||
|
||||
fn main() {
|
||||
let lib = "libclang_rt.builtins-riscv32.a";
|
||||
let mut llvm_lib_dir = String::new();
|
||||
|
||||
Command::new("llvm-config")
|
||||
@@ -15,19 +19,22 @@ fn main() {
|
||||
|
||||
let mut lib_path = std::path::PathBuf::from(llvm_lib_dir.trim())
|
||||
.join("linux")
|
||||
.join(lib);
|
||||
.join(BUILTINS_ARCHIVE_FILE);
|
||||
if !lib_path.exists() {
|
||||
lib_path = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join(lib);
|
||||
lib_path = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||
.join(BUILTINS_ARCHIVE_FILE);
|
||||
}
|
||||
let archive = fs::read(lib_path).expect("clang builtins for riscv32 not found");
|
||||
let archive = fs::read(lib_path).expect("clang builtins not found");
|
||||
|
||||
let out_dir = env::var_os("OUT_DIR").expect("has OUT_DIR");
|
||||
let archive_path = Path::new(&out_dir).join(lib);
|
||||
let archive_path = Path::new(&out_dir).join(BUILTINS_ARCHIVE_FILE);
|
||||
let len = archive.len();
|
||||
std::fs::write(archive_path, &archive).expect("can write to OUT_DIR");
|
||||
|
||||
let src_path = Path::new(&out_dir).join("compiler_rt.rs");
|
||||
let src = format!("pub static COMPILER_RT: &[u8; {len}] = include_bytes!(\"{lib}\");");
|
||||
let src = format!(
|
||||
"pub static COMPILER_RT: &[u8; {len}] = include_bytes!(\"{BUILTINS_ARCHIVE_FILE}\");"
|
||||
);
|
||||
fs::write(src_path, src).expect("can write to OUT_DIR");
|
||||
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
Reference in New Issue
Block a user