Skip to content

Commit

Permalink
Allow compilation of winfsp_wrs_sys on non-Windows platforms
Browse files Browse the repository at this point in the history
Compilation on non-Windows platform will obviously fail (as WinFSP is only available
on Windows).
However keeping the Rust part platform agnostic is still useful given it allows
linter & IDE to work correctly when groking into the code from a non-Windows machine.
  • Loading branch information
touilleMan committed Aug 7, 2024
1 parent e73325a commit 12eeff0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions winfsp_wrs_sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use std::path::PathBuf;

fn get_winfsp_install_dir() -> PathBuf {
#[cfg(windows)]
fn get_winfsp_install_dir() -> std::path::PathBuf {
let winfsp_install = registry::Hive::LocalMachine
.open("SOFTWARE\\WOW6432Node\\WinFsp", registry::Security::Read)
.ok()
.and_then(|u| u.value("InstallDir").ok())
.expect("WinFsp installation directory not found.");
match winfsp_install {
registry::Data::String(path) => PathBuf::from(path.to_os_string()),
registry::Data::String(path) => std::path::PathBuf::from(path.to_os_string()),
_ => panic!("unexpected install directory"),
}
}

#[cfg(windows)]
fn main() {
if !cfg!(windows) {
panic!("WinFSP is only supported on Windows.");
}

let winfsp_install_dir = get_winfsp_install_dir();
println!(
"cargo:rustc-link-search={}/lib",
Expand All @@ -37,3 +33,10 @@ fn main() {
panic!("unsupported triple {}", std::env::var("TARGET").unwrap())
};
}

// Compilation on non-Windows platform will obviously fail (as WinFSP is only available
// on Windows).
// However keeping the Rust part platform agnostic is still useful given it allows
// linter & IDE to work correctly when groking into the code from a non-Windows machine.
#[cfg(not(windows))]
fn main() {}

0 comments on commit 12eeff0

Please sign in to comment.