-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild.rs
More file actions
61 lines (56 loc) · 2.19 KB
/
build.rs
File metadata and controls
61 lines (56 loc) · 2.19 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
use std::{env, path::PathBuf};
fn main() {
if cfg!(feature = "mock") {
return;
}
// Get SDK paths
let dlss_sdk = env::var("DLSS_SDK")
.expect("DLSS_SDK environment variable not set. Consult the dlss_wgpu readme.");
let vulkan_sdk = env::var("VULKAN_SDK").expect("VULKAN_SDK environment variable not set");
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
// Link to needed libraries
#[cfg(not(target_os = "windows"))]
{
println!("cargo:rustc-link-search=native={dlss_sdk}/lib/Linux_x86_64");
println!("cargo:rustc-link-lib=static=nvsdk_ngx");
println!("cargo:rustc-link-lib=dylib=stdc++");
println!("cargo:rustc-link-lib=dylib=dl");
}
#[cfg(target_os = "windows")]
{
println!("cargo:rustc-link-search=native={dlss_sdk}/lib/Windows_x86_64/x64");
#[cfg(not(target_feature = "crt-static"))]
println!("cargo:rustc-link-lib=static=nvsdk_ngx_d");
#[cfg(target_feature = "crt-static")]
println!("cargo:rustc-link-lib=static=nvsdk_ngx_s");
}
// Generate rust bindings
#[cfg(not(target_os = "windows"))]
let vulkan_sdk_include = "include";
#[cfg(target_os = "windows")]
let vulkan_sdk_include = "Include";
bindgen::Builder::default()
.header(format!("{}/src/wrapper.h", env!("CARGO_MANIFEST_DIR")))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.wrap_static_fns(true)
.wrap_static_fns_path(out_dir.join("wrap_static_fns"))
.clang_arg(format!("-I{dlss_sdk}/include"))
.clang_arg(format!("-I{vulkan_sdk}/{vulkan_sdk_include}"))
.allowlist_item(".*NGX.*")
.blocklist_item("Vk.*")
.blocklist_item("PFN_vk.*")
.blocklist_item(".*Cuda.*")
.blocklist_item(".*CUDA.*")
.generate()
.unwrap()
.write_to_file(out_dir.join("bindings.rs"))
.unwrap();
// Generate and link a library for static inline functions
cc::Build::new()
.file(out_dir.join("wrap_static_fns.c"))
.includes([
format!("{dlss_sdk}/include"),
format!("{vulkan_sdk}/{vulkan_sdk_include}"),
])
.compile("wrap_static_fns");
}