Cross-platform build fails with "qemu: uncaught target signal 4" (and "invalid manifest")

I've been working on a Vapor app, and now I want to deploy it to linux/amd64. I've got it containerized and working on my M1 Mac, but when I try to build the linux/amd64 version of the Docker image, it fails with

#0 311.2 Working copy of https://github.com/vapor/fluent-kit.git resolved at 1.36.1
#0 311.3 Creating working copy for https://github.com/apple/swift-nio-http2.git
#0 312.5 Working copy of https://github.com/apple/swift-nio-http2.git resolved at 1.23.1
#0 313.9 error: 'fluent-mysql-driver': Invalid manifest (compiled with: ["/usr/bin/swiftc", "-vfsoverlay", "/tmp/TemporaryDirectory.9c4qco/vfs.yaml", "-L", "/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift/pm/ManifestAPI", "-swift-version", "5", "-I", "/usr/lib/swift/pm/ManifestAPI", "-package-description-version", "5.5.0", "/build/.build/checkouts/fluent-mysql-driver/Package.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "/tmp/TemporaryDirectory.FggUCI/fluent-mysql-driver-manifest"])
#0 313.9 qemu: uncaught target signal 4 (Illegal instruction) - core dumped
#0 314.0 error: 'jwt': Invalid manifest (compiled with: ["/usr/bin/swiftc", "-vfsoverlay", "/tmp/TemporaryDirectory.pPdOzm/vfs.yaml", "-L", "/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift/pm/ManifestAPI", "-swift-version", "5", "-I", "/usr/lib/swift/pm/ManifestAPI", "-package-description-version", "5.4.0", "/build/.build/checkouts/jwt/Package.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "/tmp/TemporaryDirectory.DL6QYW/jwt-manifest"])
#0 314.0 qemu: uncaught target signal 4 (Illegal instruction) - core dumped
#0 355.4 error: fatalError
------
Dockerfile:21
--------------------
  19 |     # files do not change.
  20 |     COPY ./Package.* ./
  21 | >>> RUN swift package resolve
  22 |     
  23 |     # Copy entire repo into container
--------------------
ERROR: failed to solve: process "/bin/sh -c swift package resolve" did not complete successfully: exit code: 1

My build invocation looks like this:

docker build --platform linux/amd64 --build-arg QEMU_CPU=max --tag camsync:latest .

I'm using Docker v4.19.0. I'm not sure if the crash is due to the "Invalid manifest," which I'm not sure why it's invalid.

QEMU is the emulator and it isn't 100% reliable and causes issues with the Swift compiler. You can create an issue on GH for Swift but the easiest way is to build it on the same architecture in CI, using something like GH actions

(Sometimes simply retrying the build will work)

1 Like

That's disappointing, given that the swift.org website tells us to do this. I'll try building it on my server until I get CI working.

I'm not sure if Swift GitHub issues tracker is a better place for this than QEMU or Docker bug trackers. This doesn't look like something that would be fixed in the Swift toolchain itself.

This is a compiler crash isn't it? I could well be wrong but I know in the past with some of these issues they've gone back to the compiler team for a fix

2 Likes

I am receiving very similar crashes when cross compiling from M2 to linux/amd64

#25 136.5 error: 'swift-algorithms': Invalid manifest (compiled with: ["/usr/bin/swiftc", "-vfsoverlay", "/tmp/TemporaryDirectory.DHFRAj/vfs.yaml", "-L", "/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift/pm/ManifestAPI", "-swift-version", "5", "-I", "/usr/lib/swift/pm/ManifestAPI", "-package-description-version", "5.1.0", "/root/relay-swift/.build/checkouts/swift-algorithms/Package.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "/tmp/TemporaryDirectory.Q1U6md/swift-algorithms-manifest"])
#25 136.5 qemu: uncaught target signal 4 (Illegal instruction) - core dumped