diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-07-17 23:50:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-17 23:50:08 -0700 |
commit | dca0f897684a6ee6651561f6c2c55058c0279dfe (patch) | |
tree | 2b609461101caea6e4bdbc782748c755a5519e83 | |
parent | 9eceb7fdb26da909f019a27b3d892a3929b184c8 (diff) | |
parent | c51a5a75beafa36bd977c292fecd574dfd640501 (diff) |
Auto merge of #15 - upsuper:fix-msvc, r=upsuper
Some fixes to make it work with MSVC
The last commit -- removing clang searching code, is not closely related. The reason its being there is that the C++ headers we need in geckolib require LLVM 3.9, which is pre-release, and thus it is usually necessary to setting `LIBCLANG_PATH` manually to get the proper clang library linked.
However, the current searching code doesn't work well on Windows, because LLVM for Windows puts `libclang.dll` and `libclang.lib` in different directories, while you can only specify one of them in `LIBCLANG_PATH`.
To fix this, I submitted some code in KyleMayes/clang-sys#34 (landed in development branch), and I don't want the searching code here to introduce any conflicts with the code there.
-rw-r--r-- | build.rs | 157 | ||||
-rw-r--r-- | src/clang.rs | 2 | ||||
-rw-r--r-- | src/parser.rs | 1 |
3 files changed, 2 insertions, 158 deletions
@@ -1,26 +1,3 @@ -use std::env; -use std::fs; -use std::path::Path; -use std::process::Command; - -const LINUX_CLANG_DIRS: &'static [&'static str] = &[ - "/usr/lib", - "/usr/lib/llvm", - "/usr/lib/llvm-3.8/lib", - "/usr/lib/llvm-3.7/lib", - "/usr/lib/llvm-3.6/lib", - "/usr/lib/llvm-3.5/lib", - "/usr/lib/llvm-3.4/lib", - "/usr/lib64/llvm", - "/usr/lib/x86_64-linux-gnu", -]; -const MAC_CLANG_DIR: &'static [&'static str] = &[ - "/usr/local/opt/llvm/lib", - "/Library/Developer/CommandLineTools/usr/lib", - "/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"]; - mod codegen { extern crate quasi_codegen; use std::path::Path; @@ -38,138 +15,4 @@ mod codegen { fn main() { codegen::main(); - search_libclang(); -} - -fn search_libclang() { - let use_static_lib = env::var_os("LIBCLANG_STATIC").is_some() || cfg!(feature = "static"); - - let possible_clang_dirs = if let Ok(dir) = env::var("LIBCLANG_PATH") { - vec![dir] - } else if cfg!(any(target_os = "linux", target_os = "freebsd")) { - LINUX_CLANG_DIRS.iter().map(ToString::to_string).collect() - } else if cfg!(target_os = "macos") { - MAC_CLANG_DIR.iter().map(ToString::to_string).collect() - } else if cfg!(target_os = "windows") { - WIN_CLANG_DIRS.iter().map(ToString::to_string).collect() - } else { - panic!("Platform not supported"); - }; - - 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) - }; - - //may contain path to libclang detected via ldconfig - let mut libclang_path_string = String::new(); - - let mut 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 { - None - } - }).next(); - - if maybe_clang_dir.is_none() && cfg!(target_os = "linux") { - //try to find via lddconfig - //may return line, like - //libclang.so.3.7 (libc6,x86-64) => /usr/lib64/libclang.so.3.7 - let lddresult = Command::new("/sbin/ldconfig") - .arg("-p") - .output(); - if lddresult.is_ok() { - let lddresult = lddresult.unwrap(); - let ldd_config_output = String::from_utf8_lossy(&lddresult.stdout).to_string(); - for line in ldd_config_output.lines() { - let line_trim = line.trim(); - if line_trim.starts_with(&*clang_lib) { - let last_word = line_trim.rsplit(" ").next(); - if let Some(last_word) = last_word { - let libclang_path = Path::new(last_word); - if path_exists(&libclang_path) { - libclang_path_string = last_word.to_owned(); - maybe_clang_dir = Path::new(&libclang_path_string).parent(); - } - } - break; - } - } - } - } - - macro_rules! qw { - ($($i:ident)*) => (vec!($(stringify!($i)),*)); - } - - if let Some(clang_dir) = maybe_clang_dir { - if use_static_lib { - let libs = qw![ - LLVMAnalysis - LLVMBitReader - LLVMCore - LLVMLTO - LLVMLinker - LLVMMC - LLVMMCParser - LLVMObjCARCOpts - LLVMObject - LLVMOption - LLVMScalarOpts - LLVMSupport - LLVMTarget - LLVMTransformUtils - LLVMVectorize - LLVMipa - LLVMipo - clang - clangARCMigrate - clangAST - clangASTMatchers - clangAnalysis - clangBasic - clangDriver - clangEdit - clangFormat - clangFrontend - clangIndex - clangLex - clangParse - clangRewrite - clangRewriteFrontend - clangSema - clangSerialization - clangStaticAnalyzerCheckers - clangStaticAnalyzerCore - clangStaticAnalyzerFrontend - clangTooling - ]; - - - print!("cargo:rustc-flags="); - for lib in libs { - print!("-l static={} ", lib); - } - println!("-L {} -l ncursesw -l z -l stdc++", clang_dir.to_str().unwrap()); - } else{ - println!("cargo:rustc-link-search={}", clang_dir.to_str().unwrap()); - if !libclang_path_string.is_empty() { - let libclang_path = Path::new(&libclang_path_string); - println!("cargo:rustc-link-lib=dylib=:{}", libclang_path.file_name().unwrap().to_str().unwrap()); - } else { - println!("cargo:rustc-link-lib=dylib=clang"); - } - } - println!("cargo:rerun-if-changed="); - } else { - panic!("Unable to find {}", clang_lib); - } -} - -fn path_exists(path: &Path) -> bool { - fs::metadata(path).is_ok() } diff --git a/src/clang.rs b/src/clang.rs index 0143c4db..2f6e6223 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -37,7 +37,7 @@ impl Cursor { }; // Try to undo backend mangling - if cfg!(target_os = "macos") || cfg!(target_os = "windows") { + if cfg!(target_os = "macos") || cfg!(all(target_os = "windows", target_env = "gnu")) { mangling.remove(0); } mangling diff --git a/src/parser.rs b/src/parser.rs index 12047213..71a6dff9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -78,6 +78,7 @@ fn match_pattern(ctx: &mut ClangParserCtx, cursor: &Cursor) -> bool { return true; } + let name = name.replace("\\", "/"); ctx.options.match_pat.iter().any(|pat| name.contains(pat)) } |