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 publish has bad error message when explicit [[bench]] isn't in package.include #13456

Closed
dhardy opened this issue Feb 18, 2024 · 9 comments · Fixed by #13713
Closed

cargo publish has bad error message when explicit [[bench]] isn't in package.include #13456

dhardy opened this issue Feb 18, 2024 · 9 comments · Fixed by #13713
Labels
C-bug Category: bug Command-package Command-publish S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@dhardy
Copy link

dhardy commented Feb 18, 2024

Problem

cargo publish fails

Steps

Using the latest rand commit:

$ cargo publish --dry-run
    Updating crates.io index
   Packaging rand v0.9.0-alpha.0 (/home/dhardy/projects/rand/rand)
    Updating crates.io index
   Verifying rand v0.9.0-alpha.0 (/home/dhardy/projects/rand/rand)
error: failed to verify package tarball

Caused by:
  failed to parse manifest at `/home/dhardy/projects/rand/rand/target/package/rand-0.9.0-alpha.0/Cargo.toml`

Caused by:
  can't find `uniform` bench at `benches/uniform.rs` or `benches/uniform/main.rs`. Please specify bench.path if you want to use a non-default path.

Possible Solution(s)

No response

Notes

The relevant part of the Cargo.toml:

[[bench]]
name = "uniform"
harness = false

This could have a path specified... but as far as I can tell, cargo publish is the only thing not happy to discover the default path (benches/uniform.rs).

Despite this, the benchmark works fine:

$ ls -l benches/uniform.rs 
-rw-r--r--. 1 dhardy dhardy 2696 Feb 13 11:39 benches/uniform.rs
$ cargo bench --bench uniform --features small_rng
   Compiling rand v0.9.0-alpha.0 (/home/dhardy/projects/rand/rand)
    Finished `bench` profile [optimized] target(s) in 2.28s
     Running benches/uniform.rs (target/release/deps/uniform-38f8da4b7c78a479)
samplei8/SmallRng/single
                        time:   [1.5141 ns 1.5143 ns 1.5145 ns]
[snip]

Steps

Version

cargo 1.78.0-nightly (fc1d58fd0 2024-02-09)
release: 1.78.0-nightly
commit-hash: fc1d58fd0531a57a6b942a14cdcdbcb82ece16f3
commit-date: 2024-02-09
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.6.0-DEV (sys:0.4.71+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Fedora 39 [64-bit]
@dhardy dhardy added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Feb 18, 2024
@epage
Copy link
Contributor

epage commented Feb 19, 2024

rand has package.include set:

include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"]

This doesn't include benches/.

When you use auto-detected benches, cargo publish works just fine because it will auto-detect among the bundled files and be fine.

When you add [[bench]] tables, cargo knows to look for them but they were not included, and so things error.

Possible ways to improve the experience for this:

  • Make the error clearer by explicitly checking whether targets were included
  • Auto-strip certain types of targets, like [[bench]] and [[test]]

@weihanglo
Copy link
Member

Auto-strip certain types of targets, like [[bench]] and [[test]]

I might be wrong, but doesn't crater run rely on tests being published to crates.io?

@epage epage changed the title cargo publish can't find benchmark cargo publish has bad error message when explicit [[bench]] isn't in package.include Feb 19, 2024
@epage
Copy link
Contributor

epage commented Feb 19, 2024

I meant "strip them if they aren't included", not "unconditionally strip them". It could also likely be a user-controlled lint so people can control whether they want to error or allow it (#12235).

@epage epage added S-needs-team-input Status: Needs input from team on whether/how to proceed. and removed S-triage Status: This issue is waiting on initial triage. labels Feb 19, 2024
@dhardy
Copy link
Author

dhardy commented Feb 20, 2024

Isn't inclusion in the package a separate issue?

I would expect

[[bench]]
name = "uniform"
harness = false

to behave identically to

[[bench]]
name = "uniform"
path = "benches/uniform.rs"
harness = false

where benches/uniform.rs exists, given that the former is already supported by cargo bench.

@epage
Copy link
Contributor

epage commented Feb 20, 2024

Interesting, I hadn't realized that the presence of path makes a difference.

The reason is that without path, we have to do target auto-detection which fails. With path, we skip that and only error if the target is activated.

This makes me think we'll only be able to handle this by stripping these target as erroring would likely break some existing cases. We could still warn though and once that is user controllable, they could turn that into an error.

@vincentdephily
Copy link

I think I'm hitting a variant of this, testing with cargo package. My Cargo.toml contains

[package]
exclude = ["benches"]
[[bench]]
# `benches/exec_compare.rs` is not meant to be run from cargo
name = "exec_compare"
bench = false

Which gives me

can't find `exec_compare` bench at `benches/exec_compare.rs` or `benches/exec_compare/main.rs`.
Please specify bench.path if you want to use a non-default path.

I can work around this by not excluding benches (but that's not the desired behavior), or by setting path="anything". The fact that even a bogus path value makes cargo happy is interesting.

bors added a commit that referenced this issue Mar 15, 2024
refactor(toml): Flatten manifest parsing

### What does this PR try to resolve?

This is just a clean up but the goals are
- Support diagnostics that show source by tracking `&str`, `ImDocument`, etc in `Manifest` by making each accessible in the creation of a `Manifest`
- Defer warning analysis until we know what is a local vs non-local workspace by refactoring warnings out into a dedicated step
- Centralize the logic for `cargo publish` stripping of dev-dependencies and their feature activations by allowing a `Summary` to be created from any "resolved" `TomlManifest`
- Enumerate all build targets in the "resolved" `TomlManifest` so they get included in `cargo publish`, reducing the work done on registry dependencies and resolving problems like #13456

Along the way, this fixed a bug where we were not reporting warnings from virtual manifests

### How should we test and review this PR?

### Additional information
bors added a commit that referenced this issue Mar 28, 2024
fix(toml): Warn on unused workspace.dependencies keys on virtual workspaces

### What does this PR try to resolve?

This splits out refactors that build on #13589 in preparation for resolving #13456.

As part of those refactors, I noticed an inconsistency on when we warn for unused keys.  We have parallel code paths between `to_virtual_manifest` and `to_real_manifest` and only one got updated on a change.  This syncs them up.  Hopefully the end state this builds to will reduce duplication.

### How should we test and review this PR?

### Additional information
bors added a commit that referenced this issue Mar 28, 2024
fix(toml): Warn on unused workspace.dependencies keys on virtual workspaces

### What does this PR try to resolve?

This splits out refactors that build on #13589 in preparation for resolving #13456.

As part of those refactors, I noticed an inconsistency on when we warn for unused keys.  We have parallel code paths between `to_virtual_manifest` and `to_real_manifest` and only one got updated on a change.  This syncs them up.  Hopefully the end state this builds to will reduce duplication.

### How should we test and review this PR?

### Additional information
bors added a commit that referenced this issue Mar 28, 2024
refactor(package): Simplify getting of published Manifest

### What does this PR try to resolve?

This is a parallel effort to #13664 in an effort to #13456

This abstracts away the logic for getting the published version of `Cargo.toml` so we can more easily change the APIs that were previously exposed

### How should we test and review this PR?

### Additional information
@heisen-li
Copy link
Contributor

At the time of upload,setting path but not verifying the validity of the path seems reasonable to me. But if bench = false is set, should existential checks be eliminated?

cargo book:

Setting targets to bench = false will stop them from being bencharmked by default.

I understand the implication here is that with bench = false set, Cargo will not execute benchmarks for crates with name=xx. Am I understanding this wrong?

@weihanglo
Copy link
Member

@heisen-li have not checked the code but I believe this is about target path auto-discovery inconsistency when packaging, not compiling default targets.

@epage
Copy link
Contributor

epage commented Mar 29, 2024

btw i have a solution in work. I am working to make it so published packages have all targets explicitly enumerated.

bors added a commit that referenced this issue Apr 3, 2024
refactor(toml): Split out an explicit step to resolve `Cargo.toml`

### What does this PR try to resolve?

This builds on #13664 and #13666.   Currently, once we have deserialized `Cargo.toml`, we pass it to a large machinery (`to_real_manifest`, `to_virtual_manifest`) so that
- `Cargo.toml` is resolved
- `Summary` is created
- `Manifest` is created

This splits out the resolving of `Cargo.toml` which is mostly workspace inheritance today.

While splitting logic conjoined like this can be a bit messy in the short term, the hope is that overall this makes the logic easier to follow (more condensed, focused sections to view; more explicit inputs/outputs).

In particular, I hope that this will make it clearer and easier to shift more logic into the resolving step, specifically the inferring of build targets for #13456.

### How should we test and review this PR?

This is broken up into very small steps in the hope that it makes it easier to analyze a step.

### Additional information
bors added a commit that referenced this issue Apr 5, 2024
refactor(toml): Decouple target discovery from Target creation

### What does this PR try to resolve?

This builds on #13693 so that the resolving of targets is easier to pull out into `resolve_toml` in prep for fixing #13456

### How should we test and review this PR?

### Additional information
@bors bors closed this as completed in ba6fb40 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-package Command-publish S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants