Cross-Compilation on Mac to Ubuntu Fails

The Swift 5.3.3 Ubuntu 20.04 Focal cross compiler in SPMDestinations is ready and seems to work fine with regular dynamic stdlib compiles, i.e. the Macro examples work and run.

It can be installed using:

brew install spmdestinations/tap/spm-dest-5.3-x86_64-ubuntu20.04

Then compile a project using:

swift build --destination /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu20.04.xtoolchain/destination.json

And you'll get proper results:

Zini18:Examples helge$ file .build/x86_64-unknown-linux/debug/express-simple-lambda
.build/x86_64-unknown-linux/debug/express-simple-lambda: ELF 64-bit LSB shared object, 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

Note that the Docker images still have no proper ld.so configuration, so either set LD_LIBRARY_PATH manually or do:

echo '/usr/lib/swift/linux'            > /etc/ld.so.conf.d/swift.conf;\
echo '/usr/lib/swift/clang/lib/linux' >> /etc/ld.so.conf.d/swift.conf;\
echo '/usr/lib/swift/pm'              >> /etc/ld.so.conf.d/swift.conf;\
ldconfig

to get things working. Have fun!

P.S.: Works on M1 as well.

1 Like