Skip to content

Commit e24cbe2

Browse files
committed
Misc tweaks
1 parent c338bd5 commit e24cbe2

File tree

13 files changed

+72
-11
lines changed

13 files changed

+72
-11
lines changed

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@
346346
# Whether to deny warnings in crates
347347
#deny-warnings = true
348348

349+
# Print backtrace on internal compiler errors during bootstrap
350+
#backtrace-on-ice = false
351+
349352
# =============================================================================
350353
# Options for specific targets
351354
#

src/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/bin/rustc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ fn main() {
107107
env::join_paths(&dylib_path).unwrap());
108108
let mut maybe_crate = None;
109109

110+
// Print backtrace in case of ICE
111+
if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() {
112+
cmd.env("RUST_BACKTRACE", "1");
113+
}
114+
115+
cmd.env("RUSTC_BREAK_ON_ICE", "1");
116+
110117
if let Some(target) = target {
111118
// The stage0 compiler has a special sysroot distinct from what we
112119
// actually downloaded, so we just always pass the `--sysroot` option.

src/bootstrap/builder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,10 @@ impl<'a> Builder<'a> {
706706
cargo.env("RUSTC_PRINT_STEP_TIMINGS", "1");
707707
}
708708

709+
if self.config.backtrace_on_ice {
710+
cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
711+
}
712+
709713
cargo.env("RUSTC_VERBOSE", format!("{}", self.verbosity));
710714

711715
// in std, we want to avoid denying warnings for stage 0 as that makes cfg's painful.

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub struct Config {
7272
pub dry_run: bool,
7373

7474
pub deny_warnings: bool,
75+
pub backtrace_on_ice: bool,
7576

7677
// llvm codegen options
7778
pub llvm_enabled: bool,
@@ -306,6 +307,7 @@ struct Rust {
306307
wasm_syscall: Option<bool>,
307308
lld: Option<bool>,
308309
deny_warnings: Option<bool>,
310+
backtrace_on_ice: Option<bool>,
309311
}
310312

311313
/// TOML representation of how each build target is configured.
@@ -531,6 +533,7 @@ impl Config {
531533
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
532534
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
533535
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
536+
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
534537

535538
if let Some(ref backends) = rust.codegen_backends {
536539
config.rust_codegen_backends = backends.iter()

src/bootstrap/job.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ struct JOBOBJECT_BASIC_LIMIT_INFORMATION {
122122
}
123123

124124
pub unsafe fn setup(build: &mut Build) {
125-
// Tell Windows to not show any UI on errors (such as not finding a required dll
126-
// during startup or terminating abnormally). This is important for running tests,
127-
// since some of them use abnormal termination by design.
128-
// This mode is inherited by all child processes.
129-
let mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
130-
SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
125+
// Enable the Windows Error Reporting dialog which msys disables,
126+
// so we can JIT debug rustc
127+
let mode = SetErrorMode(0);
128+
SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
131129

132130
// Create a new job object for us to use
133131
let job = CreateJobObjectW(0 as *mut _, 0 as *const _);

src/librustc/util/common.rs

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ fn panic_hook(info: &panic::PanicInfo) {
5858
if backtrace {
5959
TyCtxt::try_print_query_stack();
6060
}
61+
62+
#[cfg(windows)]
63+
unsafe {
64+
if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
65+
extern "system" {
66+
fn DebugBreak();
67+
}
68+
// Trigger a debugger if we crashed during bootstrap
69+
DebugBreak();
70+
}
71+
}
6172
}
6273
}
6374

src/librustc_plugin/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
html_root_url = "https://doc.rust-lang.org/nightly/")]
6666

6767
#![feature(rustc_diagnostic_macros)]
68-
#![feature(staged_api)]
6968

7069
#[macro_use] extern crate syntax;
7170

src/librustc_plugin/registry.rs

-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ impl<'a> Registry<'a> {
128128
/// This can be used in place of `register_syntax_extension` to register legacy custom derives
129129
/// (i.e. attribute syntax extensions whose name begins with `derive_`). Legacy custom
130130
/// derives defined by this function do not trigger deprecation warnings when used.
131-
#[unstable(feature = "rustc_private", issue = "27812")]
132-
#[rustc_deprecated(since = "1.15.0", reason = "replaced by macros 1.1 (RFC 1861)")]
133131
pub fn register_custom_derive(&mut self, name: ast::Name, extension: SyntaxExtension) {
134132
assert!(name.as_str().starts_with("derive_"));
135133
self.whitelisted_custom_derives.push(name);

src/tools/compiletest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ rustfix = "0.2"
1919
libc = "0.2"
2020

2121
[target.'cfg(windows)'.dependencies]
22+
lazy_static = "1.0"
2223
miow = "0.3"
2324
winapi = { version = "0.3", features = ["winerror"] }

src/tools/compiletest/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ extern crate libc;
2323
extern crate log;
2424
extern crate regex;
2525
#[macro_use]
26+
#[cfg(windows)]
27+
extern crate lazy_static;
28+
#[macro_use]
2629
extern crate serde_derive;
2730
extern crate serde_json;
2831
extern crate test;

src/tools/compiletest/src/runtest.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ use std::str;
3838

3939
use extract_gdb_version;
4040

41+
#[cfg(windows)]
42+
fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
43+
use std::sync::Mutex;
44+
const SEM_NOGPFAULTERRORBOX: u32 = 0x0002;
45+
extern "system" {
46+
fn SetErrorMode(mode: u32) -> u32;
47+
}
48+
49+
lazy_static! {
50+
static ref LOCK: Mutex<()> = {
51+
Mutex::new(())
52+
};
53+
}
54+
// Error mode is a global variable, so lock it so only one thread will change it
55+
let _lock = LOCK.lock().unwrap();
56+
57+
// Tell Windows to not show any UI on errors (such as terminating abnormally).
58+
// This is important for running tests, since some of them use abnormal
59+
// termination by design. This mode is inherited by all child processes.
60+
unsafe {
61+
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
62+
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX);
63+
let r = f();
64+
SetErrorMode(old_mode);
65+
r
66+
}
67+
}
68+
69+
#[cfg(not(windows))]
70+
fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
71+
f()
72+
}
73+
4174
/// The name of the environment variable that holds dynamic library locations.
4275
pub fn dylib_env_var() -> &'static str {
4376
if cfg!(windows) {
@@ -1578,8 +1611,7 @@ impl<'test> TestCx<'test> {
15781611
let newpath = env::join_paths(&path).unwrap();
15791612
command.env(dylib_env_var(), newpath);
15801613

1581-
let mut child = command
1582-
.spawn()
1614+
let mut child = disable_error_reporting(|| command.spawn())
15831615
.expect(&format!("failed to exec `{:?}`", &command));
15841616
if let Some(input) = input {
15851617
child

src/tools/tidy/src/deps.rs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static WHITELIST: &'static [Crate] = &[
7373
Crate("flate2"),
7474
Crate("fuchsia-zircon"),
7575
Crate("fuchsia-zircon-sys"),
76+
Crate("getopts"),
7677
Crate("humantime"),
7778
Crate("jobserver"),
7879
Crate("kernel32-sys"),

0 commit comments

Comments
 (0)