Skip to content

Commit

Permalink
fix: always cross-compile to windows via xwin
Browse files Browse the repository at this point in the history
Cross-compiling from Windows to Windows using zigbuild is broken; we're
getting `zig cc` errors we can't fix. We should always use xwin instead.
If we detect Windows cross-compilation, we should always pick an xwin
container image, specifically the same one we recommend our users to use.
  • Loading branch information
mistydemeo committed Dec 12, 2024
1 parent c818b6b commit 82c4584
Show file tree
Hide file tree
Showing 4 changed files with 684 additions and 13 deletions.
31 changes: 25 additions & 6 deletions cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use axoasset::{LocalAsset, SourceFile};
use axoprocess::Cmd;
use camino::{Utf8Path, Utf8PathBuf};
use cargo_dist_schema::{
target_lexicon::{self, OperatingSystem, Triple},
AptPackageName, ChocolateyPackageName, GhaRunStep, GithubGlobalJobConfig, GithubLocalJobConfig,
GithubMatrix, GithubRunnerConfig, GithubRunnerRef, GithubRunners, HomebrewPackageName,
PackageInstallScript, PackageVersion, PipPackageName, TripleNameRef,
target_lexicon::{self, Architecture, OperatingSystem, Triple},
AptPackageName, ChocolateyPackageName, ContainerImageRef, GhaRunStep, GithubGlobalJobConfig,
GithubLocalJobConfig, GithubMatrix, GithubRunnerConfig, GithubRunnerRef, GithubRunners,
HomebrewPackageName, PackageInstallScript, PackageVersion, PipPackageName, TripleNameRef,
};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
Expand All @@ -26,7 +26,7 @@ use crate::{
JinjaGithubRepoPair, JobStyle, ProductionMode, PublishStyle, SystemDependencies,
},
errors::DistResult,
platform::github_runners::target_for_github_runner_or_default,
platform::{github_runners::target_for_github_runner_or_default, targets},
CargoBuildWrapper, DistError, DistGraph, SortedMap, SortedSet,
};

Expand Down Expand Up @@ -661,13 +661,32 @@ fn github_runner_for_target(
let result = Some(match target_triple.operating_system {
OperatingSystem::Linux => runner_to_config(GithubRunnerRef::from_str("ubuntu-20.04")),
OperatingSystem::Darwin => runner_to_config(GithubRunnerRef::from_str("macos-13")),
OperatingSystem::Windows => runner_to_config(GithubRunnerRef::from_str("windows-2019")),
OperatingSystem::Windows => {
// Default to cargo-xwin for Windows cross-compiles
if target_triple.architecture != Architecture::X86_64 {
cargo_xwin()
} else {
runner_to_config(GithubRunnerRef::from_str("windows-2019"))
}
}
_ => return Ok(None),
});

Ok(result)
}

fn cargo_xwin() -> GithubRunnerConfig {
GithubRunnerConfig {
runner: GithubRunnerRef::from_str("ubuntu-20.04").to_owned(),
host: targets::TARGET_X64_LINUX_GNU.to_owned(),
container: Some(cargo_dist_schema::ContainerConfig {
image: ContainerImageRef::from_str("messense/cargo-xwin").to_owned(),
host: targets::TARGET_X64_LINUX_MUSL.to_owned(),
package_manager: None,
}),
}
}

fn brewfile_from<'a>(packages: impl Iterator<Item = &'a HomebrewPackageName>) -> String {
packages
.map(|p| {
Expand Down
6 changes: 1 addition & 5 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,6 @@ pub fn build_wrapper_for_cross(
},
// compiling for Windows (making PE binaries, .dll files, etc.)
OperatingSystem::Windows => match host.operating_system {
OperatingSystem::Windows => {
// this is just cross-arch, hopefully no wrappers are needed?
Ok(Some(CargoBuildWrapper::ZigBuild))
}
OperatingSystem::Linux | OperatingSystem::Darwin => {
// cargo-xwin is made for that
Ok(Some(CargoBuildWrapper::Xwin))
Expand All @@ -498,7 +494,7 @@ pub fn build_wrapper_for_cross(
Err(DistError::UnsupportedCrossCompile {
host: host.clone(),
target: target.clone(),
details: format!("no idea how to cross-compile from {host} to windows"),
details: format!("no idea how to cross-compile from {host} to windows with architecture {}", target.architecture),
})
}
},
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/integration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ fn axolotlsay_cross2() -> Result<(), miette::Report> {
[workspace.metadata.dist]
cargo-dist-version = "{dist_version}"
installers = ["shell", "powershell"]
targets = ["aarch64-unknown-linux-gnu"]
targets = ["aarch64-unknown-linux-gnu", "aarch64-pc-windows-msvc"]
ci = ["github"]
unix-archive = ".tar.gz"
windows-archive = ".tar.gz"
Expand Down
Loading

0 comments on commit 82c4584

Please sign in to comment.