From 341bf46e5345e5287ecc4ce6bd98b66d554a92f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Thu, 23 Mar 2017 22:57:29 +0100 Subject: [PATCH 1/2] Add an option to run rustbuild on low priority on Windows --- src/bootstrap/config.rs | 3 +++ src/bootstrap/config.toml.example | 3 +++ src/bootstrap/job.rs | 9 ++++++++- src/bootstrap/lib.rs | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b1d1d79b9eaa3..3b0137488c06b 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -95,6 +95,7 @@ pub struct Config { pub backtrace: bool, // support for RUST_BACKTRACE // misc + pub low_priority: bool, pub channel: String, pub quiet_tests: bool, // Fallback musl-root for all targets @@ -147,6 +148,7 @@ struct Build { target: Vec, cargo: Option, rustc: Option, + low_priority: Option, compiler_docs: Option, docs: Option, submodules: Option, @@ -304,6 +306,7 @@ impl Config { config.nodejs = build.nodejs.map(PathBuf::from); config.gdb = build.gdb.map(PathBuf::from); config.python = build.python.map(PathBuf::from); + set(&mut config.low_priority, build.low_priority); set(&mut config.compiler_docs, build.compiler_docs); set(&mut config.docs, build.docs); set(&mut config.submodules, build.submodules); diff --git a/src/bootstrap/config.toml.example b/src/bootstrap/config.toml.example index 6b2cc6eb6474c..e72cd13f17d05 100644 --- a/src/bootstrap/config.toml.example +++ b/src/bootstrap/config.toml.example @@ -152,6 +152,9 @@ # known-good version of OpenSSL, compile it, and link it to Cargo. #openssl-static = false +# Run the build with low priority on Windows +#low_priority = false + # ============================================================================= # General install configuration options # ============================================================================= diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index c3859275e6fb4..72a5d1338b8d0 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -42,6 +42,7 @@ use std::env; use std::io; use std::mem; +use Build; type HANDLE = *mut u8; type BOOL = i32; @@ -60,8 +61,10 @@ const DUPLICATE_SAME_ACCESS: DWORD = 0x2; const PROCESS_DUP_HANDLE: DWORD = 0x40; const JobObjectExtendedLimitInformation: JOBOBJECTINFOCLASS = 9; const JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE: DWORD = 0x2000; +const JOB_OBJECT_LIMIT_PRIORITY_CLASS: DWORD = 0x00000020; const SEM_FAILCRITICALERRORS: UINT = 0x0001; const SEM_NOGPFAULTERRORBOX: UINT = 0x0002; +const BELOW_NORMAL_PRIORITY_CLASS: DWORD = 0x00004000; extern "system" { fn CreateJobObjectW(lpJobAttributes: *mut u8, lpName: *const u8) -> HANDLE; @@ -118,7 +121,7 @@ struct JOBOBJECT_BASIC_LIMIT_INFORMATION { SchedulingClass: DWORD, } -pub unsafe fn setup() { +pub unsafe fn setup(build: &mut Build) { // Tell Windows to not show any UI on errors (such as not finding a required dll // during startup or terminating abnormally). This is important for running tests, // since some of them use abnormal termination by design. @@ -136,6 +139,10 @@ pub unsafe fn setup() { // children will reside in the job by default. let mut info = mem::zeroed::(); info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + if build.config.low_priority { + info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS; + info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS; + } let r = SetInformationJobObject(job, JobObjectExtendedLimitInformation, &mut info as *mut _ as LPVOID, diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 26f3c06306197..8e09266956a27 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -110,7 +110,7 @@ mod job; #[cfg(not(windows))] mod job { - pub unsafe fn setup() {} + pub unsafe fn setup(build: &mut Build) {} } pub use config::Config; @@ -257,7 +257,7 @@ impl Build { /// Executes the entire build, as configured by the flags and configuration. pub fn build(&mut self) { unsafe { - job::setup(); + job::setup(self); } if let Subcommand::Clean = self.flags.cmd { From 34de970d201f71f3197ea8a5166244b24a877deb Mon Sep 17 00:00:00 2001 From: Zoxc Date: Fri, 24 Mar 2017 03:51:36 +0100 Subject: [PATCH 2/2] Fix non-Windows builds --- src/bootstrap/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 8e09266956a27..675f8c8eefe81 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -110,7 +110,7 @@ mod job; #[cfg(not(windows))] mod job { - pub unsafe fn setup(build: &mut Build) {} + pub unsafe fn setup(_build: &mut ::Build) {} } pub use config::Config;