diff options
author | pradeep <pradeep.garigipati@gmail.com> | 2015-06-25 14:11:44 -0400 |
---|---|---|
committer | pradeep <pradeep.garigipati@gmail.com> | 2015-06-25 14:28:34 -0400 |
commit | 7bc37ecb76aaf1850e5a9b95284039fcfd29b499 (patch) | |
tree | 94e1d72a1ec6451db4e7110454b34dcc8fed86cb | |
parent | ba150d99da9f52bf75751b282ad6c9bd529409f3 (diff) |
Windows platform fixes
* Clang CMAKE project is creating the library with `libclang.dll`
instead of the usual name format `clang.dll`. Hence, added a windows
specific search pattern for clang library search.
* Replaced `cargo:rustc-flags` with individual statements for link search
path and the library link as follows: `cargo:rustc-link-search=native={}`
and `cargo:rustc-link-lib=dylib=clang`. For some reason, using rustc-flags
on windows is causing a compile error for bindgen.
-rw-r--r-- | build.rs | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -4,6 +4,7 @@ use std::path::Path; const LINUX_CLANG_DIRS: &'static [&'static str] = &["/usr/lib", "/usr/lib/llvm", "/usr/lib64/llvm", "/usr/lib/x86_64-linux-gnu"]; const MAC_CLANG_DIR: &'static str = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib"; +const WIN_CLANG_DIRS: &'static [&'static str] = &["C:\\Program Files\\LLVM\\bin", "C:\\Program Files\\LLVM\\lib"]; fn path_exists(path: &Path) -> bool { match fs::metadata(path) { @@ -21,16 +22,21 @@ fn main() { LINUX_CLANG_DIRS.iter().map(ToString::to_string).collect() } else if cfg!(target_os = "macos") { vec![MAC_CLANG_DIR.to_string()] + } else if cfg!(target_os = "windows") { + WIN_CLANG_DIRS.iter().map(ToString::to_string).collect() } else { panic!("Platform not supported"); }; - let clang_lib = format!("{}clang{}", env::consts::DLL_PREFIX, env::consts::DLL_SUFFIX); + let clang_lib = if cfg!(target_os = "windows") { + format!("libclang{}", env::consts::DLL_SUFFIX) + } else { + format!("{}clang{}", env::consts::DLL_PREFIX, env::consts::DLL_SUFFIX) + }; let maybe_clang_dir = possible_clang_dirs.iter().filter_map(|candidate_dir| { let clang_dir = Path::new(candidate_dir); let clang_path = clang_dir.join(clang_lib.clone()); - if path_exists(&*clang_path) { Some(clang_dir) } else { @@ -91,7 +97,8 @@ fn main() { } println!("-L {} -l ncursesw -l z -l stdc++", clang_dir.to_str().unwrap()); } else{ - println!("cargo:rustc-flags=-l clang -L {}", clang_dir.to_str().unwrap()); + println!("cargo:rustc-link-search=native={}", clang_dir.to_str().unwrap()); + println!("cargo:rustc-link-lib=dylib=clang"); } } else { panic!("Unable to find {}", clang_lib); |