Closed oisyn closed 9 months ago
Oh but with my change, bindgen still runs when not vendored
! It just doesn't run with vendored
without generate-bindings
.
There is one small caveat. It'll break if you used metis-rs with default-features = false
, because it then doesn't specify bindgen as a dependency. Unfortunately I don't think there's a way to have it enabled without any features and then disable it when using vendored
. But that's easily fixed by not using default-features = false
.
Ok, obviously not building bindgen is an advantage. Indeed, we (and a lot of folks in the rust ecosystem) structure crates like this so that a build of their project doesn't require any additional dependencies other then the default rust setup. (On windows, the default rust setup doesn't come with clang, for example, which this crate depended on).
However i'm not sure about this. bindgen has to run when not vendored, since in this case the sizes of
idx_t
andread_t
are only known at build time. But there is no way to enable it when vendored is not enabled.
As @oisyn mentioned, this PR doesn't change the behavior for when metis-rs
uses the system installed metis. Though I would add that in some cases it could also be useful to just ship pre-generated bindings for the set of idx_t
and read_t
's that you're willing to support for example.
Hi! I would appreciate it if this got merged. Is there anything you'd rather see done differently, or do you have concerns that haven't been addressed yet?
Hi, sorry this took longer than needed. I'm fine with the idea.
As you said this breaks when default-features is false. I think we should address this. Currently rustc complains about bindgen being missing, which can confuse users. Maybe we can silence that and instead print a compile_error that explains that either vendored or default features must be enabled?
I've addressed the issue. You now get a compile error when building without any features enabled explaining that you either need to enable "default" or "vendored".
The generated bindings on my side use unsigned ints to represent enums, instead of signed ints in this PR. I guess this can change across different versions of clang?
Yeah that's a common problem with generating bindings for Rust. I think it's a Windows vs Linux thing.
Since the METIS library in the
vendor
directory is essentially static (it requires a manual update), the bindings are technically also, but they are still regenerated on each build. This requires the user to have clang installed. The common approach in other Rust libraries is to regenerate the bindings manually, and have the file committed to the repo.This PR adds a feature,
generate-bindings
, which will generate a newbindings.rs
file based on METIS in thevendor
directory. The file itself is located inmetis-sys/gen/bindings.rs
and is committed as part of this PR. This feature also enablesvendored
.When building solely with
vendored
, it will use the pregenerated file and not be dependent on clang to be able to buildmetis-rs
. So withvendored
,metis-rs
is now purely dependent on Rust and nothing else.Also, when specifying
vendored
without default features, it no longer depends onbindgen
either, which makes a clean build very lean: