mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 08:11:02 +00:00
@@ -4,6 +4,9 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
[features]
|
||||
riscv-64 = []
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -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");
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user