Currently, the build system build stdlibs for multiple SDKs in single cmake invocation.
This design of build system makes it complex to support multiple platforms as scalable because we need to configure them at once.
This design would work well if there is no difference in options between SDKs. However, if you want to change the options for each SDK, you have to either add options for each SDK to the add_library wrapper,
or call add_library for each SDKs using foreach in CMakeLists.txt.
If CMake configuration itself runs for each platforms, CMakeLists.txt can focus only on the platform.
To achieve the desired state, we need to separate stdlib CMake process for each platforms. But currently compiler and stdlib are built at once in single CMake unit. Therefore, we need to separate cmake process into compiler and stdlib at first.
Here is an example of build directory structure after this separation.
This follows the manifest of build system. https://github.com/apple/swift/blob/master/docs/BuildManifesto.md
The new structure of
swit-macosx-x86_64 is compatible with current directory structure, so there shouldn't be any effect for packaging toolchain.
Ninja-ReleaseAssert/ swift-macosx-x86_64/ bin/ swiftc swift … lib/swift macos/ (symbolic link to ../../swiftstdlib-macosx-x86_64/lib/swift/macosx) iphonesimulator/ (symbolic link to ../../swiftstdlib-iphonesimulator-x86_64/lib/swift/iphonesimulator) iphoneos/ (symbolic link to ../../swiftstdlib-iphoneos-arm64/lib/swift/iphoneos) swiftstdlib-macosx-x86_64/ lib/swift/macosx/ libswiftCore.dylib … test-macosx-x86_64/... swiftstdlib-iphonesimulator-x86_64/ lib/swift/iphonesimulator/ libswiftCore.dylib … swiftstdlib-iphoneos-arm64/ lib/swift/iphoneos/ libswiftCore.dylib …
To evolve incrementally and safely, I propose these steps.
Move statements related with only stdlib in the root CMakeLists.txt into ./stdlib/CMakeLists.txt
At this phase, compiler and stdlib are built in single cmake process but stdlib CMake variables scope is isolated from compiler CMake unit.
Change CMake system to build ./stdlib standalone.
And change build-script to invoke cmake for compiler and stdlib separately.
At this phase, directory structure would be like this
Ninja-ReleaseAssert/ swift-macosx-x86_64/ bin/ lib/swift macos/ (symbolic link to ../../swiftstdlib-macosx-x86_64/lib/swift/macosx) iphonesimulator/ (symbolic link to ../../swiftstdlib-macosx-x86_64/lib/swift/iphonesimulator) iphoneos/ (symbolic link to ../../swiftstdlib-macosx-x86_64/lib/swift/iphoneos) swiftstdlib-macosx-x86_64/ lib/swift/ macosx/ libswiftCore.dylib … iphonesimulator/ libswiftCore.dylib ... iphoneos/ libswiftCore.dylib … test-macosx-x86_64/
Deprecate SWIFT_SDKS and change build-script to invoke cmake for each SDK.
At this phase, directory structure should be the same as the desired state.
To evolve further, invoke cmake for each os/arch/platform triple instead of SDK.
Here is a draft change for this separation. (but not cleaned up yet, so still draft)
This branch is in "Step 2" and all test cases including validation-test are passed.
I want to confirm that this separation is worth doing. cc: @compnerd