swift-toolchain-ios icon indicating copy to clipboard operation
swift-toolchain-ios copied to clipboard

Work on getting Swift 5+ support [don't merge yet]

Open michaelnew opened this issue 5 years ago • 4 comments

Still haven't gotten this to build successfully, but I wanted to put this here for potential feedback or at least to show what I've figured out so far. You're welcome to close if you don't want a half-completed PR sitting here.

Setup macOS 10.15.2 (Catalina) Xcode 11.3.1 or Xcode 11.4 beta (same result with both) swift-5.1.4-RELEASE

The swift build script seems to expect clang and llvm to be top level in the swift-source directory, hence the symlinks. This looks like an obvious bug, so it may not be needed in the future.

The clang patch seems like it's still needed. The build fails early without it.

With this setup it's able to build cmark and llvm for both macos and iphoneos, and swift for macosx, but then it fails on swift for iphoneos with this:

-- Build files have been written to: /Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/build/LLVMClangSwift_iphoneos/swift-iphoneos-arm64
+ popd
~/projects/swift-toolchain-ios/toolchains/swift-source
+ /usr/local/bin/cmake --build /Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/build/LLVMClangSwift_iphoneos/swift-iphoneos-arm64 -- -j4 all
[1/779][  0%][0.005s] Building CXX object stdlib/toolchain/Compatibility50/CMakeFiles/swiftCompatibility50-iphoneos-armv7s.dir/ProtocolConformance.cpp.o
FAILED: stdlib/toolchain/Compatibility50/CMakeFiles/swiftCompatibility50-iphoneos-armv7s.dir/ProtocolConformance.cpp.o 
/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/build/LLVMClangSwift_iphoneos/llvm-iphoneos-arm64/./bin/clang++  -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Istdlib/toolchain/Compatibility50 -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/swift/stdlib/toolchain/Compatibility50 -Iinclude -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/swift/include -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/llvm/include -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/build/LLVMClangSwift_iphoneos/llvm-iphoneos-arm64/include -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/llvm/tools/clang/include -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/build/LLVMClangSwift_iphoneos/llvm-iphoneos-arm64/tools/clang/include -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/cmark/src -I/Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/build/LLVMClangSwift_iphoneos/cmark-iphoneos-arm64/src -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -fno-sanitize=all -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1 -O3  -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk   -UNDEBUG  -fno-exceptions -fno-rtti -DSWIFT_TARGET_LIBRARY_NAME=swiftCompatibility50 -target armv7s-apple-ios10.0 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk -arch armv7s -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/../../../Developer/Library/Frameworks -mios-version-min=10.0 -O2 -g0 -UNDEBUG -DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -MD -MT stdlib/toolchain/Compatibility50/CMakeFiles/swiftCompatibility50-iphoneos-armv7s.dir/ProtocolConformance.cpp.o -MF stdlib/toolchain/Compatibility50/CMakeFiles/swiftCompatibility50-iphoneos-armv7s.dir/ProtocolConformance.cpp.o.d -o stdlib/toolchain/Compatibility50/CMakeFiles/swiftCompatibility50-iphoneos-armv7s.dir/ProtocolConformance.cpp.o -c /Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/swift/stdlib/toolchain/Compatibility50/ProtocolConformance.cpp
/bin/sh: /Users/mike/projects/swift-toolchain-ios/toolchains/swift-source/build/LLVMClangSwift_iphoneos/llvm-iphoneos-arm64/./bin/clang++: Bad CPU type in executable
[4/779][  0%][0.013s] Generating ../../../lib/swift/iphoneos/layouts-armv7.yaml
ninja: build stopped: subcommand failed.

Trying to build toolchain versions prior to 5.1.4 result in different errors. 5.1.3 in particular has this issue, which is why I've been using 5.1.4 (it seems to make it the furthest in the build process).

michaelnew avatar Feb 11 '20 01:02 michaelnew

Thanks for the PR! Just a heads-up, the buildbot_iphoneos_arm64_crosscompiler preset hasn't been updated in around three years which is probably why it's breaking. The flags that prepare-toolchain currently passes are derived from that preset itself. It might be helpful to use other, more recent presets as a reference point. Additionally, I'd recommend double-checking the recommended Xcode version for building the branch/tag you're on, since you often need to use a specific beta version to build the compiler.

kabiroberai avatar Feb 12 '20 14:02 kabiroberai

Hey there folks. I've got an interest in building an up to date toolchain for iOS as well. I filed a ticket just a while ago that lead me to this project after a lot more random github surfing: https://bugs.swift.org/browse/SR-13605. Essentially, you weren't able to build a particular library I was interested in. However, if I could get the whole darn toolchain in, then that may be the ticket. If I can be of any help here, please let me know! And hey, I'd be happy to share the project I'm working on with ya if you're interested as well.

@vaddieg, your last few comments seem to be proposed patches. @michaelnew, I could pull this down and apply those if you'd like. Or, have you perhaps made any more progress?

tikimcfee avatar Oct 16 '20 03:10 tikimcfee

@tikimcfee I haven't messed with this in a few months, but I'm still interested in getting it working. You're welcome to do anything you like and I'll be happy to help. I'll try building again today and at least see where things stand, but if you get something further along that this I can close this PR in favor of yours, or make changes here.

michaelnew avatar Oct 16 '20 18:10 michaelnew

While I personally haven't had the opportunity to make any progress on this either, it was recently brought to my attention that the Procursus bootstrap contains a working Swift toolchain for iOS: see Procursus/llvm.mk. I haven't tested that myself though, so I can't confirm that it's fully functional. It's also worth mentioning that if the ARM64 toolchain mentioned in #4 works as intended, it may be possible to entirely replace this toolchain with the one that comes with Xcode.

kabiroberai avatar Oct 16 '20 20:10 kabiroberai