gtk-rs / gir

Tool to generate rust bindings and user API for glib-based libraries
https://gtk-rs.org/gir/book/
MIT License
230 stars 102 forks source link

Suggestion: Remove dox feature in favor of rustc args #1454

Closed AaronErhardt closed 1 year ago

AaronErhardt commented 1 year ago

Cargo features are supposed to be additive, but the "dox" feature isn't. Compiling with "dox" skips compile time checks for the underlying C libraries and therefore should not be enabled during normal development.

A better solution would be to use a "docsrs" or "dox" config argument for rustc directly. This seems to be what most crates do and it's also what docs.rs recommends. This would make possible to use --all-features again and removes the need to pass the "dox" feature to the dependencies.

The code for conditional compilation would only change from #[cfg(feature = "dox")] to #[cfg(dox)].

This doesn't only affect the gtk4 crate, so feel free to move the issue if there's a better repo for this topic.

sdroege commented 1 year ago

How do you pass that via cargo so that it can be enabled as part of cargo doc? Via rustc I'm aware, I'm using that mechanism in some non-cargo project of mine.

AaronErhardt commented 1 year ago

It's as simple as using the RUSTFLAGS or RUSTDOCFLAGS env variables, for example RUSTDOCFLAGS='--cfg docsrs' cargo doc

sdroege commented 1 year ago

Not nice but I guess OK because we only do that via generator.py anyway.

bilelmoussaoui commented 1 year ago

This should probably be moved to gir itself, then whatever change happens there will propagate to all the bindings once that gets fixed.

sdroege commented 1 year ago

@AaronErhardt Do you want to work on adding this?

AaronErhardt commented 1 year ago

Yes, I think I should have some time to come up with a PR in the next few days.