-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.rs
executable file
·43 lines (38 loc) · 1.2 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
extern crate build_helper;
use build_helper::{host, rustc, target, LibKind, SearchKind};
use std::env;
use std::fs::ReadDir;
use std::path::PathBuf;
fn main() {
let lib_name = match target::triple().os() {
"windows" => "oci",
_ => "clntsh",
};
rustc::link_lib(Some(LibKind::DyLib), lib_name);
let host = host();
match (host.os(), host.env()) {
("windows", Some("gnu")) => {
if let Some(path) = find_dll(lib_name) {
rustc::link_search(Some(SearchKind::Native), path);
}
}
_ => (),
}
}
fn find_dll(dll_name: &str) -> Option<PathBuf> {
assert_eq!(host().os(), "windows");
let contains_dll = |mut contained_files: ReadDir| {
contained_files.any(|maybe_entry| {
maybe_entry
.ok()
.and_then(|entry| entry.file_name().into_string().ok())
.map(|file_name| file_name.to_lowercase() == dll_name.to_string() + ".dll")
.unwrap_or(false)
})
};
env::var_os("PATH").and_then(|paths| {
env::split_paths(&paths)
.filter(|path| path.read_dir().map(&contains_dll).unwrap_or(false))
.next()
})
}