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

Lua, Ruby, Haskell, Go Language bindings and FFI support #48

Open
e-dant opened this issue Jul 13, 2024 · 12 comments
Open

Lua, Ruby, Haskell, Go Language bindings and FFI support #48

e-dant opened this issue Jul 13, 2024 · 12 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@e-dant
Copy link
Owner

e-dant commented Jul 13, 2024

There are some languages with ecosystems which could benefit from this filesystem watcher.

This is an efficient, reasonably well tested filesystem watcher with a small, relatively stable API.

There isn't much to expose or package.

I think this is mostly a matter of figuring out the "right way" to expose a library with a C ABI to these languages, and then just doing it.

@e-dant e-dant added enhancement New feature or request help wanted Extra attention is needed labels Jul 13, 2024
@e-dant
Copy link
Owner Author

e-dant commented Jul 25, 2024

Python and Node.js are mostly done. I want to test them a bit more before uploading to pip and npm.

Haskell and Ruby were trickier.

  • Haskell doesn't compile C++ correctly. Their use of gcc seems to ignore a bunch of include paths and options needed to compile C++ correctly. A workaround might be a custom Setup.hs, but writing that in a way that's amenable to packaging isn't something I know how to do yet.

  • Ruby's Fiddle (ffi) module has some odd behavior when creating bindings for functions which take non-builtin types. For example, void* wtr_watcher_open(char const*, struct wtr_watcher_event) was problematic for Ruby. A workaround might be to write a Ruby extension (instead of just interfacing with a shared library over ffi).

@dunglas
Copy link

dunglas commented Sep 7, 2024

Would you consider Go bindings (using cgo)?

If it’s possible to call the library from pure C (exposing a C header file) this will be easy (and I can help with this).

@e-dant
Copy link
Owner Author

e-dant commented Sep 7, 2024

Would you consider Go bindings (using cgo)?

That sounds like a good idea to me

If it’s possible to call the library from pure C (exposing a C header file) this will be easy (and I can help with this).

I built one here: https://github.com/e-dant/watcher/blob/next/watcher-c/include/wtr/watcher-c.h

The C project builds as a static or shared library. It has some basic tests and examples (but of course the majority of our tests are elsewhere).

The C api may change, but not in dramatic ways. (You'll notice a second pipe-based api there, intended to make some language bindings easier. I'm thinking of removing it.)

@e-dant
Copy link
Owner Author

e-dant commented Sep 7, 2024

I can help with this

Thank you :)

@e-dant e-dant changed the title Python, Node.js, Ruby, Haskell? Language bindings Python, Node.js, Ruby, Haskell, Go Language bindings Sep 7, 2024
@dunglas
Copy link

dunglas commented Sep 8, 2024

Would you prefer bindings to be in this repository (a Go module) or in a separate one?
My preference would be to store it in this repo.

@e-dant
Copy link
Owner Author

e-dant commented Sep 8, 2024

Entirely up to you. This repo would work.

@e-dant
Copy link
Owner Author

e-dant commented Sep 8, 2024

If you choose to set it up in this repo, would you mind adding a little blurb for Go in the changelog for 0.12? Please do add an @dunglas to those parts of the changelog if you don't mind.

I'll cut a release soon. (Whenever Github resolves this InternalError: error creating tlog entry - (502) Bad Gateway issue when signing our workflow artifacts.)

@e-dant e-dant changed the title Python, Node.js, Ruby, Haskell, Go Language bindings Ruby, Haskell, Go Language bindings Oct 31, 2024
@gnois
Copy link

gnois commented Nov 1, 2024

Would you consider passing the wtr_watcher_event by address to the wtr_watcher_callback, instead of by value? Specifically LuaJIT ffi does not support callback with pass by value argument.

Fyi, libuv had this discussion too.

@e-dant
Copy link
Owner Author

e-dant commented Nov 1, 2024

Would you consider passing the wtr_watcher_event by address to the wtr_watcher_callback, instead of by value? Specifically LuaJIT ffi does not support callback with pass by value argument.

Fyi, libuv had this discussion too.

Yes, I think that's worth exploring.

While the project is still major version 0, I do try not to break things... but portability is important.


Maybe another function, which passes events by reference, is appropriate here?

Maybe another function which, instead of being callback-based, is pipe-based, is also appropriate? (Would that make things even easier?)

@gnois
Copy link

gnois commented Nov 1, 2024

Not sure how a pipe-based API would look like... But I'd be content with the current callback based API with pass by addr argument, which would already make LuaJIT ffi easy. :)

@e-dant e-dant changed the title Ruby, Haskell, Go Language bindings Lua, Ruby, Haskell, Go Language bindings Nov 1, 2024
@e-dant e-dant changed the title Lua, Ruby, Haskell, Go Language bindings Lua, Ruby, Haskell, Go Language bindings and FFI support Nov 1, 2024
@e-dant
Copy link
Owner Author

e-dant commented Nov 2, 2024

I'd be content with the current callback based API with pass by addr argument, which would already make LuaJIT ffi easy. :)

WIP on 1f0853d

I want to add some documentation and roll over some bikeshedding stuff before cutting a release.

Re bikeshedding:

  • It is a bit redundant to have both wtr_watcher_open and ..._eventref_stream.
  • The name is long, and weird.
  • ... But, just changing the current api makes me worry. I'm hesitant to break compatibility without a compelling reason.

@dunglas
Copy link

dunglas commented Nov 2, 2024

My 2 cents: prefer breaking the API while it's still in 0.x than inherit a badly named or designed API for the whole life of the project 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants