madsmtm / objc2

Bindings to Apple's frameworks in Rust
https://docs.rs/objc2/
MIT License
310 stars 40 forks source link

Cargo features user experience #627

Open AlexanderEkdahl opened 4 weeks ago

AlexanderEkdahl commented 4 weeks ago

As I mentioned earlier, excellent work on these libraries and generators!

That said, I find it frustrating to have to specify the feature for every class I want to use (objc2-metal has 61 features). Should features be enabled by default and libraries that want to reduce code only specify the functionality they need?

I understand that this might be necessary when one crate extends the functionality of another.

Is there a Cargo feature to enable every feature of a crate?

madsmtm commented 4 weeks ago

That said, I find it frustrating to have to specify the feature for every class I want to use (objc2-metal has 61 features). Should features be enabled by default and libraries that want to reduce code only specify the functionality they need?

Hmm, I guess they could all be enabled by default, though it really is a lot of code that's being compiled (objc2-foundation takes 4.5s and objc2-app-kit 9s on my fairly new Mac, a lot more on my older machine),

Is there a Cargo feature to enable every feature of a crate?

Yes there is, it's called all, and is documented in here. Please tell me how to improve the documentation such that you didn't have to ask this question (not that I mind, it's just unfortunate that you had to spend time doing so ;) ). Though now that I'm saying it, a tutorial that shows using "all" to begin with, and then narrows it down later on, would probably do the trick.

AlexanderEkdahl commented 3 weeks ago

Oh, I had no idea about the "magic string" "all". That certainly solves the problem.

Personally I don't mind waiting 9 seconds for something to compile if it saves me 30 minutes of debugging/enabling features. However, I can see how having the capability to turn features on/off is beneficial (especially for libraries). I would expect the linker to remove the unused code but that may not be enabled by default?

Please tell me how to improve the documentation such that you didn't have to ask this question

I was copy-pasting the objc2-metal example to get up-and-running. I'm not sure where it would be natural to introduce the "all" feature as I do believe it is a good starting point for someone who wants to get up and running with an Apple library from Rust.

Maybe a new section in the main README.md that introduces the objc-* crates or in the minimal Readme found on the crates.io documentation?