-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
67 lines (58 loc) · 1.96 KB
/
build.rs
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
#![feature(fs_try_exists)]
use std::{ffi::OsString, io::Write};
fn get_lib_name() -> &'static str {
#[cfg(target_arch = "x86_64")]
return "GFSDK_Aftermath_Lib.x64";
#[cfg(target_arch = "x86")]
return "GFSDK_Aftermath_Lib.x86";
#[allow(unreachable_code)]
{
panic!()
}
}
fn get_install_path() -> impl Iterator<Item = (&'static str, OsString)> {
get_download_name().iter().map(|download_name| {
let mut path: std::path::PathBuf = std::env::var("OUT_DIR").unwrap().into();
path.push(download_name);
(*download_name, path.into_os_string())
})
}
fn get_download_name() -> &'static [&'static str] {
#[cfg(target_family = "unix")]
{
#[cfg(target_arch = "x86_64")]
return &["libGFSDK_Aftermath_Lib.x64.so"];
#[cfg(target_arch = "x86")]
return &["libGFSDK_Aftermath_Lib.x86.so"];
}
#[cfg(target_family = "windows")]
{
#[cfg(target_arch = "x86_64")]
return &["GFSDK_Aftermath_Lib.x64.lib", "GFSDK_Aftermath_Lib.x64.dll"];
#[cfg(target_arch = "x86")]
return &["GFSDK_Aftermath_Lib.x86.lib", "GFSDK_Aftermath_Lib.x86.dll"];
}
#[allow(unreachable_code)]
{
panic!()
}
}
fn main() {
for (download_name, install_path) in get_install_path() {
if !std::fs::try_exists(&install_path).expect("Unable to check library file location") {
let data = sysreq::get(format!(
"https://github.com/dust-engine/aftermath-rs/releases/download/v0.1/{}",
download_name
))
.expect("Download file error");
let mut file =
std::fs::File::create(install_path).expect("Unable to create library file");
file.write_all(&data).expect("Unable to write library file");
}
}
println!("cargo:rustc-link-lib={}", get_lib_name());
println!(
"cargo:rustc-link-search={}",
std::env::var("OUT_DIR").unwrap()
);
}