Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo features user experience #627

Open
AlexanderEkdahl opened this issue Jun 9, 2024 · 5 comments
Open

Cargo features user experience #627

AlexanderEkdahl opened this issue Jun 9, 2024 · 5 comments
Labels
A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates question Further information is requested

Comments

@AlexanderEkdahl
Copy link
Contributor

AlexanderEkdahl commented Jun 9, 2024

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 madsmtm added question Further information is requested A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates labels Jun 9, 2024
@madsmtm
Copy link
Owner

madsmtm commented Jun 9, 2024

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
Copy link
Contributor Author

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?

@madsmtm
Copy link
Owner

madsmtm commented Sep 17, 2024

I've been thinking about this again, and perhaps it would indeed make sense to make all features be enabled by default, and allowing users to opt out with default-features = false. I find in the few projects that I use the libraries in myself, that I end up always enabling the "all" feature, it's only in winit that I tune it down.

@AlexanderEkdahl
Copy link
Contributor Author

With the "all" feature I find the developer experience to be perfectly acceptable.

I only wish it was more prominently visible in the README so that when I add a crate I can configure it correctly. I started a new project this morning and I had to find this thread 😃

I worry that if everything is enabled by default users (specifically users who depend on objc2-* transitively) will complain about long compile times.

@madsmtm
Copy link
Owner

madsmtm commented Sep 29, 2024

I only wish it was more prominently visible in the README so that when I add a crate I can configure it correctly. I started a new project this morning and I had to find this thread 😃

Yeah, that's part of why I've left this issue open, I still want to improve the docs on this!

I worry that if everything is enabled by default users (specifically users who depend on objc2-* transitively) will complain about long compile times.

That's also a worry of mine, and I know that some people reflexively use default-features = false everywhere for partly this reason. Idk., still have to think about it.

@madsmtm madsmtm added this to the objc2 v0.6 / frameworks v0.3 milestone Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants