Skip to content
Open
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ clang_15_0 = ["clang_14_0"]
clang_16_0 = ["clang_15_0"]
clang_17_0 = ["clang_16_0"]
clang_18_0 = ["clang_17_0"]
clang_19_0 = ["clang_18_0"]
clang_20_0 = ["clang_19_0"]

runtime = ["libloading"]
static = []
Expand All @@ -64,4 +66,4 @@ tempfile = ">=3.0.0, <3.7.0"

[package.metadata.docs.rs]

features = ["clang_18_0", "runtime"]
features = ["clang_20_0", "runtime"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ To target a version of `libclang`, enable a Cargo features such as one of the fo
* `clang_3_5` - requires `libclang` 3.5 or later
* `clang_3_6` - requires `libclang` 3.6 or later
* etc...
* `clang_17_0` - requires `libclang` 17.0 or later
* `clang_18_0` - requires `libclang` 18.0 or later
* `clang_19_0` - requires `libclang` 19.0 or later
* `clang_20_0` - requires `libclang` 20.0 or later

If you do not enable one of these features, the API provided by `libclang` 3.5 will be available by default.

Expand Down Expand Up @@ -88,8 +88,8 @@ The availability of `llvm-config` is not optional for static linking. Ensure tha

#### Static Library Availability

Linking to `libclang` statically on *nix systems requires that the `libclang.a` static library be available.
This library is usually *not* included in most distributions of LLVM and Clang (e.g., `libclang-dev` on Debian-based systems).
Linking to `libclang` statically on *nix systems requires that the `libclang.a` static library be available.
This library is usually *not* included in most distributions of LLVM and Clang (e.g., `libclang-dev` on Debian-based systems).
If 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.

Here's an example of building the required static libraries and using them with `clang-sys`:
Expand All @@ -108,7 +108,7 @@ cd clang-sys
LLVM_CONFIG_PATH=../llvm-project/build/bin/llvm-config cargo test --features static
```

Linking to `libclang` statically requires linking a large number of big static libraries.
Linking to `libclang` statically requires linking a large number of big static libraries.
Using [`rust-lld` as a linker](https://blog.rust-lang.org/2024/05/17/enabling-rust-lld-on-linux.html) can greatly reduce linking times.

### Runtime
Expand Down
102 changes: 100 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ cenum! {
const CXCallingConv_AArch64SVEPCS = 18,
/// Only produced by `libclang` 18.0 and later.
const CXCallingConv_M68kRTD = 19,
/// Only produced by `libclang` 19.0 and later.
const CXCallingConv_PreserveNone = 20,
/// Only produced by `libclang` 19.0 and later.
const CXCallingConv_RISCVVectorCall = 21,
}
}

Expand Down Expand Up @@ -375,7 +379,9 @@ cenum! {
const CXCursor_ObjCBoolLiteralExpr = 145,
const CXCursor_ObjCSelfExpr = 146,
/// Only produced by `libclang` 3.8 and later.
const CXCursor_OMPArraySectionExpr = 147,
const CXCursor_ArraySectionExpr = 147,
#[deprecated = "renamed to CXCursor_ArraySectionExpr in clang 19.0"]
const CXCursor_OMPArraySectionExpr = CXCursor_ArraySectionExpr,
/// Only produced by `libclang` 3.9 and later.
const CXCursor_ObjCAvailabilityCheckExpr = 148,
/// Only produced by `libclang` 7.0 and later.
Expand All @@ -392,6 +398,8 @@ cenum! {
const CXCursor_RequiresExpr = 154,
/// Only produced by `libclang` 16.0 and later.
const CXCursor_CXXParenListInitExpr = 155,
/// Only produced by `libclang` 19.0 and later.
const CXCursor_PackIndexingExpr = 156,
const CXCursor_UnexposedStmt = 200,
const CXCursor_LabelStmt = 201,
const CXCursor_CompoundStmt = 202,
Expand Down Expand Up @@ -559,6 +567,36 @@ cenum! {
const CXCursor_OMPErrorDirective = 305,
/// Only produced by `libclang` 18.0 and later.
const CXCursor_OMPScopeDirective = 306,
/// Only produced by `libclang` 19.0 and later.
const CXCursor_OMPReverseDirective = 307,
/// Only produced by `libclang` 19.0 and later.
const CXCursor_OMPInterchangeDirective = 308,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OMPAssumeDirective = 309,
/// Only produced by `libclang` 19.0 and later.
const CXCursor_OpenACCComputeConstruct = 320,
/// Only produced by `libclang` 19.0 and later.
const CXCursor_OpenACCLoopConstruct = 321,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCCombinedConstruct = 322,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCDataConstruct = 323,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCEnterDataConstruct = 324,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCExitDataConstruct = 325,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCHostDataConstruct = 326,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCWaitConstruct = 327,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCInitConstruct = 328,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCShutdownConstruct = 329,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCSetConstruct = 330,
/// Only produced by `libclang` 20.0 and later.
const CXCursor_OpenACCUpdateConstruct = 331,
#[cfg(not(feature="clang_15_0"))]
const CXCursor_TranslationUnit = 300,
#[cfg(feature="clang_15_0")]
Expand Down Expand Up @@ -1114,7 +1152,11 @@ cenum! {
/// Only produced by `libclang` 11.0 and later.
const CXType_Atomic = 177,
/// Only produced by `libclang` 15.0 and later.
const CXType_BTFTagAttributed = 178,
const CXType_BTFTagAttributed = 178,
/// Only produced by `libclang` 19.0 and later.
const CXType_HLSLResource = 179,
/// Only produced by `libclang` 20.0 and later.
const CXType_HLSLAttributedResource = 180,
}
}

Expand Down Expand Up @@ -1288,6 +1330,47 @@ cenum! {
}
}

cenum! {
/// Only available on `libclang` 19.0 and later.
#[cfg(feature = "clang_19_0")]
enum CX_BinaryOperatorKind {
const CX_BO_Invalid = 0,
const CX_BO_PtrMemD = 1,
const CX_BO_PtrMemI = 2,
const CX_BO_Mul = 3,
const CX_BO_Div = 4,
const CX_BO_Rem = 5,
const CX_BO_Add = 6,
const CX_BO_Sub = 7,
const CX_BO_Shl = 8,
const CX_BO_Shr = 9,
const CX_BO_Cmp = 10,
const CX_BO_LT = 11,
const CX_BO_GT = 12,
const CX_BO_LE = 13,
const CX_BO_GE = 14,
const CX_BO_EQ = 15,
const CX_BO_NE = 16,
const CX_BO_And = 17,
const CX_BO_Xor = 18,
const CX_BO_Or = 19,
const CX_BO_LAnd = 20,
const CX_BO_LOr = 21,
const CX_BO_Assign = 22,
const CX_BO_MulAssign = 23,
const CX_BO_DivAssign = 24,
const CX_BO_RemAssign = 25,
const CX_BO_AddAssign = 26,
const CX_BO_SubAssign = 27,
const CX_BO_ShlAssign = 28,
const CX_BO_ShrAssign = 29,
const CX_BO_AndAssign = 30,
const CX_BO_XorAssign = 31,
const CX_BO_OrAssign = 32,
const CX_BO_Comma = 33,
}
}

/// Only available on `libclang` 17.0 and later.
#[cfg(feature = "clang_17_0")]
#[cfg(not(target_os = "windows"))]
Expand Down Expand Up @@ -2010,6 +2093,12 @@ link! {
pub fn clang_Cursor_isNull(cursor: CXCursor) -> c_int;
pub fn clang_Cursor_isObjCOptional(cursor: CXCursor) -> c_uint;
pub fn clang_Cursor_isVariadic(cursor: CXCursor) -> c_uint;
/// Only available on `libclang` 19.0 and later.
#[cfg(feature = "clang_19_0")]
pub fn clang_Cursor_getBinaryOpcode(cursor: CXCursor) -> CX_BinaryOperatorKind;
/// Only available on `libclang` 19.0 and later.
#[cfg(feature = "clang_19_0")]
pub fn clang_Cursor_getBinaryOpcodeStr(op: CX_BinaryOperatorKind) -> CXString;
/// Only available on `libclang` 5.0 and later.
#[cfg(feature = "clang_5_0")]
pub fn clang_EnumDecl_isScoped(cursor: CXCursor) -> c_uint;
Expand Down Expand Up @@ -2116,6 +2205,9 @@ link! {
/// Only available on `libclang` 3.7 and later.
#[cfg(feature = "clang_3_7")]
pub fn clang_Type_visitFields(type_: CXType, visitor: CXFieldVisitor, data: CXClientData) -> CXVisitorResult;
/// Only available on `libclang` 20.0 and later.
#[cfg(feature = "clang_20_0")]
pub fn clang_visitCXXBaseClasses(type_: CXType, visitor: CXFieldVisitor, data: CXClientData) -> CXVisitorResult;
pub fn clang_annotateTokens(tu: CXTranslationUnit, tokens: *mut CXToken, n_tokens: c_uint, cursors: *mut CXCursor);
pub fn clang_codeCompleteAt(tu: CXTranslationUnit, file: *const c_char, line: c_uint, column: c_uint, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, flags: CXCodeComplete_Flags) -> *mut CXCodeCompleteResults;
pub fn clang_codeCompleteGetContainerKind(results: *mut CXCodeCompleteResults, incomplete: *mut c_uint) -> CXCursorKind;
Expand Down Expand Up @@ -2226,6 +2318,9 @@ link! {
/// Only available on `libclang` 7.0 and later.
#[cfg(feature = "clang_7_0")]
pub fn clang_getCursorPrettyPrinted(cursor: CXCursor, policy: CXPrintingPolicy) -> CXString;
/// Only available on `libclang` 20.0 and later.
#[cfg(feature = "clang_20_0")]
pub fn clang_getTypePrettyPrinted(type_: CXType, cx_policy: CXPrintingPolicy) -> CXString;
/// Only available on `libclang` 7.0 and later.
#[cfg(feature = "clang_7_0")]
pub fn clang_getCursorPrintingPolicy(cursor: CXCursor) -> CXPrintingPolicy;
Expand Down Expand Up @@ -2375,6 +2470,9 @@ link! {
pub fn clang_isTranslationUnit(kind: CXCursorKind) -> c_uint;
pub fn clang_isUnexposed(kind: CXCursorKind) -> c_uint;
pub fn clang_isVirtualBase(cursor: CXCursor) -> c_uint;
/// Only available on `libclang` 20.0 and later.
#[cfg(feature = "clang_20_0")]
pub fn clang_getOffsetOfBase(parent: CXCursor, base: CXCursor) -> c_longlong;
pub fn clang_isVolatileQualifiedType(type_: CXType) -> c_uint;
pub fn clang_loadDiagnostics(file: *const c_char, error: *mut CXLoadDiag_Error, message: *mut CXString) -> CXDiagnosticSet;
pub fn clang_parseTranslationUnit(index: CXIndex, file: *const c_char, arguments: *const *const c_char, n_arguments: c_int, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, flags: CXTranslationUnit_Flags) -> CXTranslationUnit;
Expand Down