Issues with SwiftPM and Cross-compiling from Mac to arm64, armv7, armv6 and amd64


Over on the swift-arm slack channel we've recently been discussing a problem we've been having when cross-compiling. x-compiling seems to work fine on the platforms mentioned in the subject line, but we have a problem with SPM.

In our Package.swift files, we'd like to specify different architectures to use when fetching. In a std setup where we are compiling on the target architecture, we use #if os(Linux) to cause SPM to fetch the dependencies which only work on linux and #if os(macOS) to fetch the Mac-only dependencies.

However, when using the x-compile toolchain, we are running on a mac but targeting say, arm64. This works great at compile time, but at package fetch time, SPM has no way of knowing that the eventual target deps are for Linux.

Currently we are handling this by defining our own -D flags but it's really clumsy to pass these in. We have to do it once to fetch or update and then do it differently to compile.

My questions are:

  1. Is there a flag somewhere which handles this which I haven't been able to find?
  2. If not has x-compilation been considered by the SPM team as a scenario?

Ideally, it would be possible to tell SPM directly to compile Package.swift for the Mac but then execute it for a different target and have it all happen as part of a swift build command.

Hope I've been clear on this.