Skip to content

Commit

Permalink
Add libcpp Cargo feature (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMayes committed May 27, 2024
1 parent 79e9b1a commit aea33e8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `]`)
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ clang_17_0 = ["clang_16_0"]
runtime = ["libloading"]
static = []

libcpp = []

[dependencies]

glob = "0.3"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 5 additions & 1 deletion build/static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit aea33e8

Please sign in to comment.