obi1kenobi / cargo-semver-checks

Scan your Rust crate for semver violations.
Apache License 2.0
1.14k stars 73 forks source link

Skip bin-only targets in `--workspace` runs #163

Open obi1kenobi opened 1 year ago

obi1kenobi commented 1 year ago

What should cargo-semver-checks' behavior be when asked to semver-check a crate that only has a bin target? (a) It could exit 1 and report an error. (b) It could exit 0 without running any semver checks, and report that this was the case since there was no lib target in the crate. (c) It could run semver checks as if the bin target was a library.

Things to keep in mind:

I'm inclined toward option (b).

Option (c) would require that we check all bin targets present in addition to any lib target, which doesn't seem useful and may be confusing -- and may require adding additional logic if users want to exclude certain bin targets from checking.

And option (a) seems like it would be both more work and also like it might lead to some inconsistency: rustdoc JSON files don't inherently include info on whether they were generated for a lib or bin target, and it's possible to manually generate rustdoc JSON for bin targets and have cargo-semver-checks scan them.

obi1kenobi commented 1 year ago

Related to #162 since the JSON file's name by default is the name of the target, not the name of the crate. By default, lib targets share the name of the crate.

obi1kenobi commented 1 year ago

Also related to #86.

epage commented 1 year ago

Checking the API is meaningless and on its own, I think it'd deserve an error. We could have --workspace automatically skip [[bin]] only crates. That should be easy with cargo_metadata as it reports back package information with all of the implicit fields populated for us.

What would change my answer is when we start checking feature flags. I think I still lean towards erroring for [[bin]]]s as the focus is on APIs for crates and not crates generally.

obi1kenobi commented 1 year ago

Let's make checking bin-only crates an error, and make --workspace skip them automatically. If --workspace ends up skipping everything, that should be an error too.

Overall, asking for a semver-check that finds nothing that can be checked is an "mismatch between tool capabilities and user expectations" error, not a silent success.

obi1kenobi commented 7 months ago

As of #663 attempting to check bin-only targets is now an error.

I'm planning to start adding workspace-level tests to pin down cargo-semver-checks' behavior in workspaces.