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

crystal_lib_gen #2

Open
fazibear opened this issue Jan 5, 2015 · 4 comments
Open

crystal_lib_gen #2

fazibear opened this issue Jan 5, 2015 · 4 comments

Comments

@fazibear
Copy link

fazibear commented Jan 5, 2015

Here is my quite working tool for generating C bindings in Crystal
Written in ruby, based on gen_ffi gem.

https://github.com/fazibear/crystal_lib_gen

Hope you like it :)

@asterite
Copy link
Member

asterite commented Jan 5, 2015

Wow, that's AWESOME!!

I followed the README instructions and it worked flawlessly :-)

I think that eventually we'll want a tool like this to be integrated in the compiler (or at least as a companion to the main binary) because it will make it so much easier to write C bindings. So preferably we would have this written in Crystal, but for now it's really, really good to have this and we will definitely use it and encourage others to use it until we get to the point when it is written in Crystal.

Just a small thing: I tried to run it with libuv and I get an undefined methoddowncase' for nil:NilClass`. I tried to debug it without much luck. Here's the code I was using:

FFIGen.generate(
  module_name: "LibUV",
  ffi_lib:     "libuv",
  headers:     %w[
                uv.h
               ],
  cflags:      ['-I/usr/local/opt/libuv/include/'],
  prefixes:    [],
  output:      "out/libuv.cr"
)

And I installed it with brew install libuv.

And a request: I tried to put "git" on the list of prefixes and it generated the functions like this:

@[Link("libgit2")]
lib Git2
    fun repository_open(out : Void**, path : UInt8*) : Int16
end

Would it be possible to generate this instead:

@[Link("libgit2")]
lib Git2
    fun repository_open = git_repository_open(out : Void**, path : UInt8*) : Int16
end

Because the lib already acts as a namespace and it'll be shorter and easier to write.

Again, thanks!

@fazibear
Copy link
Author

fazibear commented Jan 5, 2015

You're right! Prefix support added.

This should work to all possibile function names.

@[Link("libgit2")]
lib Git2
    fun repository_open = "git_repository_open"(out : Void**, path : UInt8*) : Int16
end

@fazibear
Copy link
Author

fazibear commented Jan 5, 2015

I have to look at libuv, this one not work.

@asterite
Copy link
Member

asterite commented Jan 5, 2015

That was fast! Thanks!

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