diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a02d854c..9dd8719d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - 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 `]`) 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 7c4cd99c6..c05ec617a 100644 --- a/README.md +++ b/README.md @@ -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"); }