cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Decoupling this project from Cargo

Open dwlsalmeida opened this issue 2 years ago • 2 comments

Hi,

I was trying to use cbindgen in a meson project, and noticed that it is not possible currently.

Mainly, cbindgen expects to be able to call cargo expand, it also expects a Cargo.lock and to be able to call cargo metadata.

I wonder whether it is possible to decouple this project from Cargo, such that non-cargo projects can benefit from cbindgen like they do from bindgen itself.

Thoughts?

dwlsalmeida avatar Jan 30 '24 19:01 dwlsalmeida

Meson developer here, we likely can provide at least most of the data that cargo metadata does and pass that via the --metadata flag if that was what was required, thought the Cargo.lock is more problematic. cargo expand looks like it's just a wrapper around rustc anyway, so that should be fairly trivial to change, if that would be acceptable

dcbaker avatar Jan 30 '24 19:01 dcbaker

@dcbaker turns out that this works: cbindgen --lang c -- lib.rs

dwlsalmeida avatar Feb 10 '24 12:02 dwlsalmeida

Yeah, cargo is only used to compute metadata, if you feed cbindgen the right files / metadata it should work without cargo.

Please reopen if there's anything more concrete to do here. We really don't want to re-implement the cargo crate graph resolution ourselves if we can help it :)

emilio avatar Apr 14 '24 22:04 emilio

Hi @emilio

I think what is missing is explaining that this project can be used without Cargo in the README file.

Currently, there is only this:

cbindgen --config cbindgen.toml --crate my_rust_library --output my_header.h

So it is not far-fetched to say that people may think that using Cargo is a pre-requisite to use cbindgen, which is not true.

dwlsalmeida avatar Apr 20 '24 17:04 dwlsalmeida