This repository was archived by the owner on Sep 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.rs
More file actions
50 lines (45 loc) · 1.51 KB
/
build.rs
File metadata and controls
50 lines (45 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn aarch64_vfp_compile() {
// 获取当前 crate 输出目录
let out_dir = env::var("OUT_DIR").unwrap();
// 指定汇编文件路径
let asm_file = PathBuf::from("src/arch/vfp.S");
let asm_out_file = PathBuf::from(&out_dir).join("vfp.o");
// 编译汇编文件,增加 target-feature 选项
let status = Command::new("clang")
.args([
"-c",
asm_file.to_str().unwrap(),
"-o",
asm_out_file.to_str().unwrap(),
"-target",
"aarch64-unknown-none",
"-mfpu=neon",
])
.status()
.expect("failed to execute clang");
assert!(status.success(), "clang failed to compile assembly file");
// 打包对象文件为静态库
let lib_out_file = PathBuf::from(&out_dir).join("libvfp.a");
let status = Command::new("ar")
.args([
"crus",
lib_out_file.to_str().unwrap(),
asm_out_file.to_str().unwrap(),
])
.status()
.expect("failed to execute ar");
assert!(status.success(), "ar failed to create static library");
// 指示 rustc 链接器链接汇编对象文件
println!("cargo:rerun-if-changed=src/arch/vfp.S");
println!("cargo:rustc-link-search={}", out_dir);
println!("cargo:rustc-link-lib=static=vfp");
}
fn main() {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if arch == "aarch64" {
aarch64_vfp_compile();
}
}