Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalidate cross image if rust version has changed (but nothing else) #917

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docker/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod file;
mod id;
mod interpreter;
pub mod rustc;
mod rustup;
pub mod rustup;
pub mod shell;
pub mod temp;

Expand Down
3 changes: 2 additions & 1 deletion src/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
23 changes: 23 additions & 0 deletions xtask/src/build_docker_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,29 @@ pub fn build_docker_image(
if verbose > 1 {
docker_build.args(&["--build-arg", "VERBOSE=1"]);
}
// FIXME: Move to matrix?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to move to util at least. It should be more general functionality, so we can get the latest stable.

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);
Expand Down