cross-rs/cross

Improve error message on CI when target = MSVC or Darwin and target = host

Emilgardis opened this issue · 4 comments

With #661, we now error on warnings in CI.

[cross] warning: `cross` does not provide a Docker image for target x86_64-apple-darwin, specify a custom image in `Cross.toml`.
[cross] error: Errors encountered before cross compilation, aborting.
[cross] note: Disable this with `CROSS_NO_WARNINGS=0`

To clear up confusion, we could suggest a fix that just running cargo could work, we can also point to https://github.com/cross-rs/cross-toolchains.

See discussion

The way to solve this would probably be to add a check in the error path here:

cross/src/lib.rs

Lines 775 to 787 in f272b47

let image = match docker::get_image(&config, &target, uses_zig) {
Ok(i) => i,
Err(docker::GetImageError::NoCompatibleImages(..))
if config.dockerfile(&target)?.is_some() =>
{
"scratch".into()
}
Err(err) => {
msg_info.warn(err)?;
return Ok(None);
}
};

where we check if the target is x86_64-pc-windows-msvc, x86_64-apple-darwin or aarch64-apple-darwin (probably some more targets we could add here), and if it is, emit a info message suggesting if the host is similar to the target, just running cargo ... could work. Lastly suggest cross-toolchains

I hit that issue today and got confused indeed :). Many thanks @Emilgardis for the swift help in the matrix channel!

I hit the same thing. Setting CROSS_NO_WARNINGS=0 worked as a quick fix but of course not ideal to ignore warnings in general.

Rather than simply improving the error message, perhaps it would be useful to have an explicit option to allow failing back automatically in such cases? The rationale here is that it is convenient when doing matrix builds which include a variety of targets, some of which require cross and some which do not. Of course it is possible to enumerate which is which in the matrix and avoid the issue, so this is simply for convenience.

@fujiapple852 an automatic fallback would be the opposite of the intended behaviour. Perhaps a way to say "i dont care about cross not supporting this target, but I do care about other warnings in ci" is needed.

I dont like this approach though, the reason for doing this was that cross shouldnt be used in those cases, and some people were/are under the false impression that cross does work for these targets, when it actually doesnt