Skip to content

Fix cargo run on Windows #95254

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 10, 2022
Merged

Fix cargo run on Windows #95254

merged 1 commit into from
Apr 10, 2022

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Mar 23, 2022

Fixes the following error:

error: failed to run custom build command for `bootstrap v0.0.0 (C:\Users\Walther\git\rust\src\bootstrap)`

Caused by:
  process didn't exit successfully: `C:\Users\Walther\git\rust\target\debug\build\bootstrap-7757a4777dec0f86\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-env-changed=RUSTC
  cargo:rustc-env=BUILD_TRIPLE=x86_64-pc-windows-msvc
  cargo:rerun-if-env-changed=PATH

  --- stderr
  thread 'main' panicked at 'assertion failed: rustc.is_absolute()', src\bootstrap\build.rs:22:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

The problem was that the dir.join check only works with rustc.exe, not rustc.

Thanks @Walther for the help testing the fix!

Helps with #94829.

@rust-highfive
Copy link
Contributor

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 23, 2022
@jyn514 jyn514 force-pushed the fix-windows-builds branch from c379355 to 37835dc Compare March 23, 2022 23:34
@ChrisDenton
Copy link
Member

ChrisDenton commented Mar 24, 2022

I don't know if rustc currently builds on any other platforms that have executable suffixes but maybe using std::env::consts::EXE_SUFFIX might be more future proof?

@jyn514 jyn514 force-pushed the fix-windows-builds branch from 37835dc to dcd7dbf Compare March 24, 2022 00:47
@rust-log-analyzer

This comment has been minimized.

Fixes the following error:
```
error: failed to run custom build command for `bootstrap v0.0.0 (C:\Users\Walther\git\rust\src\bootstrap)`

Caused by:
  process didn't exit successfully: `C:\Users\Walther\git\rust\target\debug\build\bootstrap-7757a4777dec0f86\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-env-changed=RUSTC
  cargo:rustc-env=BUILD_TRIPLE=x86_64-pc-windows-msvc
  cargo:rerun-if-env-changed=PATH

  --- stderr
  thread 'main' panicked at 'assertion failed: rustc.is_absolute()', src\bootstrap\build.rs:22:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
```

The problem was that the `dir.join` check only works with rustc.exe, not rustc.

Thanks Walther for the help testing the fix!
/// Given an executable called `name`, return the filename for the
/// executable for a particular target.
pub fn exe(name: &PathBuf) -> PathBuf {
if EXE_EXTENSION != "" && name.extension() != Some(EXE_EXTENSION.as_ref()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this method is basically name.with_extension(EXE_EXTENSION)? Unless I'm missing something, that's the intent of the code...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is this doesn't replace any existing extension. with_extension will change my.file to my.exe.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2022
@jyn514
Copy link
Member Author

jyn514 commented Apr 6, 2022

@rustbot ready

#95254 (comment)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 6, 2022
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2022
@jyn514
Copy link
Member Author

jyn514 commented Apr 9, 2022

Hi @Mark-Simulacrum , I saw you marked this as waiting on author, but I'm not sure why? with_extension has different behavior. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c39259bf36bf9e0ee79b136b3978b27c

That said it's very unlikely for this to actually come up, so I'm ok with using with_extension to get this landed.

@jyn514
Copy link
Member Author

jyn514 commented Apr 9, 2022

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 9, 2022
@Mark-Simulacrum
Copy link
Member

Seems okay, I think the author status was probably just a race with each other (I don't recall seeing your comment so probably I either by accident changed the wrong PR or something else went wrong).

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 9, 2022

📌 Commit 76d7bcc has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 9, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 9, 2022
…imulacrum

Fix `cargo run` on Windows

Fixes the following error:
```
error: failed to run custom build command for `bootstrap v0.0.0 (C:\Users\Walther\git\rust\src\bootstrap)`

Caused by:
  process didn't exit successfully: `C:\Users\Walther\git\rust\target\debug\build\bootstrap-7757a4777dec0f86\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-env-changed=RUSTC
  cargo:rustc-env=BUILD_TRIPLE=x86_64-pc-windows-msvc
  cargo:rerun-if-env-changed=PATH

  --- stderr
  thread 'main' panicked at 'assertion failed: rustc.is_absolute()', src\bootstrap\build.rs:22:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
```

The problem was that the `dir.join` check only works with `rustc.exe`, not `rustc`.

Thanks `@Walther` for the help testing the fix!

Helps with rust-lang#94829.
@bors
Copy link
Collaborator

bors commented Apr 10, 2022

⌛ Testing commit 76d7bcc with merge f7b4824...

@bors
Copy link
Collaborator

bors commented Apr 10, 2022

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing f7b4824 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 10, 2022
@bors bors merged commit f7b4824 into rust-lang:master Apr 10, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 10, 2022
@rust-timer
Copy link
Collaborator

This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@jyn514 jyn514 deleted the fix-windows-builds branch April 10, 2022 15:22
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants