Skip to content

Commit 278cc19

Browse files
Merge #1057
1057: suggest that buildx needs to be available r=Alexhuszagh a=Emilgardis touches on #1055 ``` ❯ cross build --target x86_64-unknown-linux-gnu unknown flag: --label See 'docker buildx build --help'. Error: 0: could not run container 1: when building custom image 2: when pre-building 3: `docker buildx build --platform linux/amd64 --labela 'org.cross-rs.for-cross-target=x86_64-unknown-linux-gnu' --label 'org.cross-rs.runs-with=x86_64-unknown-linux-gnu' --label 'org.cross-rs.workspace_root=/Users/emil/workspace/cross' --tag localhost/cross-rs/cross-custom-cross:x86_64-unknown-linux-gnu-b0dac-pre-build --build-arg 'CROSS_CMD=hello world' --build-arg 'CROSS_DEB_ARCH=amd64' --file /Users/emil/workspace/cross/target/x86_64-unknown-linux-gnu/Dockerfile.x86_64-unknown-linux-gnu-custom --output 'type=docker' /Users/emil/workspace/cross` failed with exit status: 125 Warning: call to docker failed Suggestion: is `buildx` available for the container engine? Note: disable the `buildkit` dependency optionally with `CROSS_CONTAINER_ENGINE_NO_BUILDKIT=1` Note: CROSS_CMD=hello world ``` Co-authored-by: Emil Gardström <[email protected]>
2 parents 6ecf9e3 + 835f21f commit 278cc19

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/bin/commands/images.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub fn list_images(
276276
map.get_mut(&target).expect("map must have key").push(image);
277277
}
278278
}
279-
let mut keys: Vec<&str> = map.iter().map(|(k, _)| k.as_ref()).collect();
279+
let mut keys: Vec<&str> = map.keys().map(|k| k.as_ref()).collect();
280280
keys.sort_unstable();
281281

282282
let print_string =

src/docker/custom.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,32 @@ impl<'a> Dockerfile<'a> {
163163
docker_build.arg(paths.host_root());
164164
}
165165

166-
docker_build.run(msg_info, true)?;
166+
let mut res = docker_build.run(msg_info, true).with_warning(|| {
167+
format!(
168+
"call to {} failed",
169+
options
170+
.engine
171+
.path
172+
.file_name()
173+
.and_then(|s| s.to_str())
174+
.map_or_else(|| "container engine", |s| s)
175+
)
176+
});
177+
178+
// FIXME: Inspect the error message, while still inheriting stdout on verbose mode to
179+
// conditionally apply this suggestion and note. This could then inspect if a help string is emitted,
180+
// if the daemon is not running, etc.
181+
if docker::Engine::has_buildkit() {
182+
res = res
183+
.suggestion("is `buildx` available for the container engine?")
184+
.with_note(|| {
185+
format!(
186+
"disable the `buildkit` dependency optionally with `{}=1`",
187+
docker::Engine::CROSS_CONTAINER_ENGINE_NO_BUILDKIT_ENV
188+
)
189+
});
190+
}
191+
res?;
167192
Ok(image_name)
168193
}
169194

src/docker/engine.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub struct Engine {
6969
}
7070

7171
impl Engine {
72+
pub const CROSS_CONTAINER_ENGINE_NO_BUILDKIT_ENV: &'static str =
73+
"CROSS_CONTAINER_ENGINE_NO_BUILDKIT";
7274
pub fn new(
7375
in_docker: Option<bool>,
7476
is_remote: Option<bool>,
@@ -135,7 +137,7 @@ impl Engine {
135137

136138
#[must_use]
137139
pub fn has_buildkit() -> bool {
138-
!env::var("CROSS_CONTAINER_ENGINE_NO_BUILDKIT")
140+
!env::var(Self::CROSS_CONTAINER_ENGINE_NO_BUILDKIT_ENV)
139141
.map(|x| bool_from_envvar(&x))
140142
.unwrap_or_default()
141143
}

0 commit comments

Comments
 (0)