{"id":13648681,"url":"https://github.com/KyleMayes/clang-sys","last_synced_at":"2025-04-22T11:33:01.054Z","repository":{"id":3104290,"uuid":"48451751","full_name":"KyleMayes/clang-sys","owner":"KyleMayes","description":"Rust bindings for libclang.","archived":false,"fork":false,"pushed_at":"2024-09-25T01:20:53.000Z","size":526,"stargazers_count":136,"open_issues_count":14,"forks_count":68,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-29T16:25:00.713Z","etag":null,"topics":["rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KyleMayes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-22T20:09:34.000Z","updated_at":"2024-10-14T02:44:58.000Z","dependencies_parsed_at":"2024-02-26T01:49:46.971Z","dependency_job_id":"964c56b1-d669-4540-bb9f-ff714740406b","html_url":"https://github.com/KyleMayes/clang-sys","commit_stats":{"total_commits":393,"total_committers":32,"mean_commits":12.28125,"dds":"0.12468193384223913","last_synced_commit":"b7992e864eaa2c8cb5c014a52074b962f257e29b"},"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleMayes%2Fclang-sys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleMayes%2Fclang-sys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleMayes%2Fclang-sys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleMayes%2Fclang-sys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KyleMayes","download_url":"https://codeload.github.com/KyleMayes/clang-sys/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222247137,"owners_count":16955120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust"],"created_at":"2024-08-02T01:04:27.150Z","updated_at":"2024-11-09T23:30:27.912Z","avatar_url":"https://github.com/KyleMayes.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# clang-sys\n\n[![Crate](https://img.shields.io/crates/v/clang-sys.svg)](https://crates.io/crates/clang-sys)\n[![Documentation](https://docs.rs/clang-sys/badge.svg)](https://docs.rs/clang-sys)\n[![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)\n![MSRV](https://img.shields.io/badge/MSRV-1.60.0-blue)\n\nRust bindings for `libclang`.\n\nIf you are interested in a somewhat idiomatic Rust wrapper for these bindings, see [`clang-rs`](https://github.com/KyleMayes/clang-rs).\n\nReleased under the Apache License 2.0.\n\n## [Documentation](https://docs.rs/clang-sys)\n\nNote 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.\n\nDue 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.\n\nDue 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.\n\n## Supported Versions\n\nTo target a version of `libclang`, enable a Cargo features such as one of the following:\n\n* `clang_3_5` - requires `libclang` 3.5 or later\n* `clang_3_6` - requires `libclang` 3.6 or later\n* etc...\n* `clang_17_0` - requires `libclang` 17.0 or later\n* `clang_18_0` - requires `libclang` 18.0 or later\n\nIf you do not enable one of these features, the API provided by `libclang` 3.5 will be available by default.\n\n**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.\n\n## Dependencies\n\nBy 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.\n\nThese libraries can be either be installed as a part of Clang or downloaded [here](http://llvm.org/releases/download.html).\n\n**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.\n\n### Versioned Dependencies\n\nThis 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:\n\n1. `libclang-4.0.so`\n2. `libclang-4.so`\n3. `libclang-3.9.so`\n4. `libclang-3.so`\n5. `libclang.so`\n\n**Note:** On BSD distributions, versioned instances of `libclang.so` matching the pattern `libclang.so.*` (e.g., `libclang.so.7.0`) are also included.\n\n**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.\n\n## Environment Variables\n\nThe following environment variables, if set, are used by this crate to find the required libraries and executables:\n\n* `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`])\n* `LIBCLANG_PATH` **(compiletime)** - provides a path to a directory containing a `libclang` shared library or a full path to a specific `libclang` shared library\n* `LIBCLANG_STATIC_PATH` **(compiletime)** - provides a path to a directory containing LLVM and Clang static libraries\n* `CLANG_PATH` **(runtime)** - provides a path to a `clang` executable\n\n## Linking\n\n### Dynamic\n\n`libclang` shared libraries will be searched for in the following directories:\n\n* the directory provided by the `LIBCLANG_PATH` environment variable\n* the `bin` and `lib` directories in the directory provided by `llvm-config --libdir`\n* the directories provided by `LD_LIBRARY_PATH` environment variable\n* a list of likely directories for the target platform (e.g., `/usr/local/lib` on Linux)\n* **macOS only:** the toolchain directory in the directory provided by `xcode-select --print-path`\n\nOn 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.\n\nOn 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.\n\n### Static\n\nThe 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.\n\n**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.\n\n#### Static Library Availability\n\nLinking to `libclang` statically on *nix systems requires that the `libclang.a` static library be available.  \nThis library is usually *not* included in most distributions of LLVM and Clang (e.g., `libclang-dev` on Debian-based systems).  \nIf you need to link to `libclang` statically then most likely the only consistent way to get your hands on `libclang.a` is to build it yourself.\n\nHere's an example of building the required static libraries and using them with `clang-sys`:\n\n```text\ngit clone git@github.com:llvm/llvm-project.git\ncd llvm-project\n\ncmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS=clang -DLIBCLANG_BUILD_STATIC=ON\nninja -C build\n\ncd ..\ngit clone git@github.com:KyleMayes/clang-sys.git\ncd clang-sys\n\nLLVM_CONFIG_PATH=../llvm-project/build/bin/llvm-config cargo test --features static\n```\n\nLinking to `libclang` statically requires linking a large number of big static libraries.  \nUsing [`rust-lld` as a linker](https://blog.rust-lang.org/2024/05/17/enabling-rust-lld-on-linux.html) can greatly reduce linking times.\n\n### Runtime\n\nThe `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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyleMayes%2Fclang-sys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKyleMayes%2Fclang-sys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyleMayes%2Fclang-sys/lists"}