Skip to content

Commit d90b016

Browse files
Merge #795
795: Add additional toolchains maintained by cross-rs. r=Emilgardis a=Alexhuszagh 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. Co-authored-by: Alex Huszagh <[email protected]>
2 parents 0f81c21 + 243d3d9 commit d90b016

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docker/cross-toolchains"]
2+
path = docker/cross-toolchains
3+
url = https://github.com/cross-rs/cross-toolchains.git

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77

88
### Added
99

10+
- #795 - added images for additional toolchains maintained by cross-rs.
1011
- #792 - added `CROSS_CONTAINER_IN_CONTAINER` environment variable to replace `CROSS_DOCKER_IN_DOCKER`.
1112
- #782 - added `build-std` config option, which builds the rust standard library from source if enabled.
1213
- #775 - forward Cargo exit code to host

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ terminate.
348348
<!--[6] libc = musl, gcc = emcc. The Docker images for these targets are currently not built automatically
349349
due to a [compiler bug](https://github.com/rust-lang/rust/issues/85821), you will have to build them yourself for now.-->
350350

351+
Additional Dockerfiles for other targets can be found in [cross-toolchains](https://github.com/cross-rs/cross-toolchains).
352+
351353
## Debugging
352354

353355
### QEMU_STRACE (v0.1.9+)

docker/cross-toolchains

Submodule cross-toolchains added at a49c817

xtask/src/build_docker_image.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ pub struct BuildDockerImage {
4848
targets: Vec<String>,
4949
}
5050

51+
fn locate_dockerfile(
52+
target: String,
53+
docker_root: &Path,
54+
cross_toolchain_root: &Path,
55+
) -> cross::Result<(String, String)> {
56+
let dockerfile_name = format!("Dockerfile.{target}");
57+
let dockerfile_root = if cross_toolchain_root.join(&dockerfile_name).exists() {
58+
&cross_toolchain_root
59+
} else if docker_root.join(&dockerfile_name).exists() {
60+
&docker_root
61+
} else {
62+
eyre::bail!("unable to find dockerfile for target \"{target}\"");
63+
};
64+
let dockerfile = dockerfile_root.join(dockerfile_name).display().to_string();
65+
Ok((target, dockerfile))
66+
}
67+
5168
pub fn build_docker_image(
5269
BuildDockerImage {
5370
ref_type,
@@ -102,23 +119,28 @@ pub fn build_docker_image(
102119
}
103120
}
104121
let gha = std::env::var("GITHUB_ACTIONS").is_ok();
122+
let docker_root = metadata.workspace_root.join("docker");
123+
let cross_toolchains_root = docker_root.join("cross-toolchains").join("docker");
124+
let targets = targets
125+
.into_iter()
126+
.map(|t| locate_dockerfile(t, &docker_root, &cross_toolchains_root))
127+
.collect::<cross::Result<Vec<_>>>()?;
128+
105129
let mut results = vec![];
106-
for target in &targets {
130+
for (target, dockerfile) in &targets {
107131
if gha && targets.len() > 1 {
108132
println!("::group::Build {target}");
109133
}
110134
let mut docker_build = Command::new(engine);
111135
docker_build.args(&["buildx", "build"]);
112-
docker_build.current_dir(metadata.workspace_root.join("docker"));
136+
docker_build.current_dir(&docker_root);
113137

114138
if push {
115139
docker_build.arg("--push");
116140
} else {
117141
docker_build.arg("--load");
118142
}
119143

120-
let dockerfile = format!("Dockerfile.{target}");
121-
122144
let (target, sub) = if let Some((t, sub)) = target.split_once('.') {
123145
(t.to_owned(), format!("-{sub}"))
124146
} else {
@@ -192,7 +214,7 @@ pub fn build_docker_image(
192214
docker_build.args(&["--label", label]);
193215
}
194216

195-
docker_build.args(&["-f", &dockerfile]);
217+
docker_build.args(&["-f", dockerfile]);
196218

197219
if gha || progress == "plain" {
198220
docker_build.args(&["--progress", "plain"]);
@@ -207,7 +229,10 @@ pub fn build_docker_image(
207229
if gha && targets.len() > 1 {
208230
if let Err(e) = &result {
209231
// TODO: Determine what instruction errorred, and place warning on that line with appropriate warning
210-
println!("::error file=docker/{dockerfile},title=Build failed::{}", e)
232+
println!(
233+
"::error file=docker/{},title=Build failed::{}",
234+
dockerfile, e
235+
)
211236
}
212237
}
213238
results.push(

0 commit comments

Comments
 (0)