From f21f92a1ac8338d95f127d81830bfacd784d36d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Wed, 6 Jul 2022 19:21:02 +0200 Subject: [PATCH] use current available rust stable as cache invalidator --- docker/Dockerfile.cross | 8 +++++--- src/lib.rs | 2 +- src/rustup.rs | 3 ++- xtask/src/build_docker_image.rs | 23 +++++++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.cross b/docker/Dockerfile.cross index bb0fd55d7..daa1e0664 100644 --- a/docker/Dockerfile.cross +++ b/docker/Dockerfile.cross @@ -1,14 +1,13 @@ FROM ubuntu:20.04 as rust ARG DEBIAN_FRONTEND=noninteractive +ARG RUST_STABLE COPY docker/lib.sh docker/cross.sh / COPY ./ /project -RUN /cross.sh /project +RUN /cross.sh /project $RUST_STABLE # we build our images in 2 steps, to ensure we have a compact # image, since we want to add our current subdirectory FROM ubuntu:20.04 -COPY --from=rust /root/.cargo /root/.cargo -COPY --from=rust /root/.rustup /root/.rustup # need some basic devtools, and requirements for docker RUN apt-get update && apt-get install --assume-yes --no-install-recommends \ @@ -18,5 +17,8 @@ RUN apt-get update && apt-get install --assume-yes --no-install-recommends \ RUN curl -fsSL https://get.docker.com | sh +COPY --from=rust /root/.cargo /root/.cargo +COPY --from=rust /root/.rustup /root/.rustup + ENV CROSS_CONTAINER_IN_CONTAINER=1 \ PATH=/root/.cargo/bin:$PATH diff --git a/src/lib.rs b/src/lib.rs index 1f5c94692..ca03ca008 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ mod file; mod id; mod interpreter; pub mod rustc; -mod rustup; +pub mod rustup; pub mod shell; pub mod temp; diff --git a/src/rustup.rs b/src/rustup.rs index f04fd07e2..430341ed5 100644 --- a/src/rustup.rs +++ b/src/rustup.rs @@ -27,7 +27,7 @@ impl AvailableTargets { } } -fn rustup_command(msg_info: &mut MessageInfo, no_flags: bool) -> Command { +pub fn rustup_command(msg_info: &mut MessageInfo, no_flags: bool) -> Command { let mut cmd = Command::new("rustup"); if no_flags { return cmd; @@ -127,6 +127,7 @@ pub fn install_component( .wrap_err_with(|| format!("couldn't install the `{component}` component")) } +#[derive(Debug)] pub enum Component<'a> { Installed(&'a str), Available(&'a str), diff --git a/xtask/src/build_docker_image.rs b/xtask/src/build_docker_image.rs index 81c52ab87..aa1212ff0 100644 --- a/xtask/src/build_docker_image.rs +++ b/xtask/src/build_docker_image.rs @@ -238,6 +238,29 @@ pub fn build_docker_image( if verbose > 1 { docker_build.args(&["--build-arg", "VERBOSE=1"]); } + // FIXME: Move to matrix? + if target.triplet == "cross" { + let rustup = cross::rustup::rustup_command(msg_info, false) + .arg("check") + .run_and_get_stdout(msg_info)?; + let version = rustup + .lines() + .find(|line| line.starts_with("stable")) + .and_then(|stable| { + // Check is formatted as + // `Update available : 1.61.0 (fe5b13d68 2022-05-18) -> 1.62.0 (a8314ef7d 2022-06-27)` + // or + // `Up to date : 1.62.0 (a8314ef7d 2022-06-27)` + stable + .split_once(" -> ") + .or_else(|| stable.split_once(" : ")) + }) + .and_then(|(_, v)| v.split_once(' ')) + .map(|(v, _)| v) + .unwrap_or("stable"); + dbg!(&version); + docker_build.args(&["--build-arg", &format!("RUST_STABLE={version}")]); + } if target.needs_workspace_root_context() { docker_build.arg(&root);