analytech-solutions / cbindinggen.jl Goto Github PK
View Code? Open in Web Editor NEWAutomatically generate Julia-C bindings!
License: MIT License
Automatically generate Julia-C bindings!
License: MIT License
One of the C header files for which I used CBindingGen.jl
contained $
signs, which caused Julia to produce numerous errors like this
syntax: invalid interpolation syntax: "$ "
Is there a way to disable comment generation and/or to automatically convert $
in docstrings to something innocuous(, e.g., `
)?
Inline functions could be transformed from the C AST into a Julia AST.
Julia 1.6 will use LLVM 11.0.1; so this package will have to support that as well in order to work on 1.6, I think? See also JuliaLang/julia#39160 (comment)
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
Such as Core.InitError
et al.
#define CONST (42)
#define FUNC(x,y) ((x)*(y))
should become something like
const CONST = 42
const FUNC = (x,y) -> x*y
A tricky situation occurs when this is done:
enum E {
E_1 = 0
#define E_1 0
};
But assuming the symbol already exists, we can also assume they are equivalent values, perhaps displaying a warning.
Conversion of the struct F3ret *p
redeclares the F3ret
struct.
typedef struct F3ret { int i; float f; } (*F3[3])(union { int i; float f; } x[1], struct F3ret *p);
I created some code to generate bindings for GNU Gettext library and it generated incorrect bindings. Any C macro that expands to a function name is translated into a Julia macro that expands to another macro. For instance:
๐ฃ๐ฅ.@doc """
## Reference
[libintl.h:358](./..\\..\\..\\..\\.julia\\artifacts\\c38e0f0854753b42d208bf7f62aafa3100ba3880\\include\\libintl.h:358:10)
""" :(@libintl_printf)
export @libintl_printf
macro libintl_printf() return quote (@__printf__) end end
# [...]
๐ฃ๐ฅ.@doc """
```
๐ฃ๐ฅ.@cextern __printf__(var\"?1?\"::๐ฃ๐ฅ.Ptr{๐ฃ๐ฅ.Cconst(๐ฃ๐ฅ.Cchar)}, var\"?vararg?\"...)::๐ฃ๐ฅ.Cint
```
## Reference
[libintl.h:361](./..\\..\\..\\..\\.julia\\artifacts\\c38e0f0854753b42d208bf7f62aafa3100ba3880\\include\\libintl.h:361:12)
""" __printf__
๐ฃ๐ฅ.@cextern __printf__(var"?1?"::๐ฃ๐ฅ.Ptr{๐ฃ๐ฅ.Cconst(๐ฃ๐ฅ.Cchar)}, var"?vararg?"...)::๐ฃ๐ฅ.Cint
But the macro @__printf__
doesn't exist:
julia> LibGettext.@libintl_printf
ERROR: UndefVarError: @__printf__ not defined
The same problem occurs with gettext
, ngettext
, etc.
The workaround for the lack of forward declarations in Julia propagates the type name at the type definition up through typedefs and such. Within a package this works, but when another package needs to use the higher-level typedef type names, they don't exist.
First of all, great work @krrutkow, thanks for putting in all the effort, and also for providing CBinding.jl as well!
I'm experiencing some issues while using CBindingGen.jl
and I am not sure whether it is a user question or a bug, thus I don't know if I should be asking here or on Discourse. Please let me know if I you feel like Discourse would be more appropriate!
I am trying to auto-generate bindings for the p4est library. One of the issues I am experiencing there is that they forward declare (for some simple macro shenanigans) a function sc_extern_c_hack_3
(and _4
) multiple times, never providing a definition for it (it is a hack after all):
https://github.com/cburstedde/libsc/blob/7089d44934f34b60d6f63dded2cf774eebbfe1c9/src/sc.h#L110-L118
However, CBindingGen.jl
), generates a C function binding each time, like so
๐ฃ๐ฅ.@doc """
๐ฃ๐ฅ.@cextern sc_extern_c_hack_3()::๐ฃ๐ฅ.Cvoid
## Reference
[sc_containers.h:50](~/.julia/artifacts/9347f3407298e3ccce2b12eb83235b4d80ef8e54/include/sc_containers.h:50:1)
""" sc_extern_c_hack_3
export sc_extern_c_hack_3
๐ฃ๐ฅ.@cextern sc_extern_c_hack_3()::๐ฃ๐ฅ.Cvoid
Thus my question is: Is there a way to avoid generating a binding multiple times (i.e., like some sort of unique
pass before the generation process)? And if not, what would be the best way to get rid of it - maybe filtering for it like here:
CBindingGen.jl/deps/generate.jl
Line 25 in 1043a00
While trying to generate bindings for a C library in deps/build.jl
, I cannot get past the call to convert_headers
, since it always throws an error as
โ ERROR: LoadError: Errors encountered parsing headers, unable to proceed with conversion
โ Stacktrace:
โ [1] error(::String) at ./error.jl:33
โ [2] (::CBindingGen.var"#18#21"{var"#1#2",Array{String,1}})(::String) at /home/mschlott/.julia/packages/CBindingGen/BiQcs/src/CBindingGen.jl:193
โ [3] mktempdir(::CBindingGen.var"#18#21"{var"#1#2",Array{String,1}}, ::String; prefix::String) at ./file.jl:709
โ [4] mktempdir(::Function, ::String) at ./file.jl:707 (repeats 2 times)
โ [5] convert_headers(::Function, ::Array{String,1}; args::Array{String,1}) at /home/mschlott/.julia/packages/CBindingGen/BiQcs/src/CBindingGen.jl:169
โ [6] top-level scope at /mnt/ssd/home/mschlott/code/SEAL.jl/deps/build.jl:56
โ [7] include(::String) at ./client.jl:457
โ [8] top-level scope at none:5
โ in expression starting at /mnt/ssd/home/mschlott/code/SEAL.jl/deps/build.jl:56
I have tried looking at CBindingGen.jl:193
, but I cannot figure out how to make LibClang tell me what is actually the problem (e.g., is it a bad include directory, or is it something in the headers themselves etc.). Can you give me advice on how to proceed here, i.e., how to debug the error that caused this message?
I followed the example
CBindingGen.jl/deps/generate.jl
Line 22 in 1043a00
to only generate wrappers for library headers, not system headers. However, is there a simple way to get external dependencies like the Ptr{FILE}
to work, which is the reason (I assume) for the error I get during pre-compilation:
[ Info: Precompiling P4est [7d669430-f675-4ae7-b43e-fab78ec5a902]
ERROR: LoadError: LoadError: LoadError: UndefVarError: FILE not defined
Stacktrace:
[1] top-level scope at /home/mschlott/.julia/packages/CBinding/Vcw7p/src/cbindings.jl:92
[2] eval(::Module, ::Any) at ./boot.jl:331
[3] top-level scope at /home/mschlott/.julia/packages/CBinding/Vcw7p/src/cbindings.jl:801
[4] include(::Function, ::Module, ::String) at ./Base.jl:380
[5] include(::Module, ::String) at ./Base.jl:368
[6] top-level scope at /home/mschlott/gdrive/work/code/p4est/P4est.jll/src/libp4est.jl:5
[7] include(::Function, ::Module, ::String) at ./Base.jl:380
[8] include at ./Base.jl:368 [inlined]
[9] include(::String) at /home/mschlott/gdrive/work/code/p4est/P4est.jll/src/P4est.jl:1
[10] top-level scope at /home/mschlott/gdrive/work/code/p4est/P4est.jll/src/P4est.jl:3
[11] include(::Function, ::Module, ::String) at ./Base.jl:380
[12] include(::Module, ::String) at ./Base.jl:368
[13] top-level scope at none:2
[14] eval at ./boot.jl:331 [inlined]
[15] eval(::Expr) at ./client.jl:467
[16] top-level scope at ./none:3
in expression starting at /home/mschlott/gdrive/work/code/p4est/P4est.jll/deps/libp4est.jl:4
in expression starting at /home/mschlott/gdrive/work/code/p4est/P4est.jll/src/libp4est.jl:5
in expression starting at /home/mschlott/gdrive/work/code/p4est/P4est.jll/src/P4est.jl:3
ERROR: Failed to precompile P4est [7d669430-f675-4ae7-b43e-fab78ec5a902] to /home/mschlott/.julia/compiled/v1.5/P4est/OxTLc_z5FAb.ji.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1290
[3] _require(::Base.PkgId) at ./loading.jl:1030
[4] require(::Base.PkgId) at ./loading.jl:928
[5] require(::Module, ::Symbol) at ./loading.jl:923
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.