If I wanted to be able to target PowerPC / Darwin9 (Leopard), what would need to be added to the Swift compiler?
Would it be enough to add PowerPC / Darwin9 support to LLVM, and then the Swift infrastructure would automatically gain that target? Or would additional work be needed specific to the Swift compiler?
You probably couldn't get Objective-C support in this theoretical build of Swift because that requires support form the Objective-C Runtime support. But I'm sure it wouldn't be that hard considering someone ported a lot of Swift to Mac OS 9 at one point.
Aside from reviving LLVM's support for PowerPC Darwin, it's likely you'll have to modify the Swift runtime a bit; you could disable ObjC interop to avoid depending on the integration we get in newer versions of libobjc, but the runtime code also generally takes for granted a newer version of the C++ standard library than shipped in those older OSes. You might be able to treat it as an Embedded Swift target if you want to subset out any runtime support at all.
Yep, these days I’d probably start from embedded, so I wouldn’t have to chop the stdlib down and build the runtime up myself like I did with the hack. As has been said, you won’t get free ObjC interop, so no backporting Swift AppKit apps. You probably can get CF interop to work the same way I did, but that might take the wind out of your sails somewhat.
Get modern Clang to compile for powerpc-apple-darwin again
Go find all the places in the Swift codebase that use “darwin” as a shorthand for “has ObjC interop”. I got to skip this because I used “aix” as the name of the OS. (But you’d get to skip a lot of things I had to deal with about XCOFF.)
Make some module maps for the old OS SDKs, or find an SDK that still declares ppc things but is new enough for module maps.
Turn things off in the compiler until you have a subset that works. Get optimizations-on, no-debug-info working first, because it’s closest to what you would have had with C.
P.S. …it’s possible that you could get ObjC messages to work, just not subclassing. But the compiler right now only has “ObjC is present” and “ObjC is absent” modes, so this would be yet more work to disentangle.
I've just recently started looking at Iain Sandoe's fork of LLVM-7.x, the goal of which was to complete the unfinished PowerPC/Darwin work in LLVM. Might be a while before I can circle back around to Swift support
You can already target Darwin/PowerPC today, see x.com (and many other systems, see x.com), by cross-compiling to WebAssembly, and then further compiling to native code, via e.g. w2c2, or wasm2c.
This requires no changes to the Swift compiler or LLVM.
Even small Swift binaries are quite large, as they include the whole Standard Library. Those binaries can be translated to C very quickly with w2c2, but the final compilation with gcc takes quite a while, especially on era-appropriate hardware.
I need to look into what @turbolent’s done to make the ObjC parts work, I kinda assumed it just wouldn’t! Though I did say maybe objc_msgSend was going to be sufficient…
With w2c2, you should be able to run Swift on Amiga OS. I have not tried it myself, but as long as a C89 compiler is available, it should be little effort.