|
24 | 24 | #![feature(quote)]
|
25 | 25 | #![feature(rustc_diagnostic_macros)]
|
26 | 26 | #![feature(set_stdio)]
|
| 27 | +#![feature(rustc_stack_internals)] |
27 | 28 |
|
28 | 29 | extern crate arena;
|
29 | 30 | extern crate getopts;
|
@@ -1461,16 +1462,50 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
|
1461 | 1462 | // Temporarily have stack size set to 16MB to deal with nom-using crates failing
|
1462 | 1463 | const STACK_SIZE: usize = 16 * 1024 * 1024; // 16MB
|
1463 | 1464 |
|
1464 |
| - let mut cfg = thread::Builder::new().name("rustc".to_string()); |
| 1465 | + #[cfg(unix)] |
| 1466 | + let spawn_thread = unsafe { |
| 1467 | + // Fetch the current resource limits |
| 1468 | + let mut rlim = libc::rlimit { |
| 1469 | + rlim_cur: 0, |
| 1470 | + rlim_max: 0, |
| 1471 | + }; |
| 1472 | + if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { |
| 1473 | + let err = io::Error::last_os_error(); |
| 1474 | + error!("in_rustc_thread: error calling getrlimit: {}", err); |
| 1475 | + true |
| 1476 | + } else if rlim.rlim_max < STACK_SIZE as libc::rlim_t { |
| 1477 | + true |
| 1478 | + } else { |
| 1479 | + rlim.rlim_cur = STACK_SIZE as libc::rlim_t; |
| 1480 | + if libc::setrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { |
| 1481 | + let err = io::Error::last_os_error(); |
| 1482 | + error!("in_rustc_thread: error calling setrlimit: {}", err); |
| 1483 | + true |
| 1484 | + } else { |
| 1485 | + std::thread::update_stack_guard(); |
| 1486 | + false |
| 1487 | + } |
| 1488 | + } |
| 1489 | + }; |
1465 | 1490 |
|
1466 |
| - // FIXME: Hacks on hacks. If the env is trying to override the stack size |
1467 |
| - // then *don't* set it explicitly. |
1468 |
| - if env::var_os("RUST_MIN_STACK").is_none() { |
1469 |
| - cfg = cfg.stack_size(STACK_SIZE); |
1470 |
| - } |
| 1491 | + #[cfg(not(unix))] |
| 1492 | + let spawn_thread = true; |
| 1493 | + |
| 1494 | + // The or condition is added from backward compatibility. |
| 1495 | + if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() { |
| 1496 | + let mut cfg = thread::Builder::new().name("rustc".to_string()); |
| 1497 | + |
| 1498 | + // FIXME: Hacks on hacks. If the env is trying to override the stack size |
| 1499 | + // then *don't* set it explicitly. |
| 1500 | + if env::var_os("RUST_MIN_STACK").is_none() { |
| 1501 | + cfg = cfg.stack_size(STACK_SIZE); |
| 1502 | + } |
1471 | 1503 |
|
1472 |
| - let thread = cfg.spawn(f); |
1473 |
| - thread.unwrap().join() |
| 1504 | + let thread = cfg.spawn(f); |
| 1505 | + thread.unwrap().join() |
| 1506 | + } else { |
| 1507 | + Ok(f()) |
| 1508 | + } |
1474 | 1509 | }
|
1475 | 1510 |
|
1476 | 1511 | /// Get a list of extra command-line flags provided by the user, as strings.
|
|
0 commit comments