`cargo run`, on a freshly-created cargo project, does not work until after doing a plain `cargo build`.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Problem
I'm attempting to replicate the tutorial here: https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html
But running gives an error.
Steps
cargo new guessing_game gives Created binary (application) 'guessing_game' package
Then
cd guessing_game, followed by cargo run gives:
Compiling guessing_game v0.1.0 (/home/bismurphy/Projects/Rust/guessing_game)
Finished dev [unoptimized + debuginfo] target(s) in 2.49s
Running `target/debug/guessing_game`
error: could not execute process `target/debug/guessing_game` (never executed)
Caused by:
Invalid argument (os error 22)
This is odd - it successfully compiles, but won't run. So then I try again, with an explicit build step added:
cd .., rm -r guessing_game, cargo new guessing_game, cd guessing_game, cargo build, cargo run
And at that point, it runs successfully. If I do a dedicated compile step prior to running, then all is well. Additionally, if I create the project, then do cargo run twice, the first one gives me the error, but the second one works fine. I wonder if there might be some sort of race condition going on, where the compiling step is done, but the file isn't fully written, and the system needs just a tiny bit more time to finish getting the file written to disk before being ready to actually run it.
Possible Solution(s)
No response
Notes
Of course running twice is a perfectly fine workaround, but for the sake of usability, it would be very nice if the cargo run command worked as expected on the first try.
Version
cargo 1.65.0 (4bc8f24d3 2022-10-20)
release: 1.65.0
commit-hash: 4bc8f24d3e899462e43621aab981f6383a370365
commit-date: 2022-10-20
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
os: Linux Mint 21 (vanessa) [64-bit]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the sequence with cargo new, cargo run, and a second cargo run on the reported Linux environment, then compare it with an explicit cargo build. Start by tracing the cargo run entry point and its build-to-execution transition. Done means a freshly created project runs successfully on the first cargo run, with a regression test covering that path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100