Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous updates #178

Merged
merged 6 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down 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
1 change: 0 additions & 1 deletion src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -61,14 +61,16 @@ 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");
}
}

// Determine the cross-compilation target, if any.

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]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}