diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e2a69f83..9dd8719d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ ### Changed - Bumped minimum supported Rust version (MSRV) to 1.60.0 +- Added error logging when `CLANG_PATH` set but it isn't a full path to an executable +- Removed reference to `libclang` 3.5 in error message for attempting to call an unsupported function + +### Added +- Added `libcpp` Cargo feature which enables linking to `libc++` instead of `libstdc++` when linking to `libclang` statically on Linux or Haiku + +### Fixed +- Fixed handling of paths that contain characters that have special meaning in +glob patterns (e.g., `[` or `]`) +- Fixed `Clang::find` to support both the `-target` and `--target` arguments +when using target-prefixed `clang` binaries ## [1.7.0] - 2023-12-31 diff --git a/Cargo.toml b/Cargo.toml index 5af722aaa..80b760bf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,8 @@ clang_17_0 = ["clang_16_0"] runtime = ["libloading"] static = [] +libcpp = [] + [dependencies] glob = "0.3" diff --git a/README.md b/README.md index b441463b8..c05ec617a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Crate](https://img.shields.io/crates/v/clang-sys.svg)](https://crates.io/crates/clang-sys) [![Documentation](https://docs.rs/clang-sys/badge.svg)](https://docs.rs/clang-sys) [![CI](https://img.shields.io/github/actions/workflow/status/KyleMayes/clang-sys/ci.yml?branch=master)](https://github.com/KyleMayes/clang-sys/actions?query=workflow%3ACI) -![MSRV](https://img.shields.io/badge/MSRV-1.56.0-blue) +![MSRV](https://img.shields.io/badge/MSRV-1.60.0-blue) Rust bindings for `libclang`. @@ -84,6 +84,8 @@ On Windows, running an executable that has been dynamically linked to `libclang` The availability of `llvm-config` is not optional for static linking. Ensure that an instance of this executable can be found on your system's path or set the `LLVM_CONFIG_PATH` environment variable. The required LLVM and Clang static libraries will be searched for in the same way as shared libraries are searched for, except the `LIBCLANG_STATIC_PATH` environment variable is used in place of the `LIBCLANG_PATH` environment variable. +**Note:** The `libcpp` Cargo feature can be used to enable linking to `libc++` instead of `libstd++` when linking to `libclang` statically on Linux or Haiku. + ### Runtime The `clang_sys::load` function is used to load a `libclang` shared library for use in the thread in which it is called. The `clang_sys::unload` function will unload the `libclang` shared library. `clang_sys::load` searches for a `libclang` shared library in the same way one is searched for when linking to `libclang` dynamically at compiletime. diff --git a/build/static.rs b/build/static.rs index a78a7dcbf..013dfd52b 100644 --- a/build/static.rs +++ b/build/static.rs @@ -129,7 +129,11 @@ pub fn link() { if cfg!(target_os = "freebsd") { println!("cargo:rustc-flags=-l ffi -l ncursesw -l c++ -l z"); } else if cfg!(any(target_os = "haiku", target_os = "linux")) { - println!("cargo:rustc-flags=-l ffi -l ncursesw -l stdc++ -l z"); + if cfg!(feature = "libcpp") { + println!("cargo:rustc-flags=-l c++"); + } else { + println!("cargo:rustc-flags=-l ffi -l ncursesw -l stdc++ -l z"); + } } else if cfg!(target_os = "macos") { println!("cargo:rustc-flags=-l ffi -l ncurses -l c++ -l z"); } diff --git a/src/link.rs b/src/link.rs index 79b3d49a3..58e64b507 100644 --- a/src/link.rs +++ b/src/link.rs @@ -185,7 +185,6 @@ A `libclang` function was called that is not supported by the loaded `libclang` called function = `{0}` loaded `libclang` instance = {1} -This crate only supports `libclang` 3.5 and later. The minimum `libclang` requirement for this particular function can be found here: https://docs.rs/clang-sys/latest/clang_sys/{0}/index.html diff --git a/src/support.rs b/src/support.rs index 20005ba1e..51764d281 100644 --- a/src/support.rs +++ b/src/support.rs @@ -52,7 +52,7 @@ impl Clang { /// /// ## Cross-compilation /// - /// If target arguments are provided (e.g., `-target` followed by a target + /// If target arguments are provided (e.g., `--target` followed by a target /// like `x86_64-unknown-linux-gnu`) then this method will prefer a /// target-prefixed instance of `clang` (e.g., /// `x86_64-unknown-linux-gnu-clang` for the above example). @@ -61,6 +61,8 @@ impl Clang { let p = Path::new(&path); if p.is_file() && is_executable(p).unwrap_or(false) { return Some(Clang::new(p, args)); + } else { + eprintln!("`CLANG_PATH` env var set but is not a full path to an executable"); } } @@ -68,7 +70,7 @@ impl Clang { let mut target = None; for i in 0..args.len() { - if args[i] == "-target" && i + 1 < args.len() { + if (args[i] == "-target" || args[i] == "-target") && i + 1 < args.len() { target = Some(&args[i + 1]); } } diff --git a/tests/lib.rs b/tests/lib.rs index e39170ed5..e9f5927c2 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -46,7 +46,7 @@ fn test_support() { #[test] fn test_support_target() { - let args = &["-target".into(), "x86_64-unknown-linux-gnu".into()]; + let args = &["--target".into(), "x86_64-unknown-linux-gnu".into()]; let clang = support::Clang::find(None, args).unwrap(); println!("{:?}", clang); }