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

Workspace with multiple members using the same example name results in filename conflict #14769

Closed
sdroege opened this issue Nov 1, 2024 · 4 comments
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@sdroege
Copy link
Contributor

sdroege commented Nov 1, 2024

Problem

If a cargo workspace contains multiple member crates that have an example with the same name then the executable of that example is stored place for all of them.

Steps

  1. Create a workspace of the following shape (actual file content doesn't really matter)
a/Cargo.toml
a/src
a/src/lib.rs
a/examples
a/examples/dummy.rs
b/Cargo.toml
b/examples
b/examples/dummy.rs
b/src
b/src/lib.rs
Cargo.toml
  1. $ cargo build -p a --example dummy
$ ls -al target/debug/examples
drwxr-xr-x. slomo slomo 116 B  Fri Nov  1 12:49:25 2024  .
drwxr-xr-x. slomo slomo 102 B  Fri Nov  1 12:49:25 2024  ..
.rwxr-xr-x. slomo slomo 3.7 MB Fri Nov  1 12:49:25 2024  dummy
.rwxr-xr-x. slomo slomo 3.7 MB Fri Nov  1 12:49:25 2024  dummy-d4e2cacc3295a333
.rw-r--r--. slomo slomo 227 B  Fri Nov  1 12:49:25 2024  dummy-d4e2cacc3295a333.d
.rw-r--r--. slomo slomo 167 B  Fri Nov  1 12:49:25 2024  dummy.d
  1. $ cargo build -p b --example dummy
$ ls -al target/debug/examples
drwxr-xr-x. slomo slomo 208 B  Fri Nov  1 12:49:37 2024  .
drwxr-xr-x. slomo slomo 102 B  Fri Nov  1 12:49:25 2024  ..
.rwxr-xr-x. slomo slomo 3.7 MB Fri Nov  1 12:49:37 2024  dummy
.rwxr-xr-x. slomo slomo 3.7 MB Fri Nov  1 12:49:25 2024  dummy-d4e2cacc3295a333
.rw-r--r--. slomo slomo 227 B  Fri Nov  1 12:49:25 2024  dummy-d4e2cacc3295a333.d
.rwxr-xr-x. slomo slomo 3.7 MB Fri Nov  1 12:49:37 2024  dummy-dc40cbdf25da73d7
.rw-r--r--. slomo slomo 227 B  Fri Nov  1 12:49:37 2024  dummy-dc40cbdf25da73d7.d
.rw-r--r--. slomo slomo 167 B  Fri Nov  1 12:49:37 2024  dummy.d

Note that target/debug/examples/dummy and target/debug/examples/dummy.d is used by both crates. That's obviously not optimal because only one example can exist at a time like this, but it also means that parallel builds on Windows fail randomly with a linker error if both crates are built in parallel and two link.exe are trying to access target/debug/example/dummy.exe at the same time.

Possible Solution(s)

Store examples in subdirectories based on the crates they're from

Notes

No response

Version

cargo 1.82.0 (8f40fc5 2024-08-21)
release: 1.82.0
commit-hash: 8f40fc5
commit-date: 2024-08-21
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Fedora 41.0.0 [64-bit]

@sdroege sdroege added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Nov 1, 2024
@sdroege
Copy link
Contributor Author

sdroege commented Nov 1, 2024

FWIW, I ran into this when trying to work around #13447 by simply placing a examples/dummy.rs into all crates that don't have any example to force the publishing of its Cargo.lock.

@ehuss
Copy link
Contributor

ehuss commented Nov 1, 2024

Thanks for the report! This is a known issue, and if you build both examples at the same time you should get a warning of warning: output filename collision. along with an explanation. Since this is tracked in #6313, closing as a duplicate of that.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2024
@sdroege
Copy link
Contributor Author

sdroege commented Nov 1, 2024

Thanks, sorry for missing that. Searched for the wrong keywords apparently :)

@epage
Copy link
Contributor

epage commented Nov 1, 2024

imo the focus should probably be on #13447 since that is the root issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

3 participants