From 90e32e2ac67a3bfa5388c49def90712385f504cb Mon Sep 17 00:00:00 2001 From: Niels Sascha Reedijk Date: Thu, 5 Jul 2018 07:12:24 +0200 Subject: [PATCH] Haiku: work around the lack of setrlimit By default, Haiku has the desired 16 MB stack, therefore in general we do not have to spawn a new thread. The code has been written in such a way that any changes in Haiku or in Rust will be adapted to. --- src/librustc_driver/lib.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 84f7b35d21f..1078dadce25 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1493,7 +1493,7 @@ pub fn in_rustc_thread(f: F) -> Result> // Temporarily have stack size set to 16MB to deal with nom-using crates failing const STACK_SIZE: usize = 16 * 1024 * 1024; // 16MB - #[cfg(unix)] + #[cfg(all(unix,not(target_os = "haiku")))] let spawn_thread = unsafe { // Fetch the current resource limits let mut rlim = libc::rlimit { @@ -1525,6 +1525,26 @@ pub fn in_rustc_thread(f: F) -> Result> #[cfg(windows)] let spawn_thread = false; + #[cfg(target_os = "haiku")] + let spawn_thread = unsafe { + // Haiku does not have setrlimit implemented for the stack size. + // By default it does have the 16 MB stack limit, but we check this in + // case the minimum STACK_SIZE changes or Haiku's defaults change. + let mut rlim = libc::rlimit { + rlim_cur: 0, + rlim_max: 0, + }; + if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { + let err = io::Error::last_os_error(); + error!("in_rustc_thread: error calling getrlimit: {}", err); + true + } else if rlim.rlim_cur >= STACK_SIZE { + false + } else { + true + } + }; + #[cfg(not(any(windows,unix)))] let spawn_thread = true;