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

Make loom optional #43

Merged
merged 8 commits into from
Jun 10, 2024
Merged

Make loom optional #43

merged 8 commits into from
Jun 10, 2024

Conversation

faern
Copy link
Owner

@faern faern commented May 25, 2024

I have come to realize that with:

[target.'cfg(loom)'.dependencies]
loom = { version = "0.7.2", features = ["futures"] }

loom is pulled in as a mandatory dependency and pollutes Cargo.lock. This means it pollutes the dependency tree by quite a lot. This should be a small and lightweight library, so that's not ideal. Downstream users of this library should not need to have the entire loom dependency tree in their supply chain, they will/should never use it!

This PR explores making loom a proper optional dependency instead.

@faern faern force-pushed the make-loom-optional branch from 585b962 to 1938579 Compare May 25, 2024 10:01
@faern faern force-pushed the make-loom-optional branch from 1938579 to d7820e3 Compare June 10, 2024 07:47
@faern faern force-pushed the make-loom-optional branch from 2a77b4b to d4b041a Compare June 10, 2024 08:16
@faern faern marked this pull request as ready for review June 10, 2024 08:16
@faern
Copy link
Owner Author

faern commented Jun 10, 2024

This PR was inspired by crossbeam-rs/crossbeam#666. However, I do not understand why they went with putting the loom dependency both behind a cfg and a feature. I might be missing something here, but I can't see what benefit the cfg makes. It only complicates stuff. Cargo is not competent enough to see this cfg logic, and loom will be listed as an optional dependency even when put behind a cfg like this. That was the original problem, that loom was part of the dependency tree even when put behind a cfg.

Putting it behind a cfg as well as making it optional only introduced issues for me. Building with cargo build --features loom failed, because the feature was activated, but the dependency was not pulled in etc.

Making loom an optional feature only seems to solve the problem rather OK. Except for the fact that it's not really an additive feature, nor is it supposed to be used by consumers of this library. It would have been better if cargo had some "internal features" support.

@faern
Copy link
Owner Author

faern commented Jun 10, 2024

@Wuelle Maybe you would like to take a look? You helped improve the situation around loom just a few weeks ago. EDIT: I'm going to merge this, but please feel free to come with feedback and help me spot problems with this approach.

@faern faern merged commit d911a58 into main Jun 10, 2024
12 checks passed
@faern faern deleted the make-loom-optional branch June 10, 2024 08:56
@simonwuelker
Copy link
Contributor

@Wuelle Maybe you would like to take a look? You helped improve the situation around loom just a few weeks ago. EDIT: I'm going to merge this, but please feel free to come with feedback and help me spot problems with this approach.

Ah sorry, I totally missed this! I don't understand the combination of cfg + feature used by oneshot either - they probably want to keep their features additive so it does nothing unless the cfg is also enabled? Doesn't really make much sense imo... Your changes look fine, its what I would have done too. Keeping the dependency tree small is more important than strictly additive features in my opinion.

Also I agree, the way cargo deals with cfg parameters is quite - lacking. Another problem I personally ran into in another project is that since the cfg is usually also available to dependencies it invalidates the cache and causes huge recompiles... Using cargo rustc fixes that, but then cfg-dependent dependencies don't work anymore - anyways, I digress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants