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

Publish fails when exluding files referenced by cargo targets using a default path #10182

Open
daxpedda opened this issue Dec 8, 2021 · 1 comment
Labels
C-bug Category: bug Command-package S-triage Status: This issue is waiting on initial triage.

Comments

@daxpedda
Copy link
Contributor

daxpedda commented Dec 8, 2021

Problem

When using package.exclude or package.include (which will exclude everything not included) on a file that is referenced by a Cargo target with a default path (not specifying a path), cargo publish will fail.

Steps

  1. Initialize an empty crate with the following Cargo.toml file:
[package]
name = "test-publish-target"
version = "0.0.0"
edition = "2021"
exclude = ["tests"]

[[test]]
name = "test"
test = false
  1. Run cargo publish --dry-run

Possible Solution(s)

Specifying a path solves the problem:

[[test]]
name = "test"
path = "tests/test.rs"
test = false

Notes

This was also reported here: https://users.rust-lang.org/t/cargo-publish-with-excluded-benchmark-fails-validation/53444. But I didn't find a corresponding issue report.

Version

cargo 1.57.0 (b2e52d7ca 2021-10-21)
release: 1.57.0
commit-hash: b2e52d7cab0a286ee9fcc0c17510b1e72fcb53eb
commit-date: 2021-10-21
host: x86_64-apple-darwin
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.77.0 (sys:0.4.49+curl-7.79.1 system ssl:(SecureTransport) LibreSSL/2.8.3)
os: Mac OS 12.0.1 [64-bit]
@daxpedda daxpedda added the C-bug Category: bug label Dec 8, 2021
@weihanglo
Copy link
Member

This should be improved by #10090, which provides a better error message. For example,

error: failed to verify package tarball

Caused by:
  failed to parse manifest at `/projects/issue10182/target/package/issue10182-0.1.0/Cargo.toml`

Caused by:
-  can't find `test` test, specify test.path
+  can't find `test` test at `tests/test.rs` or `tests/test/main.rs`. Please specify test.path if you want to use a non-default path.

We may check all paths of possible Cargo targets (either specified or unspecified) against exclude/include fields. We could share the ignore logic from cargo::core::path::PathSource to cargo::util::toml::targets. Then use the same ignore rule to suppress targets that are excluded.

Alternatively, we can craft a specialized message for missing file of a Cargo target for cargo package, telling that this may be due to file being excluded.

Both of the solution seem a bit overkill to me personally from Cargo implementation side.

@epage epage added the S-triage Status: This issue is waiting on initial triage. label Nov 20, 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 S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

4 participants