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

Clang.jl generated bindings #897

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mkitti
Copy link
Member

@mkitti mkitti commented Feb 2, 2022

Clang.jl is able to read C headers and automatically generate Julia bindings.

Following the instructions at https://juliainterop.github.io/Clang.jl/stable/ , I have generated a module LibHDF5.

As-is, I believe this is useful since HDF5.jl does not cover the entire HDF5 API. Also, currently this generator does not mangle the names. They are the same as their C functions, which may help some to port code from C or other languages to Julia.

The Clang.jl generator is also customizable. It may be possible to combine this with the current generator for HDF5.jl in order to expand the HDF5.API module to cover the entire API.

Questions

  1. Should we release an independent LibHDF5.jl package? Perhaps it could be another subdirectory package.
  2. Would we be interested in combining the Clang.jl generator with the current bindings to expand the generator for the API module to the entire API?

@mkitti mkitti marked this pull request as draft February 2, 2022 09:40
@mkitti
Copy link
Member Author

mkitti commented Feb 2, 2022

I created a prototype package at https://github.com/mkitti/LibHDF5.jl . Some manual edits needed to be made to the resulting generated module, but I hope to automate those shortly.

@musm
Copy link
Member

musm commented Feb 5, 2022

While I really like the simplicity of the current binding generator, using Clang.jl is probably the right future direction. I'd like to spend time to understand how the Clang.jl works here, so I hope you're ok with this process taking longer than usual.

@mkitti
Copy link
Member Author

mkitti commented Feb 5, 2022

Based on that feedback, what I will do is have the Clang.jl generator generate a version of api_defs.jl. We can copy and and paste methods lines from there and perhaps automate the addition of missing @bind statements in the future.

@mkitti
Copy link
Member Author

mkitti commented Feb 7, 2022

I now have a generator that generates @bind statements:
https://github.com/mkitti/LibHDF5.jl/blob/main/gen/bind_generator.jl

For example, here is a new set of H5PL bindings:
https://github.com/mkitti/LibHDF5.jl/blob/712b6e306a15de37f748727b37676aca70ea0664/src/bind.jl#L2368-L2384

@bind h5pl_set_loading_state(plugin_control_mask::Cuint)::herr_t "Error in h5pl_set_loading_state (not annotated)"

@bind h5pl_get_loading_state(plugin_control_mask::Ptr{Cuint})::herr_t "Error in h5pl_get_loading_state (not annotated)"

@bind h5pl_append(search_path::Ptr{Cchar})::herr_t "Error in h5pl_append (not annotated)"

@bind h5pl_prepend(search_path::Ptr{Cchar})::herr_t "Error in h5pl_prepend (not annotated)"

@bind h5pl_replace(search_path::Ptr{Cchar}, index::Cuint)::herr_t "Error in h5pl_replace (not annotated)"

@bind h5pl_insert(search_path::Ptr{Cchar}, index::Cuint)::herr_t "Error in h5pl_insert (not annotated)"

@bind h5pl_remove(index::Cuint)::herr_t "Error in h5pl_remove (not annotated)"

@bind h5pl_get(index::Cuint, path_buf::Ptr{Cchar}, buf_size::Csize_t)::Cssize_t "Error in h5pl_get (not annotated)"

@bind h5pl_size(num_paths::Ptr{Cuint})::herr_t "Error in h5pl_size (not annotated)"

@mkitti
Copy link
Member Author

mkitti commented Jul 5, 2022

Closing since we currently do not plan to merge this. However, many of the generated bindings from LibHDF5.jl have been integrated manually.

https://github.com/mkitti/LibHDF5.jl/blob/main/src/bind.jl

@mkitti mkitti closed this Jul 5, 2022
@musm musm reopened this Jul 19, 2022
@musm
Copy link
Member

musm commented Jul 19, 2022

Going to leave this open since it probably makes sense to use this, just haven't gotten around to testing things out yet.

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

Successfully merging this pull request may close these issues.

None yet

2 participants