mkDummySrc: rework to only stub bins if they actually exist #752
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The previous implementation would always unconditionally introduce a
crane-dummy-*
binary target as a means of ensuring that any workspaces which use the (unstable)bindeps
feature will have their binaries built. Unfortunately this meant causing headaches for certain projects (e.g. embedded projects which require additional linking handling which would naturally be missing for the dummy target coming out of nowhere).Instead, now we emulate cargo's
autobin
detection logic and only dummify binary targets if they exist (turning this logic off viapackage.autobin = false
inCargo.toml
is fully supported, as is explicitly defining[[bin]]
targets there as well) meaning fewer surprises for anyone bitten by this!It's also worth noting that either removing an existing or defining a new binary (either by defining a
[[bin]]
entry inCargo.toml
or by adding a new file insrc/bin/new.rs
orsrc/bin/new/main.rs
) will cause the deps-only derivation to be rebuilt once more. In my experience this is usually pretty rare during the lifecycle of a project that an extra rebuild here or there is not a showstopper, but please open an issue if this becomes a nuisance. For now I've chosen not to allow an opt-out of this behavior for the sake of simplicity of the change, but this can be revisited in the future.It's also worth noting that this auto-detection is not implemented for
bench
,example
, andtest
targets since those are definitely more likely to get added and result in unnecessary rebuilds and it's not clear to me (at this time) that this functionality would be needed anywhere.Fixes #444
Fixes #268
Checklist
docs/API.md
(or general documentation) with changesCHANGELOG.md