-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
56 lines (48 loc) 路 1.92 KB
/
Copy pathbuild.rs
File metadata and controls
56 lines (48 loc) 路 1.92 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
51
52
53
54
55
56
fn main() {
#[cfg(feature = "simd")]
{
let mut build = cc::Build::new();
// Set include path
build.include("external/hsdlib/include");
// Add C source files
build.file("external/hsdlib/src/utils.c");
build.file("external/hsdlib/src/distance/euclidean.c");
build.file("external/hsdlib/src/distance/manhattan.c");
build.file("external/hsdlib/src/similarity/cosine.c");
build.file("external/hsdlib/src/similarity/dot.c");
// Enable optimizations
build.opt_level(3);
// Architecture-specific SIMD flags
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
// Set C standard to C11 (this is needed for building Hsdlib)
if std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default() == "msvc" {
build.flag("/std:c11");
build.flag("/TC");
} else {
build.flag_if_supported("-std=c11");
}
match target_arch.as_str() {
"x86_64" | "x86" => {
// Enable AVX/AVX2/FMA for Intel/AMD
build.flag_if_supported("-mavx");
build.flag_if_supported("-mavx2");
build.flag_if_supported("-mfma");
}
"aarch64" => {
// ARM64 has NEON by default, but enable it explicitly
build.flag_if_supported("-march=armv8-a");
// Define HWCAP_SVE for older kernels/headers (e.g. manylinux_2_24)
build.flag_if_supported("-DHWCAP_SVE=(1<<22)");
}
"arm" => {
// ARM32 NEON
build.flag_if_supported("-mfpu=neon");
}
_ => {}
}
// Compile as static library
build.compile("hsd");
println!("cargo:rerun-if-changed=external/hsdlib/include/hsdlib.h");
println!("cargo:rerun-if-changed=external/hsdlib/src/");
}
}