forked from Traverse-Research/intel-tex-rs-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
98 lines (85 loc) · 3.56 KB
/
build.rs
File metadata and controls
98 lines (85 loc) · 3.56 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
ISPC project file builds the kernels as such:
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ispc -O2 "%(Filename).ispc" -o "$(TargetDir)%(Filename).obj" -h "$(ProjectDir)%(Filename)_ispc.h" --target=sse2,sse4,avx,avx2 --opt=fast-math</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(TargetDir)%(Filename).obj;$(TargetDir)%(Filename)_sse2.obj;$(TargetDir)%(Filename)_sse4.obj;$(TargetDir)%(Filename)_avx.obj;$(TargetDir)%(Filename)_avx2.obj;</Outputs>
*/
#[cfg(feature = "ispc")]
fn compile_kernel() {
use ispc_compile::{bindgen::builder, Config, TargetISA};
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let target_isas = match target_arch.as_str() {
"x86" | "x86_64" => vec![
TargetISA::SSE2i32x4,
TargetISA::SSE4i32x4,
TargetISA::AVX1i32x8,
TargetISA::AVX2i32x8,
TargetISA::AVX512KNLi32x16,
TargetISA::AVX512SKXi32x16,
],
"arm" | "aarch64" => vec![
// TargetISA::Neoni32x4,
TargetISA::Neoni32x8,
],
x => panic!("Unsupported target architecture {}", x),
};
Config::new()
.opt_level(2)
.woff()
.target_isas(target_isas.clone())
.out_dir("src/ispc")
.file("vendor/ispc_texcomp/kernel.ispc")
.bindgen_builder(builder().allowlist_function(r#"CompressBlocks(BC\dH?|ETC1)_ispc"#))
.compile("kernel");
Config::new()
.opt_level(2)
.woff()
.target_isas(target_isas)
.out_dir("src/ispc")
.file("vendor/ispc_texcomp/kernel_astc.ispc")
.bindgen_builder(
builder()
.allowlist_function("astc_rank_ispc")
.allowlist_function("astc_encode_ispc")
.allowlist_function("get_programCount"),
)
.compile("kernel_astc");
// ASTC encoder `extern "C"`'s some code, so we need to make sure to link
// and compile that in. The relevant codepath using this functionality is
// completely commented out and only results in linker errors on MSVC which
// is unable to deadstrip it and the requirement for a single symbol.
let out_dir = std::env::var("OUT_DIR").unwrap();
cc::Build::new()
.include(out_dir)
.file("vendor/ispc_texcomp/ispc_texcomp_astc.cpp")
.out_dir("src/ispc")
// Append the target triple since we'll be checking this file in, just like
// the compiled kernels above.
.compile(&format!(
"ispc_texcomp_astc{}",
std::env::var("TARGET").unwrap()
));
}
#[cfg(not(feature = "ispc"))]
fn compile_kernel() {
use std::path::Path;
ispc_rt::PackagedModule::new("kernel")
.lib_path("src/ispc")
.link();
ispc_rt::PackagedModule::new("kernel_astc")
.lib_path("src/ispc")
.link();
// Manually link ispc_texcomp_astc since it's not an ISPC module but C++.
let libname = format!("ispc_texcomp_astc{}", std::env::var("TARGET").unwrap());
let libpath = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/ispc");
let libfile = match std::env::var("CARGO_CFG_TARGET_FAMILY").unwrap().as_str() {
"unix" => format!("lib{}.a", libname),
"windows" => format!("{}.lib", libname),
x => panic!("Unknown target family {}", x),
};
println!("cargo:rustc-link-lib=static={}", libname);
println!("cargo:rerun-if-changed={}", libpath.join(libfile).display());
println!("cargo:rustc-link-search=native={}", libpath.display());
}
fn main() {
compile_kernel();
}