JuliaInterop / Clang.jl

C binding generator and Julia interface to libclang
https://juliainterop.github.io/Clang.jl/
MIT License
217 stars 68 forks source link

Binding generation for MLIR fails due to C++ being present #470

Closed vchuravy closed 3 months ago

vchuravy commented 5 months ago

I currently don't have time to push this forward but the binding generator in https://github.com/JuliaLabs/MLIR.jl currently runs on top off #435 If I recall the issue the MLIR headers contain some C++ code that make generation fail.

@mofeing could you isolate some examples of what is failing here and maybe @Gnimuc has an idea on how to fix this properly instead of my hobbled together approach in #435

Gnimuc commented 3 months ago

need to add a C++ JLL environment to support this.

Gnimuc commented 3 months ago

maybe we can somehow reuse https://github.com/Gnimuc/ClangCompiler.jl/blob/master/src/platform/system.jl

Gnimuc commented 3 months ago

@vchuravy what LLVM version are you working on?

I tried LLVM16 and it looks like Clang.jl can handle it well.

https://github.com/Gnimuc/MLIR.jl/commit/17cb4e61554af2165560f3c825c1f53fcb3b6bed#diff-4eb27dac28b031df3cf7f13beb5184b4d51541faf3a375b9b7704f97f545d9cc

Gnimuc commented 3 months ago

ok. now I can reproduce the failure in https://github.com/Gnimuc/MLIR.jl/commit/c7b693a7cb194ff55b1efb7211e96ad063d6c9cb

[ Info: Processing header: /Users/gnimuc/.julia/artifacts/83a18f414eae212b19fdc137a4fcbd9982fc7ac4/include/mlir-c/BuiltinAttributes.h
 Clang.CLNamespace std
   Clang.CLNamespace __1
ERROR: LoadError: No support for code at /Users/gnimuc/.julia/artifacts/fbb170fa64a06b66dd9a16aaa21bf12848042d9a/aarch64-apple-darwin20/sys-root/usr/include/c++/v1/__config:817:1, please file an issue to Clang.jl.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] collect_top_level_nodes!(nodes::Vector{ExprNode}, cursor::Clang.CLNamespace, options::Dict{String, Any})
   @ Clang.Generators ~/.julia/dev/Clang/src/generator/top_level.jl:10
 [3] (::CollectTopLevelNode)(dag::ExprDAG, options::Dict{String, Any})
   @ Clang.Generators ~/.julia/dev/Clang/src/generator/passes.jl:0
 [4] build!(ctx::Context, stage::Clang.Generators.BuildStage)
   @ Clang.Generators ~/.julia/dev/Clang/src/generator/context.jl:176
 [5] top-level scope
   @ ~/.julia/dev/MLIR/bindings/make.jl:168
 [6] include(fname::String)
   @ Main ./sysimg.jl:38
 [7] top-level scope
   @ REPL[6]:1
in expression starting at /Users/gnimuc/.julia/dev/MLIR/bindings/make.jl:168
Gnimuc commented 3 months ago

patching #432 and #435 works well.

https://github.com/Gnimuc/MLIR.jl/commit/8df3d70b4a5b7fe94ae1f08f628e6079cd53408f

mofeing commented 3 months ago

The problem seems to be on processing this file: https://github.com/llvm/llvm-project/blob/main/libcxx/include/__config