Skip to content

Most of the Swift source now built into the Swift compiler does not have a cross-compilation CMake configuration #71507

Open
@finagolfin

Description

@finagolfin

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:

  1. Add cross-compilation flags for Android to _add_host_swift_compile_options(), which is used to build lib/{ASTGen,Macros}/ and tools/swift-plugin-server/. This should be easy to generalize like SwiftCompilerSources/ does.
  2. 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.
  3. Cross-compiling swift-plugin-server with add_pure_swift_host_tool() and 1. doesn't work, so I hacked it to use the old add_swift_host_tool() instead. I forget the precise error but it had to do with its swiftLLVMJSON 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    build-scriptArea → utils: The build scriptcmakecross-compilationArea → utils: Cross-compilation of project sourcesfeatureA feature request or implementationutilsArea: the build system and other accessory scripts under the "utils" directory

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions