Clang.jl on a Header with Function Overloading

luke-kiernan
Tue, 15 Apr 2025 02:57:53 +0000
General Usage

Is it possible to use Clang.jl to parse a header that uses the overloadable attribute? When I try, it only parses the first function with each name. Here’s my build setup: you’ll have to be on an Apple Silicon Mac to run this, though. (My goal is to automate the generation of Julia wrappers for Apple Accelerate libraries, instead of writing them by hand like I did here.)

using Clang.Generators
using Clang.LibClang.Clang_jll

cd(@__DIR__)

include_dir = normpath(Clang_jll.artifact_dir, "include")
options = load_options(joinpath(@__DIR__, "generator.toml"))
args = get_default_args()
push!(args, "-I$include_dir")
# may need to replace MacOSX15.sdk with a different version number.
headers = ["/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/"*
            "Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework"*
            "/Versions/A/Headers/Sparse/Solve.h"]
ctx = create_context(headers, args, options)
build!(ctx)

generator.toml (8.6 KB)
I may open an issue on the GitHub repo as well: naively, it seems like it shouldn’t be too hard to add as a feature.

Edit: for a simple MWE, the tgsin code snippet in the clang docs works just fine. Copy-paste that into a .h file and build a Julia library from it, using the default generator.toml: you only get a single function definition, for tgsin(x::Cfloat).

1 post - 1 participant