Building a fat binary compiler?


Pretty basic question. I want to build the swift binaries as "fat" so they will work on both intel and apple silicon Macs, to give backward compatibility for people using old Macs.

I see the switch for utils/build-script looks like --host-target HOST_TARGET but I'm guessing you can't use it twice or pass two architectures? --host-target arm64;i386?

I know I could just try multiple attempts but the builds take hours so I thought I'd ask people if they have immediate feedback before I start! :slight_smile:


p.s. If there's absolutely no way to do this normally, I can probably live with doing the build twice, once for apple silicon and once for intel and making sure I keep the built binaries separate in my IDE, but it's clunky.

I believe when you build for Darwin it will automatically build fat binaries by default; this is configured in cmake/modules/DarwinSDKs.cmake.

1 Like

I'm not sure?

I built the "default" Swift using utils/build-script -R -t...

when I query the built compiler with file it only shows an arm64 slice...

ls Documents/Code/swift/build/Ninja-ReleaseAssert/
cmark-macosx-arm64		earlyswiftdriver-macosx-arm64	llvm-macosx-arm64		swift-macosx-arm64

file  Documents/Code/swift/build/Ninja-ReleaseAssert/swift-macosx-arm64/bin/swift-frontend 
Documents/Code/swift/build/Ninja-ReleaseAssert/swift-macosx-arm64/bin/swift-frontend: Mach-O 64-bit executable arm64

To be clear, I'm not saying I want to build a compiler that's capable of building code for Intel and Apple Silicon... I'm saying I want the compiler itself to be able to run on both of those architectures!

I don't have a working Intel machine at the moment (my old MacBook is needing repair) but I'm betting if I run the above compiler on it it won't work? Up to now, the solution I've come up with (which I don't like) is to run a Terminal in Rosetta2 mode, then build swift there, so it builds an Intel binary. Then that Intel binary can be deployed to anyone, but most users will have Apple Silicon machines and will be running their compilers under Rosetta2... slower and less efficient.