Skip to content

Commit 1c71c1f

Browse files
authored
Unrolled build for rust-lang#130899
Rollup merge of rust-lang#130899 - bjorn3:wasi_bootstrap_fixes, r=davidtwco Couple of changes to make it easier to compile rustc for wasm This is a subset of the patches I have on my rust fork to compile rustc for wasm32-wasip1.
2 parents 7caad69 + bf1f5c9 commit 1c71c1f

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

compiler/rustc_driver_impl/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ use std::path::PathBuf;
2929
use std::process::{self, Command, Stdio};
3030
use std::sync::atomic::{AtomicBool, Ordering};
3131
use std::sync::{Arc, OnceLock};
32-
use std::time::{Duration, Instant, SystemTime};
32+
use std::time::{Instant, SystemTime};
3333
use std::{env, str};
3434

3535
use rustc_ast as ast;
3636
use rustc_codegen_ssa::traits::CodegenBackend;
3737
use rustc_codegen_ssa::{CodegenErrors, CodegenResults};
38-
use rustc_const_eval::CTRL_C_RECEIVED;
3938
use rustc_data_structures::profiling::{
4039
TimePassesFormat, get_resident_set_size, print_time_passes_entry,
4140
};
@@ -1577,8 +1576,8 @@ pub fn install_ctrlc_handler() {
15771576
// time to check CTRL_C_RECEIVED and run its own shutdown logic, but after a short amount
15781577
// of time exit the process. This sleep+exit ensures that even if nobody is checking
15791578
// CTRL_C_RECEIVED, the compiler exits reasonably promptly.
1580-
CTRL_C_RECEIVED.store(true, Ordering::Relaxed);
1581-
std::thread::sleep(Duration::from_millis(100));
1579+
rustc_const_eval::CTRL_C_RECEIVED.store(true, Ordering::Relaxed);
1580+
std::thread::sleep(std::time::Duration::from_millis(100));
15821581
std::process::exit(1);
15831582
})
15841583
.expect("Unable to install ctrlc handler");

compiler/rustc_fs_util/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<Li
7676
}
7777
}
7878

79-
#[cfg(unix)]
79+
#[cfg(any(unix, all(target_os = "wasi", target_env = "p1")))]
8080
pub fn path_to_c_string(p: &Path) -> CString {
8181
use std::ffi::OsStr;
82+
#[cfg(unix)]
8283
use std::os::unix::ffi::OsStrExt;
84+
#[cfg(all(target_os = "wasi", target_env = "p1"))]
85+
use std::os::wasi::ffi::OsStrExt;
86+
8387
let p: &OsStr = p.as_ref();
8488
CString::new(p.as_bytes()).unwrap()
8589
}

src/bootstrap/src/core/builder.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1687,10 +1687,24 @@ impl<'a> Builder<'a> {
16871687
match mode {
16881688
Mode::Std | Mode::ToolBootstrap | Mode::ToolStd => {}
16891689
Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {
1690-
// Build proc macros both for the host and the target
1690+
// Build proc macros both for the host and the target unless proc-macros are not
1691+
// supported by the target.
16911692
if target != compiler.host && cmd_kind != Kind::Check {
1692-
cargo.arg("-Zdual-proc-macros");
1693-
rustflags.arg("-Zdual-proc-macros");
1693+
let error = command(self.rustc(compiler))
1694+
.arg("--target")
1695+
.arg(target.rustc_target_arg())
1696+
.arg("--print=file-names")
1697+
.arg("--crate-type=proc-macro")
1698+
.arg("-")
1699+
.run_capture(self)
1700+
.stderr();
1701+
let not_supported = error
1702+
.lines()
1703+
.any(|line| line.contains("unsupported crate type `proc-macro`"));
1704+
if !not_supported {
1705+
cargo.arg("-Zdual-proc-macros");
1706+
rustflags.arg("-Zdual-proc-macros");
1707+
}
16941708
}
16951709
}
16961710
}

src/bootstrap/src/utils/shared_helpers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub fn exe(name: &str, target: &str) -> String {
4949
format!("{name}.exe")
5050
} else if target.contains("uefi") {
5151
format!("{name}.efi")
52+
} else if target.contains("wasm") {
53+
format!("{name}.wasm")
5254
} else {
5355
name.to_string()
5456
}

0 commit comments

Comments
 (0)