mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.29k stars 294 forks source link

Decoupling this project from Cargo #922

Closed dwlsalmeida closed 3 months ago

dwlsalmeida commented 5 months ago

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?

dcbaker commented 5 months ago

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

dwlsalmeida commented 5 months ago

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

emilio commented 3 months ago

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 :)

dwlsalmeida commented 2 months ago

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.