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

Add additional toolchains maintained by cross-rs. #795

Merged
merged 1 commit into from
Jun 15, 2022
Merged
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
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