Description
Motivation
The Swift source in SwiftCompilerSources/
has long supported cross-compilation, added by @eeckstein in #40068 for Darwin a couple years ago and then in #40277 for non-Darwin Unix by me. However, the recently added Swift source in lib/{ASTGen,Macros}/
and tools/swift-plugin-server/
does not support cross-compilation, and the new swift-syntax parser never has. Before we start requiring the swift-syntax parser to build the Swift compiler, we better get it cross-compiling, as cross-compilation will be the only way to get the Swift compiler running on new platforms after that.
Proposed solution
I cross-compile the Swift compiler for Android AArch64 from a linux x86_64 host, and these are the three changes I had to make to get all this Swift source in the compiler itself cross-compiled:
- Add cross-compilation flags for Android to
_add_host_swift_compile_options()
, which is used to buildlib/{ASTGen,Macros}/
andtools/swift-plugin-server/
. This should be easy to generalize likeSwiftCompilerSources/
does. - Do the same in the swift-syntax repo with
add_swift_syntax_library()
: this may take more work to generalize because of the cross-repo CMake config. - Cross-compiling
swift-plugin-server
withadd_pure_swift_host_tool()
and 1. doesn't work, so I hacked it to use the oldadd_swift_host_tool()
instead. I forget the precise error but it had to do with itsswiftLLVMJSON
dependency in turn linking a C++ library,swiftBasic
, so the tool wasn't actually pure Swift. That works fine when natively compiling, but not when cross-compiling.
I can probably implement 1. easily for non-Darwin Unix, but I'm looking for input from @rintaro and @bnbarham on how we should properly fix the other two, plus I don't use Darwin or Windows so others will have to get cross-compilation working again there.