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

Replaccement for convert_headers? #64

Open
freemin7 opened this issue Apr 4, 2021 · 1 comment
Open

Replaccement for convert_headers? #64

freemin7 opened this issue Apr 4, 2021 · 1 comment

Comments

@freemin7
Copy link

freemin7 commented Apr 4, 2021

Hey, i used CBindingGen for my project and now want migrate away from it. I ran the following buildscript:

using CBindingGen

include_dir = try
    ENV["JULIA_WORHP_INCLUDE_PATH"]
catch
    "/usr/include/worhp/"
end

shared_library_so = try
    ENV["JULIA_LIBWORHP_SO"]
catch
    "/usr/lib64/libworhp.so"
end

header_files = joinpath.(include_dir,filter(readdir(include_dir)) do name
    endswith(name,".h") && !startswith(name,"monitor")
end)

converted_header = convert_headers(header_files, args = ["-I", include_dir]) do cursor
    header = CodeLocation(cursor).file

    startswith(header, include_dir) || endswith(header,"stdbool.h") || return false
    println(header)
    return true
end

open("bindings.jl", "w+") do io
	generate(io,shared_library_so => converted_header)
end

txt = read("bindings.jl", String)

open("bindings.jl", "w") do f
	write(f, replace(txt, "InitError" => "InitErr")) #Blase Baremodule
end

How would i replace the convert_headers loop, since that's not part of CBinding?

Thank you?

@krrutkow
Copy link
Member

krrutkow commented Apr 4, 2021

Are you referring to using convert_header's do-lambda function as a filter for what gets converted? That was more of a crutch to avoid problematic code. So there is no way to filter out individual items, but the new framework should produce nearly ideal results and it does support header file granularity of filtering (if you explicitly include the header, it will be converted, otherwise it will not). So with your example, usage might look something like this:

c`-I$(include_dir) -L$(dirname(shared_library_so)) -l$(basename(shared_library_so))`
c"""
  #include <worhp.h>   // possibly `#include <worhp/worhp.h>` instead
"""ji

The i option for the C string macro allows conversion of the explicitly included header files as well as any implicitly included header files that are found in the same directory structure as the explicitly included files. If you want to drop the i option and explicitly include every header file, that could be done as well.

The j option creates Julia names for converted items, the J option can be used instead if annotated types (with struct_, union_, or enum_ prefixes) are needed to avoid name collisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants