Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Separate libsc bindings #34

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
57 changes: 47 additions & 10 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ else
println("Use p4est library provided by P4est_jll")
end

sc_library = ""
if isempty(sc_library)
sc_library = P4est_jll.libsc_path
println("Use sc library provided by P4est_jll")
end


# Step 3a: Choose the p4est include path according to the settings
include_directories = String[]
Expand Down Expand Up @@ -153,11 +159,6 @@ else

# Step 4: Generate binding using the include path according to the settings

# Manually set header files to consider
hdrs = ["p4est.h", "p4est_extended.h",
"p6est.h", "p6est_extended.h",
"p8est.h", "p8est_extended.h"]

# Build list of arguments for Clang
include_args = String[]
@show include_directories
Expand All @@ -177,31 +178,67 @@ else
append!(include_args, ("-idirafter", xcode_include_path_cli, "-idirafter", xcode_include_path_gui))
end

# Manually set header files to consider
hdrs = ["p4est.h", "p4est_extended.h",
"p6est.h", "p6est_extended.h",
"p8est.h", "p8est_extended.h"]


# Step 4a: p4est bindings
# Convert symbols in header
cvts = convert_headers(hdrs, args=include_args) do cursor
header = CodeLocation(cursor).file
name = string(cursor)

# only wrap the libp4est and libsc headers
# only wrap the libp4est headers
dirname, filename = splitdir(header)
if !(filename in hdrs ||
startswith(filename, "p4est_") ||
startswith(filename, "p6est_") ||
startswith(filename, "p8est_") ||
startswith(filename, "sc_") ||
filename == "sc.h" )
startswith(filename, "p8est_"))
return false
end

# Ignore macro hacks
startswith(name, "sc_extern_c_hack_") && return false
startswith(name, "sc_") && return false

return true
end

# Write generated C bindings to file
const bindings_filename = joinpath(@__DIR__, "libp4est.jl")
rm(bindings_filename, force=true)
open(bindings_filename, "w+") do io
generate(io, p4est_library => cvts)
end


# Step 4a: p4est bindings
# Convert symbols in header
cvts = convert_headers(hdrs, args=include_args) do cursor
header = CodeLocation(cursor).file
name = string(cursor)

# only wrap the libsc headers
dirname, filename = splitdir(header)
if !(startswith(filename, "sc_") ||
filename == "sc.h" )
return false
end
startswith(name, "p4est_") && return false
startswith(name, "p6est_") && return false
startswith(name, "p8est_") && return false

# Ignore macro hacks
startswith(name, "sc_extern_c_hack_") && return false

return true
end

# Write generated C bindings to file
const bindings_filename = joinpath(@__DIR__, "libsc.jl")
rm(bindings_filename, force=true)
open(bindings_filename, "w+") do io
generate(io, sc_library => cvts)
end
end
Loading