• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..30-Mar-2022-

build/H30-Mar-2022-682452

src/H30-Mar-2022-2,7502,116

tests/H30-Mar-2022-6350

.cargo-checksum.jsonH A D03-May-202289 11

CHANGELOG.mdH A D30-Mar-202210.8 KiB439291

Cargo.tomlH A D30-Mar-20221.4 KiB5550

README.mdH A D30-Mar-20226.3 KiB12993

build.rsH A D30-Mar-20222.6 KiB8645

clippy.tomlH A D30-Mar-202231 21

README.md

1# clang-sys
2
3[![Crate](https://img.shields.io/crates/v/clang-sys.svg)](https://crates.io/crates/clang-sys)
4[![Documentation](https://docs.rs/clang-sys/badge.svg)](https://docs.rs/clang-sys)
5[![CI](https://github.com/KyleMayes/clang-sys/workflows/CI/badge.svg?branch=master)](https://github.com/KyleMayes/clang-sys/actions?query=workflow%3ACI)
6
7Rust bindings for `libclang`.
8
9If you are interested in a Rust wrapper for these bindings, see
10[clang-rs](https://github.com/KyleMayes/clang-rs).
11
12Supported on the stable, beta, and nightly Rust channels.<br/>
13Minimum supported Rust version: **1.40.0**
14
15Released under the Apache License 2.0.
16
17## [Documentation](https://docs.rs/clang-sys)
18
19Note 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_11_0`), neither of which are enabled by default.
20
21Due to the usage of the `runtime` Cargo feature, this documentation will contain some additional types and functions to manage a dynamically loaded
22`libclang` instance at runtime.
23
24Due 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.
25
26## Supported Versions
27
28To target a version of `libclang`, enable one of the following Cargo features:
29
30* `clang_3_5` - requires `libclang` 3.5 or later
31* `clang_3_6` - requires `libclang` 3.6 or later
32* `clang_3_7` - requires `libclang` 3.7 or later
33* `clang_3_8` - requires `libclang` 3.8 or later
34* `clang_3_9` - requires `libclang` 3.9 or later
35* `clang_4_0` - requires `libclang` 4.0 or later
36* `clang_5_0` - requires `libclang` 5.0 or later
37* `clang_6_0` - requires `libclang` 6.0 or later
38* `clang_7_0` - requires `libclang` 7.0 or later
39* `clang_8_0` - requires `libclang` 8.0 or later
40* `clang_9_0` - requires `libclang` 9.0 or later
41* `clang_10_0` - requires `libclang` 10.0 or later
42* `clang_11_0` - requires `libclang` 11.0 or later
43
44If you do not enable one of these features, the API provided by `libclang` 3.5 will be available by
45default.
46
47## Dependencies
48
49By default, this crate will attempt to link to `libclang` dynamically. In this case, this crate
50depends on the `libclang` shared library (`libclang.so` on Linux, `libclang.dylib` on macOS,
51`libclang.dll` on Windows). If you want to link to `libclang` statically instead, enable the
52`static` Cargo feature. In this case, this crate depends on the LLVM and Clang static libraries. If
53you don't want to link to `libclang` at compiletime but instead want to load it at runtime, enable
54the `runtime` Cargo feature.
55
56These libraries can be either be installed as a part of Clang or downloaded
57[here](http://llvm.org/releases/download.html).
58
59**Note:** The downloads for LLVM and Clang 3.8 and later do not include the `libclang.a` static
60library. This means you cannot link to any of these versions of `libclang` statically unless you
61build it from source.
62
63### Versioned Dependencies
64
65This crate supports finding versioned instances of `libclang.so` (e.g.,`libclang-3.9.so`).
66In the case where there are multiple instances to choose from, this crate will prefer instances with
67higher versions. For example, the following instances of `libclang.so` are listed in descending
68order of preference:
69
701. `libclang-4.0.so`
712. `libclang-4.so`
723. `libclang-3.9.so`
734. `libclang-3.so`
745. `libclang.so`
75
76**Note:** On BSD distributions, versioned instances of `libclang.so` matching the pattern
77`libclang.so.*` (e.g., `libclang.so.7.0`) are also included.
78
79**Note:** On Linux distributions when the `runtime` features is enabled, versioned instances of
80`libclang.so` matching the pattern `libclang.so.*` (e.g., `libclang.so.1`) are also included.
81
82## Environment Variables
83
84The following environment variables, if set, are used by this crate to find the required libraries
85and executables:
86
87* `LLVM_CONFIG_PATH` **(compiletime)** - provides a full path to an `llvm-config` executable
88  (including the executable itself [i.e., `/usr/local/bin/llvm-config-8.0`])
89* `LIBCLANG_PATH` **(compiletime)** - provides a path to a directory containing a `libclang` shared
90  library or a full path to a specific `libclang` shared library
91* `LIBCLANG_STATIC_PATH` **(compiletime)** - provides a path to a directory containing LLVM and
92  Clang static libraries
93* `CLANG_PATH` **(runtime)** - provides a path to a `clang` executable
94
95## Linking
96
97### Dynamic
98
99`libclang` shared libraries will be searched for in the following directories:
100
101* the directory provided by the `LIBCLANG_PATH` environment variable
102* the `bin` and `lib` directories in the directory provided by `llvm-config --libdir`
103* the directories provided by `LD_LIBRARY_PATH` environment variable
104* a list of likely directories for the target platform (e.g., `/usr/local/lib` on Linux)
105* **macOS only:** the toolchain directory in the directory provided by `xcode-select --print-path`
106
107On Linux, running an executable that has been dynamically linked to `libclang` may require you to
108add a path to `libclang.so` to the `LD_LIBRARY_PATH` environment variable. The same is true on OS
109X, except the `DYLD_LIBRARY_PATH` environment variable is used instead.
110
111On Windows, running an executable that has been dynamically linked to `libclang` requires that
112`libclang.dll` can be found by the executable at runtime. See
113[here](https://msdn.microsoft.com/en-us/library/7d83bc18.aspx) for more information.
114
115### Static
116
117The availability of `llvm-config` is not optional for static linking. Ensure that an instance of
118this executable can be found on your system's path or set the `LLVM_CONFIG_PATH` environment
119variable. The required LLVM and Clang static libraries will be searched for in the same way as
120shared libraries are searched for, except the `LIBCLANG_STATIC_PATH` environment variable is used in
121place of the `LIBCLANG_PATH` environment variable.
122
123### Runtime
124
125The `clang_sys::load` function is used to load a `libclang` shared library for use in the thread in
126which it is called. The `clang_sys::unload` function will unload the `libclang` shared library.
127`clang_sys::load` searches for a `libclang` shared library in the same way one is searched for when
128linking to `libclang` dynamically at compiletime.
129