Skip to content

Commit

Permalink
Fix build script for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Zhixing committed Jun 30, 2023
1 parent a83ab81 commit 57c4937
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aftermath-rs"
version = "0.1.0"
version = "0.1.2"
edition = "2021"
description = "Rust bindings for NVIDIA Aftermath, targeting Vulkan applications"
license = "MIT"
Expand Down
53 changes: 29 additions & 24 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

use std::{ffi::OsString, io::Write};

fn get_install_path() -> OsString {
let mut path: std::path::PathBuf = std::env::var("OUT_DIR").unwrap().into();
path.push(get_download_name());
path.into_os_string()
}

fn get_lib_name() -> &'static str {
#[cfg(target_arch = "x86_64")]
return "GFSDK_Aftermath_Lib.x64";
Expand All @@ -20,22 +14,30 @@ fn get_lib_name() -> &'static str {
}
}

fn get_download_name() -> &'static str {
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";
return &["libGFSDK_Aftermath_Lib.x64.so"];

#[cfg(target_arch = "x86")]
return "libGFSDK_Aftermath_Lib.x86.so";
return &["libGFSDK_Aftermath_Lib.x86.so"];
}
#[cfg(target_family = "windows")]
{
#[cfg(target_arch = "x86_64")]
return "GFSDK_Aftermath_Lib.x64.lib";
return &["GFSDK_Aftermath_Lib.x64.lib", "GFSDK_Aftermath_Lib.x64.dll"];

#[cfg(target_arch = "x86")]
return "GFSDK_Aftermath_Lib.x86.lib";
return &["GFSDK_Aftermath_Lib.x86.lib", "GFSDK_Aftermath_Lib.x86.dll"];
}
#[allow(unreachable_code)]
{
Expand All @@ -44,19 +46,22 @@ fn get_download_name() -> &'static str {
}

fn main() {
let install_path = 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/{}",
get_download_name()
))
.expect("Download file error");
println!("{}", get_install_path().into_string().unwrap());
let mut file =
std::fs::File::create(get_install_path()).expect("Unable to create library file");
file.write_all(&data).expect("Unable to write library file");
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());
println!(
"cargo:rustc-link-search={}",
std::env::var("OUT_DIR").unwrap()
);
}
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ impl Status {
let mut status = Self::get();
let delta = std::time::Duration::from_millis(50);
let mut time = std::time::Duration::new(0, 0);
while status != Status::CollectingDataFailed && status != Status::Finished && timeout.map_or(true, |t| time < t) {
while status != Status::CollectingDataFailed
&& status != Status::Finished
&& timeout.map_or(true, |t| time < t)
{
std::thread::sleep(delta);
time += delta;
status = Self::get();
Expand Down

0 comments on commit 57c4937

Please sign in to comment.