From 243d3d9cde350144b5fa24f98200a78c0070d2b4 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Tue, 14 Jun 2022 18:12:40 -0500 Subject: [PATCH] Added additional toolchains maintained by cross-rs. These toolchains are not automatically tested by CI, and must be built manually by the user. However, they are confirmed to build at least once, and are likely to work as-is. Also adds better error handling when it cannot find a suitable Dockerfile for a given target. --- .gitmodules | 3 +++ CHANGELOG.md | 1 + README.md | 2 ++ docker/cross-toolchains | 1 + xtask/src/build_docker_image.rs | 37 +++++++++++++++++++++++++++------ 5 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 .gitmodules create mode 160000 docker/cross-toolchains diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..ca49da821 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "docker/cross-toolchains"] + path = docker/cross-toolchains + url = https://github.com/cross-rs/cross-toolchains.git diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a5870728..a61dbdf1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added +- #795 - added images for additional toolchains maintained by cross-rs. - #792 - added `CROSS_CONTAINER_IN_CONTAINER` environment variable to replace `CROSS_DOCKER_IN_DOCKER`. - #782 - added `build-std` config option, which builds the rust standard library from source if enabled. - #775 - forward Cargo exit code to host diff --git a/README.md b/README.md index 48b73c5b7..33f73f242 100644 --- a/README.md +++ b/README.md @@ -348,6 +348,8 @@ terminate. +Additional Dockerfiles for other targets can be found in [cross-toolchains](https://github.com/cross-rs/cross-toolchains). + ## Debugging ### QEMU_STRACE (v0.1.9+) diff --git a/docker/cross-toolchains b/docker/cross-toolchains new file mode 160000 index 000000000..a49c8176c --- /dev/null +++ b/docker/cross-toolchains @@ -0,0 +1 @@ +Subproject commit a49c8176cbcc0fa70e4690be9510722e7a11d0f2 diff --git a/xtask/src/build_docker_image.rs b/xtask/src/build_docker_image.rs index 58645a852..4a0d37770 100644 --- a/xtask/src/build_docker_image.rs +++ b/xtask/src/build_docker_image.rs @@ -48,6 +48,23 @@ pub struct BuildDockerImage { targets: Vec, } +fn locate_dockerfile( + target: String, + docker_root: &Path, + cross_toolchain_root: &Path, +) -> cross::Result<(String, String)> { + let dockerfile_name = format!("Dockerfile.{target}"); + let dockerfile_root = if cross_toolchain_root.join(&dockerfile_name).exists() { + &cross_toolchain_root + } else if docker_root.join(&dockerfile_name).exists() { + &docker_root + } else { + eyre::bail!("unable to find dockerfile for target \"{target}\""); + }; + let dockerfile = dockerfile_root.join(dockerfile_name).display().to_string(); + Ok((target, dockerfile)) +} + pub fn build_docker_image( BuildDockerImage { ref_type, @@ -102,14 +119,21 @@ pub fn build_docker_image( } } let gha = std::env::var("GITHUB_ACTIONS").is_ok(); + let docker_root = metadata.workspace_root.join("docker"); + let cross_toolchains_root = docker_root.join("cross-toolchains").join("docker"); + let targets = targets + .into_iter() + .map(|t| locate_dockerfile(t, &docker_root, &cross_toolchains_root)) + .collect::>>()?; + let mut results = vec![]; - for target in &targets { + for (target, dockerfile) in &targets { if gha && targets.len() > 1 { println!("::group::Build {target}"); } let mut docker_build = Command::new(engine); docker_build.args(&["buildx", "build"]); - docker_build.current_dir(metadata.workspace_root.join("docker")); + docker_build.current_dir(&docker_root); if push { docker_build.arg("--push"); @@ -117,8 +141,6 @@ pub fn build_docker_image( docker_build.arg("--load"); } - let dockerfile = format!("Dockerfile.{target}"); - let (target, sub) = if let Some((t, sub)) = target.split_once('.') { (t.to_owned(), format!("-{sub}")) } else { @@ -192,7 +214,7 @@ pub fn build_docker_image( docker_build.args(&["--label", label]); } - docker_build.args(&["-f", &dockerfile]); + docker_build.args(&["-f", dockerfile]); if gha || progress == "plain" { docker_build.args(&["--progress", "plain"]); @@ -207,7 +229,10 @@ pub fn build_docker_image( if gha && targets.len() > 1 { if let Err(e) = &result { // TODO: Determine what instruction errorred, and place warning on that line with appropriate warning - println!("::error file=docker/{dockerfile},title=Build failed::{}", e) + println!( + "::error file=docker/{},title=Build failed::{}", + dockerfile, e + ) } } results.push(