diff --git a/build/common.rs b/build/common.rs index 665347813..f2210dcad 100644 --- a/build/common.rs +++ b/build/common.rs @@ -20,16 +20,13 @@ thread_local! { /// Adds an error encountered by the build script while executing a command. fn add_command_error(name: &str, path: &str, arguments: &[&str], message: String) { COMMAND_ERRORS.with(|e| { - e.borrow_mut() - .entry(name.into()) - .or_default() - .push(format!( - "couldn't execute `{} {}` (path={}) ({})", - name, - arguments.join(" "), - path, - message, - )) + e.borrow_mut().entry(name.into()).or_default().push(format!( + "couldn't execute `{} {}` (path={}) ({})", + name, + arguments.join(" "), + path, + message, + )) }); } @@ -190,14 +187,14 @@ const DIRECTORIES_WINDOWS: &[(&str, bool)] = &[ ("C:\\LLVM\\lib", true), // LLVM + Clang can be installed as a component of Visual Studio. // https://github.com/KyleMayes/clang-sys/issues/121 - ("C:\\Program Files*\\Microsoft Visual Studio\\*\\VC\\Tools\\Llvm\\**\\lib", true), + ( + "C:\\Program Files*\\Microsoft Visual Studio\\*\\VC\\Tools\\Llvm\\**\\lib", + true, + ), ]; /// `libclang` directory patterns for illumos -const DIRECTORIES_ILLUMOS: &[&str] = &[ - "/opt/ooce/llvm-*/lib", - "/opt/ooce/clang-*/lib", -]; +const DIRECTORIES_ILLUMOS: &[&str] = &["/opt/ooce/llvm-*/lib", "/opt/ooce/clang-*/lib"]; //================================================ // Searching @@ -318,11 +315,15 @@ pub fn search_libclang_directories(filenames: &[String], variable: &str) -> Vec< DIRECTORIES_MACOS.into() } else if target_os!("windows") { let msvc = target_env!("msvc"); + DIRECTORIES_WINDOWS .iter() .filter(|d| d.1 || !msvc) .map(|d| d.0) .collect() + } else if target_os!("cygwin") { + // For Cygwin/MSYS environments, the filesystem layout is Unix-like. + DIRECTORIES_LINUX.into() } else if target_os!("illumos") { DIRECTORIES_ILLUMOS.into() } else { @@ -334,7 +335,11 @@ pub fn search_libclang_directories(filenames: &[String], variable: &str) -> Vec< let directories = if test!() { directories .iter() - .map(|d| d.strip_prefix('/').or_else(|| d.strip_prefix("C:\\")).unwrap_or(d)) + .map(|d| { + d.strip_prefix('/') + .or_else(|| d.strip_prefix("C:\\")) + .unwrap_or(d) + }) .collect::>() } else { directories diff --git a/build/dynamic.rs b/build/dynamic.rs index 87e32ccf9..436c92f81 100644 --- a/build/dynamic.rs +++ b/build/dynamic.rs @@ -140,7 +140,8 @@ fn search_libclang_directories(runtime: bool) -> Result Result &name[0..index], None => name, }; diff --git a/build/macros.rs b/build/macros.rs index ff6545bf1..219c3efa4 100644 --- a/build/macros.rs +++ b/build/macros.rs @@ -1,7 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 macro_rules! test { - () => (cfg!(test) && ::std::env::var("_CLANG_SYS_TEST").is_ok()); + () => { + cfg!(test) && ::std::env::var("_CLANG_SYS_TEST").is_ok() + }; } macro_rules! target_os { diff --git a/src/lib.rs b/src/lib.rs index 35b93bfe5..a37f65364 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1114,7 +1114,7 @@ cenum! { /// Only produced by `libclang` 11.0 and later. const CXType_Atomic = 177, /// Only produced by `libclang` 15.0 and later. - const CXType_BTFTagAttributed = 178, + const CXType_BTFTagAttributed = 178, } } diff --git a/src/link.rs b/src/link.rs index 87f94ba60..d94346af6 100644 --- a/src/link.rs +++ b/src/link.rs @@ -190,7 +190,7 @@ https://docs.rs/clang-sys/latest/clang_sys/{0}/index.html Instructions for installing `libclang` can be found here: https://rust-lang.github.io/rust-bindgen/requirements.html -"#, +"#, stringify!($name), library .version() diff --git a/tests/build.rs b/tests/build.rs index e56f3fefb..c4ce57df9 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -27,7 +27,6 @@ struct RunCommandMock { responses: HashMap, String>, } - #[derive(Copy, Clone, Debug)] enum Arch { ARM64, @@ -77,7 +76,10 @@ impl Env { env: None, vars: HashMap::new(), cwd: env::current_dir().unwrap(), - tmp: tempfile::Builder::new().prefix("clang_sys_test").tempdir().unwrap(), + tmp: tempfile::Builder::new() + .prefix("clang_sys_test") + .tempdir() + .unwrap(), files: vec![], commands: Default::default(), } @@ -96,7 +98,8 @@ impl Env { fn var(mut self, name: &str, value: Option<&str>) -> Self { let previous = env::var(name).ok(); - self.vars.insert(name.into(), (value.map(|v| v.into()), previous)); + self.vars + .insert(name.into(), (value.map(|v| v.into()), previous)); self } @@ -141,7 +144,11 @@ impl Env { let mut key = vec![command]; key.extend(args); - self.commands.lock().unwrap().responses.insert(key, response.into()); + self.commands + .lock() + .unwrap() + .responses + .insert(key, response.into()); self } @@ -173,7 +180,9 @@ impl Env { let args = args.iter().map(|a| a.to_string()).collect::>(); let mut commands = commands.lock().unwrap(); - commands.invocations.push((command.clone(), path, args.clone())); + commands + .invocations + .push((command.clone(), path, args.clone())); let mut key = vec![command]; key.extend(args); @@ -209,7 +218,7 @@ impl Drop for Env { #[test] fn test_all() { // Run tests serially since they alter the environment. - + test_linux_directory_preference(); test_linux_version_preference(); test_linux_directory_and_version_preference(); @@ -228,7 +237,10 @@ macro_rules! assert_error { ($result:expr, $contents:expr $(,)?) => { if let Err(error) = $result { if !error.contains($contents) { - panic!("expected error to contain {:?}, received: {error:?}", $contents); + panic!( + "expected error to contain {:?}, received: {error:?}", + $contents + ); } } else { panic!("expected error, received: {:?}", $result); @@ -336,7 +348,7 @@ fn test_windows_arm64_on_x86_64() { .enable(); assert_error!( - dynamic::find(true), + dynamic::find(true), "invalid: [(Program Files\\LLVM\\bin\\libclang.dll: invalid DLL (ARM64)", ); } @@ -350,7 +362,7 @@ fn test_windows_x86_64_on_arm64() { .enable(); assert_error!( - dynamic::find(true), + dynamic::find(true), "invalid: [(Program Files\\LLVM\\bin\\libclang.dll: invalid DLL (x86-64)", ); }