From 05801f3f06ad90cd3e4143d3c9d20c36faec2c7f Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 18 Aug 2021 18:30:35 +0800 Subject: [PATCH] xtask: add simple check for toolchain This adds a simple check for the proper Rust toolchain. A more advance test will advise on toolchain installation. Signed-off-by: Sean Cross --- xtask/src/main.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index bfdd55570..1fb3fd3b0 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -224,7 +224,12 @@ Please refer to tools/README_UPDATE.md for instructions on how to set up `usb_up ) } -fn update_usb(do_kernel: bool, do_loader: bool, nuke_soc: bool, stage_soc: bool) -> Result<(), DynError> { +fn update_usb( + do_kernel: bool, + do_loader: bool, + nuke_soc: bool, + stage_soc: bool, +) -> Result<(), DynError> { use std::io::{BufRead, BufReader, Error, ErrorKind}; use std::process::Stdio; @@ -534,6 +539,37 @@ fn build_kernel(debug: bool) -> Result { Ok(path) } +static DONE_COMPILER_CHECK: std::sync::atomic::AtomicBool = + std::sync::atomic::AtomicBool::new(false); +fn ensure_compiler(target: &Option<&str>) -> Result<(), String> { + use std::process::Stdio; + if DONE_COMPILER_CHECK.load(std::sync::atomic::Ordering::SeqCst) { + return Ok(()) + } + let target = target.unwrap_or(PROGRAM_TARGET).to_owned(); + let have_toolchain = Command::new("rustc") + .stderr(Stdio::null()) + .stdout(Stdio::null()) + .args(&[ + "--target", + &target, + "--print", + "sysroot", + ]) + .spawn() + .unwrap() + .wait() + .unwrap() + .success(); + + DONE_COMPILER_CHECK.store(have_toolchain, std::sync::atomic::Ordering::SeqCst); + if have_toolchain { + Ok(()) + } else { + Err(format!("Toolchain for {} not found", target)) + } +} + fn build( packages: &[&str], debug: bool, @@ -541,6 +577,7 @@ fn build( directory: Option, extra_args: Option<&[&str]>, ) -> Result { + ensure_compiler(&target)?; let stream = if debug { "debug" } else { "release" }; let mut args = vec!["build"]; print!("Building");