Skip to content

Commit 76d7bcc

Browse files
committed
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!
1 parent 5f4e067 commit 76d7bcc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/bootstrap/build.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1+
use env::consts::{EXE_EXTENSION, EXE_SUFFIX};
12
use std::env;
3+
use std::ffi::OsString;
24
use std::path::PathBuf;
35

6+
/// Given an executable called `name`, return the filename for the
7+
/// executable for a particular target.
8+
pub fn exe(name: &PathBuf) -> PathBuf {
9+
if EXE_EXTENSION != "" && name.extension() != Some(EXE_EXTENSION.as_ref()) {
10+
let mut name: OsString = name.clone().into();
11+
name.push(EXE_SUFFIX);
12+
name.into()
13+
} else {
14+
name.clone()
15+
}
16+
}
17+
418
fn main() {
19+
let host = env::var("HOST").unwrap();
520
println!("cargo:rerun-if-changed=build.rs");
621
println!("cargo:rerun-if-env-changed=RUSTC");
7-
println!("cargo:rustc-env=BUILD_TRIPLE={}", env::var("HOST").unwrap());
22+
println!("cargo:rustc-env=BUILD_TRIPLE={}", host);
823

924
// This may not be a canonicalized path.
1025
let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
1126

1227
if rustc.is_relative() {
1328
println!("cargo:rerun-if-env-changed=PATH");
1429
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
15-
let absolute = dir.join(&rustc);
30+
let absolute = dir.join(&exe(&rustc));
1631
if absolute.exists() {
1732
rustc = absolute;
1833
break;

0 commit comments

Comments
 (0)