This package provides a Julia language wrapper for libclang: the stable, C-exported interface to the LLVM Clang compiler. The libclang API documentation provides background on the functionality available through libclang, and thus through the Julia wrapper. The repository also hosts related tools built on top of libclang functionality.
This package is under an overhaul. It's highly recommended to use the master branch and the new generator API.
If you'd like to use the old version, please checkout this branch for the documentation. Should you have any questions on how to upgrade the generator script, feel free to submit a post/request in the Discussions area.
pkg> dev Clang
Clang.jl provides a module Clang.Generators
for auto-generating C library bindings for Julia language from C headers.
Write a config file generator.toml
:
[general]
library_name = "libclang"
output_file_path = "./LibClang.jl"
module_name = "LibClang"
jll_pkg_name = "Clang_jll"
export_symbol_prefixes = ["CX", "clang_"]
and a Julia script generator.jl
:
using Clang.Generators
using Clang.LibClang.Clang_jll
cd(@__DIR__)
include_dir = joinpath(Clang_jll.artifact_dir, "include") |> normpath
clang_dir = joinpath(include_dir, "clang-c")
options = load_options(joinpath(@__DIR__, "generator.toml"))
# add compiler flags, e.g. "-DXXXXXXXXX"
args = get_default_args()
push!(args, "-I$include_dir")
headers = [joinpath(clang_dir, header) for header in readdir(clang_dir) if endswith(header, ".h")]
# there is also an experimental `detect_headers` function for auto-detecting top-level headers in the directory
# headers = detect_headers(clang_dir, args)
# create context
ctx = create_context(headers, args, options)
# run generator
build!(ctx)
Please refer to this toml file for a full list of configuration options.
The generator is currently used by several projects and you can take them as examples.
- JuliaInterop/Clang.jl: the thin low-level LibClang.jl is generated by this package itself
- JuliaMultimedia/CSFML.jl: config multiple library names
- JuliaGraphics/FreeType.jl: select function-like macros
- maleadt/LLVM.jl: cross-platform support with patches
- JuliaWeb/LibCURL.jl: cross-platform build
- scipopt/SCIP.jl: applying custom patches by using
prologue.jl
&epilogue.jl
- JuliaLang/SuiteSparse.jl: config compiler definitions for cross-platform
- JuliaGPU/VulkanCore.jl: cross-platform build with third-party JLL dependencies
- JuliaGPU/oneAPI.jl: format the generated code with JuliaFormatter.jl