Skip to content

Commit

Permalink
Added additional toolchains maintained by cross-rs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Alexhuszagh committed Jun 14, 2022
1 parent f333a1b commit 243d3d9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "docker/cross-toolchains"]
path = docker/cross-toolchains
url = https://github.com/cross-rs/cross-toolchains.git
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ terminate.
<!--[6] libc = musl, gcc = emcc. The Docker images for these targets are currently not built automatically
due to a [compiler bug](https://github.com/rust-lang/rust/issues/85821), you will have to build them yourself for now.-->

Additional Dockerfiles for other targets can be found in [cross-toolchains](https://github.com/cross-rs/cross-toolchains).

## Debugging

### QEMU_STRACE (v0.1.9+)
Expand Down
1 change: 1 addition & 0 deletions docker/cross-toolchains
Submodule cross-toolchains added at a49c81
37 changes: 31 additions & 6 deletions xtask/src/build_docker_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ pub struct BuildDockerImage {
targets: Vec<String>,
}

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,
Expand Down Expand Up @@ -102,23 +119,28 @@ 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::<cross::Result<Vec<_>>>()?;

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");
} else {
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 {
Expand Down Expand Up @@ -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"]);
Expand All @@ -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(
Expand Down

0 comments on commit 243d3d9

Please sign in to comment.