16cdb10c1Sopenharmony_ci# clang-sys 26cdb10c1Sopenharmony_ci 36cdb10c1Sopenharmony_ci[](https://crates.io/crates/clang-sys) 46cdb10c1Sopenharmony_ci[](https://docs.rs/clang-sys) 56cdb10c1Sopenharmony_ci[](https://github.com/KyleMayes/vulkanalia/actions?query=workflow%3ACI) 66cdb10c1Sopenharmony_ci 76cdb10c1Sopenharmony_ci 86cdb10c1Sopenharmony_ciRust bindings for `libclang`. 96cdb10c1Sopenharmony_ci 106cdb10c1Sopenharmony_ciIf you are interested in a somewhat idiomatic Rust wrapper for these bindings, see [`clang-rs`](https://github.com/KyleMayes/clang-rs). 116cdb10c1Sopenharmony_ci 126cdb10c1Sopenharmony_ciReleased under the Apache License 2.0. 136cdb10c1Sopenharmony_ci 146cdb10c1Sopenharmony_ci## [Documentation](https://docs.rs/clang-sys) 156cdb10c1Sopenharmony_ci 166cdb10c1Sopenharmony_ciNote that the documentation on https://docs.rs for this crate assumes usage of the `runtime` Cargo feature as well as the Cargo feature for the latest supported version of `libclang` (e.g., `clang_16_0`), neither of which are enabled by default. 176cdb10c1Sopenharmony_ci 186cdb10c1Sopenharmony_ciDue to the usage of the `runtime` Cargo feature, this documentation will contain some additional types and functions to manage a dynamically loaded `libclang` instance at runtime. 196cdb10c1Sopenharmony_ci 206cdb10c1Sopenharmony_ciDue to the usage of the Cargo feature for the latest supported version of `libclang`, this documentation will contain constants and functions that are not available in the oldest supported version of `libclang` (3.5). All of these types and functions have a documentation comment which specifies the minimum `libclang` version required to use the item. 216cdb10c1Sopenharmony_ci 226cdb10c1Sopenharmony_ci## Supported Versions 236cdb10c1Sopenharmony_ci 246cdb10c1Sopenharmony_ciTo target a version of `libclang`, enable a Cargo features such as one of the following: 256cdb10c1Sopenharmony_ci 266cdb10c1Sopenharmony_ci* `clang_3_5` - requires `libclang` 3.5 or later 276cdb10c1Sopenharmony_ci* `clang_3_6` - requires `libclang` 3.6 or later 286cdb10c1Sopenharmony_ci* etc... 296cdb10c1Sopenharmony_ci* `clang_15_0` - requires `libclang` 15.0 or later 306cdb10c1Sopenharmony_ci* `clang_16_0` - requires `libclang` 16.0 or later 316cdb10c1Sopenharmony_ci 326cdb10c1Sopenharmony_ciIf you do not enable one of these features, the API provided by `libclang` 3.5 will be available by default. 336cdb10c1Sopenharmony_ci 346cdb10c1Sopenharmony_ci**Note:** If you are using Clang 15.0 or later, you should enable the `clang_15_0` feature or a more recent version feature. Clang 15.0 introduced [a breaking change to the `EntityKind` enum](https://github.com/llvm/llvm-project/commit/bb83f8e70bd1d56152f02307adacd718cd67e312#diff-674613a0e47f4e66cc19061e28e3296d39be2d124dceefb68237b30b8e241e7c) which resulted in a mismatch between the values returned by `libclang` and the values for `EntityKind` defined by this crate in previous versions. 356cdb10c1Sopenharmony_ci 366cdb10c1Sopenharmony_ci## Dependencies 376cdb10c1Sopenharmony_ci 386cdb10c1Sopenharmony_ciBy default, this crate will attempt to link to `libclang` dynamically. In this case, this crate depends on the `libclang` shared library (`libclang.so` on Linux, `libclang.dylib` on macOS, `libclang.dll` on Windows). If you want to link to `libclang` statically instead, enable the `static` Cargo feature. In this case, this crate depends on the LLVM and Clang static libraries. If you don't want to link to `libclang` at compiletime but instead want to load it at runtime, enable the `runtime` Cargo feature. 396cdb10c1Sopenharmony_ci 406cdb10c1Sopenharmony_ciThese libraries can be either be installed as a part of Clang or downloaded [here](http://llvm.org/releases/download.html). 416cdb10c1Sopenharmony_ci 426cdb10c1Sopenharmony_ci**Note:** The downloads for LLVM and Clang 3.8 and later do not include the `libclang.a` static library. This means you cannot link to any of these versions of `libclang` statically unless you build it from source. 436cdb10c1Sopenharmony_ci 446cdb10c1Sopenharmony_ci### Versioned Dependencies 456cdb10c1Sopenharmony_ci 466cdb10c1Sopenharmony_ciThis crate supports finding versioned instances of `libclang.so` (e.g.,`libclang-3.9.so`). In the case where there are multiple instances to choose from, this crate will prefer instances with higher versions. For example, the following instances of `libclang.so` are listed in descending order of preference: 476cdb10c1Sopenharmony_ci 486cdb10c1Sopenharmony_ci1. `libclang-4.0.so` 496cdb10c1Sopenharmony_ci2. `libclang-4.so` 506cdb10c1Sopenharmony_ci3. `libclang-3.9.so` 516cdb10c1Sopenharmony_ci4. `libclang-3.so` 526cdb10c1Sopenharmony_ci5. `libclang.so` 536cdb10c1Sopenharmony_ci 546cdb10c1Sopenharmony_ci**Note:** On BSD distributions, versioned instances of `libclang.so` matching the pattern `libclang.so.*` (e.g., `libclang.so.7.0`) are also included. 556cdb10c1Sopenharmony_ci 566cdb10c1Sopenharmony_ci**Note:** On Linux distributions when the `runtime` features is enabled, versioned instances of `libclang.so` matching the pattern `libclang.so.*` (e.g., `libclang.so.1`) are also included. 576cdb10c1Sopenharmony_ci 586cdb10c1Sopenharmony_ci## Environment Variables 596cdb10c1Sopenharmony_ci 606cdb10c1Sopenharmony_ciThe following environment variables, if set, are used by this crate to find the required libraries and executables: 616cdb10c1Sopenharmony_ci 626cdb10c1Sopenharmony_ci* `LLVM_CONFIG_PATH` **(compiletime)** - provides a full path to an `llvm-config` executable (including the executable itself [i.e., `/usr/local/bin/llvm-config-8.0`]) 636cdb10c1Sopenharmony_ci* `LIBCLANG_PATH` **(compiletime)** - provides a path to a directory containing a `libclang` shared library or a full path to a specific `libclang` shared library 646cdb10c1Sopenharmony_ci* `LIBCLANG_STATIC_PATH` **(compiletime)** - provides a path to a directory containing LLVM and Clang static libraries 656cdb10c1Sopenharmony_ci* `CLANG_PATH` **(runtime)** - provides a path to a `clang` executable 666cdb10c1Sopenharmony_ci 676cdb10c1Sopenharmony_ci## Linking 686cdb10c1Sopenharmony_ci 696cdb10c1Sopenharmony_ci### Dynamic 706cdb10c1Sopenharmony_ci 716cdb10c1Sopenharmony_ci`libclang` shared libraries will be searched for in the following directories: 726cdb10c1Sopenharmony_ci 736cdb10c1Sopenharmony_ci* the directory provided by the `LIBCLANG_PATH` environment variable 746cdb10c1Sopenharmony_ci* the `bin` and `lib` directories in the directory provided by `llvm-config --libdir` 756cdb10c1Sopenharmony_ci* the directories provided by `LD_LIBRARY_PATH` environment variable 766cdb10c1Sopenharmony_ci* a list of likely directories for the target platform (e.g., `/usr/local/lib` on Linux) 776cdb10c1Sopenharmony_ci* **macOS only:** the toolchain directory in the directory provided by `xcode-select --print-path` 786cdb10c1Sopenharmony_ci 796cdb10c1Sopenharmony_ciOn Linux, running an executable that has been dynamically linked to `libclang` may require you to add a path to `libclang.so` to the `LD_LIBRARY_PATH` environment variable. The same is true on OS X, except the `DYLD_LIBRARY_PATH` environment variable is used instead. 806cdb10c1Sopenharmony_ci 816cdb10c1Sopenharmony_ciOn Windows, running an executable that has been dynamically linked to `libclang` requires that `libclang.dll` can be found by the executable at runtime. See [here](https://msdn.microsoft.com/en-us/library/7d83bc18.aspx) for more information. 826cdb10c1Sopenharmony_ci 836cdb10c1Sopenharmony_ci### Static 846cdb10c1Sopenharmony_ci 856cdb10c1Sopenharmony_ciThe 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. 866cdb10c1Sopenharmony_ci 876cdb10c1Sopenharmony_ci### Runtime 886cdb10c1Sopenharmony_ci 896cdb10c1Sopenharmony_ciThe `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. 90