You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Create a workspace of the following shape (actual file content doesn't really matter)
$ 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
$ 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
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.
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.
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
$ cargo build -p a --example dummy
$ cargo build -p b --example dummy
Note that
target/debug/examples/dummy
andtarget/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 twolink.exe
are trying to accesstarget/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]
The text was updated successfully, but these errors were encountered: