I'm building a server app written in Swift and am trying to deploy it on Linux for the first time. I'm generally following this guide and some others found on the internet.
My docker command is:
docker run --rm -v "$PWD:/code" -w /code --platform linux/amd64 \
-e QEMU_CPU=max swift:latest <build-and-tar-script>
I then pack the binary along with the required shared Swift libs and upload them to my Ubuntu 23.10 server, and the binary crashes with "illegal instruction" before it gets a chance to do anything.
The shared libs are copied from the container, so they are the ones the binary was compiled against. Also, without them on my linux server my binary crashes with a missing .so message, so they are in the right place.
file mybinary prints this:
ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped
which seems correct.
I also tried to build the app with --static-swift-stdlibs and got the same result.
I know that I should probably run it in a container on the server too, but I was trying to avoid that to minimize overhead.
What am I doing wrong? Is this even possible to do at all, i.e. run this binary without a container on the server?
It appears that you have an ARM64 system but you're emulating Swift for Intel x86-64 on it using Qemu. That's not necessary and can lead to instructions that Qemu cannot emulate. Could you try running it this way:
? If that still doesn't work, please provide all of the output.