1 | use std::env; |
2 | use std::path::PathBuf; |
3 | |
4 | pub fn setup_gnu() { |
5 | let libnode_path: Option = search_libnode_path(); |
6 | if let Some(libnode_dir: PathBuf) = libnode_path { |
7 | let node_lib_path: PathBuf = libnode_dir.join(path:"libnode.dll" ); |
8 | if node_lib_path.exists() { |
9 | println!("cargo:rustc-link-search=native= {}" , libnode_dir.display()); |
10 | println!("cargo:rustc-link-lib=node" ); |
11 | } else { |
12 | panic!("libnode.dll not found in {}" , libnode_dir.display()); |
13 | } |
14 | } else { |
15 | panic!("libnode.dll not found in any search path" ); |
16 | } |
17 | } |
18 | |
19 | fn search_libnode_path() -> Option<PathBuf> { |
20 | if let Ok(path) = env::var("LIBNODE_PATH" ) { |
21 | let libnode_dir = PathBuf::from(path); |
22 | if libnode_dir.exists() { |
23 | return Some(libnode_dir); |
24 | } |
25 | } |
26 | |
27 | if let Ok(paths) = env::var("LIBPATH" ) { |
28 | for path in env::split_paths(&paths) { |
29 | if path.join("libnode.dll" ).exists() { |
30 | return Some(path); |
31 | } |
32 | } |
33 | } |
34 | |
35 | if let Ok(paths) = env::var("PATH" ) { |
36 | for path in env::split_paths(&paths) { |
37 | if path.join("libnode.dll" ).exists() { |
38 | return Some(path); |
39 | } |
40 | } |
41 | } |
42 | |
43 | None |
44 | } |
45 | |