-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# Example script to wrap PETSc | ||
# | ||
|
||
using Clang.cindex | ||
using Clang.wrap_c | ||
|
||
PETSC_INCLUDE = abspath("/usr/include/petsc") | ||
MPI_INCLUDE = "/usr/include/openmpi" | ||
JULIA_ROOT=abspath(JULIA_HOME, "../../") | ||
|
||
LLVM_VER = "3.3" | ||
LLVM_BUILD_TYPE = "Release+Asserts" | ||
|
||
LLVM_PATH = joinpath(JULIA_ROOT, "deps/llvm-$LLVM_VER") | ||
This comment has been minimized.
Sorry, something went wrong. |
||
clanginc_path = joinpath(LLVM_PATH, "build/$LLVM_BUILD_TYPE/lib/clang/3.3/include") | ||
|
||
petsc_hdrs = [joinpath(PETSC_INCLUDE, "petsc.h")] | ||
|
||
clang_includes = map(x::ASCIIString->joinpath(LLVM_PATH, x), [ | ||
"build/$LLVM_BUILD_TYPE/lib/clang/3.3/include", | ||
"build/include/", | ||
"include" | ||
]) | ||
push!(clang_includes, PETSC_INCLUDE) | ||
push!(clang_includes, MPI_INCLUDE) | ||
clang_extraargs = ["-v"] | ||
# clang_extraargs = ["-D", "__STDC_LIMIT_MACROS", "-D", "__STDC_CONSTANT_MACROS"] | ||
|
||
# Callback to test if a header should actually be wrapped (for exclusion) | ||
function should_wrap(hdr::ASCIIString, name::ASCIIString) | ||
return beginswith(dirname(hdr), PETSC_INCLUDE) | ||
end | ||
|
||
function lib_file(hdr::ASCIIString) | ||
return "petsc" | ||
end | ||
|
||
function output_file(hdr::ASCIIString) | ||
return "PETSc.jl" | ||
end | ||
|
||
const wc = wrap_c.init("libPETSc_h.jl", "libPETSc_common.jl", clang_includes, | ||
clang_extraargs, | ||
should_wrap, | ||
lib_file, | ||
output_file) | ||
|
||
function wrap_libPETSc(wc::WrapContext, wrap_hdrs) | ||
wrap_c.wrap_c_headers(wc, wrap_hdrs) | ||
end |
6 comments
on commit 1489ab3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output here: https://gist.github.com/ihnorton/6331142
I need to tweak the exclusion criteria a little bit because right now it is pulling in hdf5 and other externals that we don't actually want to wrap. Loading takes about 6 seconds - which is faster than I expected.
fwiw, I agree with you about wrapping high-level APIs. I don't think clang.jl is worth the trouble for less than at least several dozen functions. The real goal of writing it was as a foundation for a C++ wrapper generator, which is much less practical to do manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to get this file to work anymore. I updated the paths to those on my system, commented out the reference to the obsolete wc.cache_wrapped
field, and it ran without printing an error, but no output was produced.
Also, I don't understand why this is so complicated. Why shouldn't it suffice to do
using Clang
using Clang.cindex
function should_wrap(top_hdr, cursor_hdr)
println("hdr_wrapped: $top_hdr, $cursor_hdr")
return startswith(basename(cursor_hdr), "petsc")
end
context = Clang.wrap_c.init(common_file="petsc_h.jl",
output_dir="petsc",
header_library=x->"petsc",
clang_includes=["/usr/local/include"],
header_wrapped = should_wrap,
clang_diagnostics=true)
context.headers = ["/usr/local/include/petsc.h"]
? This produces an output file, at least, but the output file is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you get a chance to update this soon, that would be great. I was hoping to work on the PETSc Julia wrappers, but I wanted to Clang-ify petsc.h
first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a couple small but blocking bugs. Updated now. The output is somewhat expansive, mostly due to trying much harder now with macros (of which petsc uses many) than in Aug 2013. It may take some more tweaking here and in wrap_c to get down to repeatable re-generation without hand-editing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the gist with the latest generator output (this is against petsc-dev 3.4.2 on ubuntu 14.04)
Why does this LLVM_PATH stuff need to be included in the script? Isn't that set up by
Pkg.build("Clang")
?