WWDC2020 will be free to all developers through the Apple Developer App and the Apple Developer website! From last year’s SwiftUI and Combine to this year’s new Swift Student Challenge, the Swift era has come

I’m also a deep and obsessive developer for Swift, and kind of like playing the bottom! Thanks to Apple dad Swift is highly open source, but there’s always something missing in the day-to-day development process…

In fact, if I can not understand the bottom, directly into the source code to see the process, analyze the principle! This is perfect… So I have no hesitation: Swift source code compilation goes

If you are in a hurry to try something new, please click on my quick channel: Swift source code -Github address

I. Preparation for Swift compilation

  • Clone here we need to compile the source code
  • Version preparation: macOS 10.15.3 Xcode 11.5 (this is my current version, should only need Xcode 11.2)
  • The latest source code here requires Xcode 12.0 to compile. I am not currently upgrading, and it is still only beta, so I will not play it, after all, it will take some time! In case of instability
  • Because the compilation speed is still a little slow, I suggest that the computer performance is slightly higher, specific you decide
  • Network suggestion: Small stairs (not explained), stable network cable
  • The most important thing is: keep patient (there will definitely be various errors, or the time is very serious: 1-2h this is normal)

Two, start compiling

Xcode – Ninja – Linux – VScode! Each has its own convenience, here we won’t say the others first to a very familiar one: Xcode

1: Prepares the compilation directory

Create a directory for your favorite files

mkdir swift-source
cd swift-source
Copy the code

2: Clone source

Swift-5.2.4-release is the stable version used here, which is enough for the current development! In the future, please remember to follow my version, because the version is not the same and your Xcode is not compatible, after the error, I can not be responsible: haha haha

git clone-- - 5.2.4 - RELEASE branch swift https://github.com/apple/swift.gitCopy the code
  • It should be quick here if you have a little staircase

3: Clone supplementary verification

  • Jump below the Swift fileutils/update-checkout
  • Clone out the files required for subsequent compilation
  • This is important because update-checkout checks out the repository next to the Swift source directory
  • This step is also time-consuming. At this point, you can:Have a cup of coffee
. / swift/utils/update - checkout - tag swift - 5.2.4 - RELEASE - cloneCopy the code

4: Buid Swift (waiting)

  • Use swift source script compilation
./swift/utils/build-script -x -R --debug-swift
Copy the code
  • Apple’s Github also points out several examples of compiling, which you can also play with yourself!
  • If you are not proficient in compiling, you also want to avoid the pit (after all, this step takes 1-2h) follow the steps I give you, safe and reliable!
utils/build-script --release-debuginfo --debug-swift # Swift frontend built in debug
utils/build-script --release-debuginfo --debug-swift-stdlib # Standard library built in debug
utils/build-script --release-debuginfo --debug-swift --force-optimized-typechecker # Swift frontend sans type checker built in debug
Copy the code

/swift/utils/ build-script-h = /swift/utils/ build-script-h = /swift/utils/ build-script-h = /swift/utils/ build-script-h Such as compiling standard libraries and compiling LLDB and all…

After building the previous step, there will be a very long uncomfortable waiting process! If you’re bored, use this time to check out my other blog: Cooci_ Harmonious Learning – No rush

⚠️ : BUILD SUCCEEDED 😄

Debug Swift source code

To open the Swift project in Xcode, open /swift-source/build/ xcode-releaseassert + swift-debugassert /swift-macosx-x86_64/ swift.xcodeProj. It will automatically create many scenarios for all available targets. A common debugging flow will involve:

  • chooseswiftThe scheme.
  • Bring up theschemeEditor (⌘ ⇧ <).
  • chooseArgumentsTAB, and click+.
  • Add command line option, this is set according to your own requirements, if no special requirements, normal compilation
  • Shut downschemeEditor.
  • Compile and run.

Another option is to change the solution to Wait for Executable to be launched, and then run the build product on the terminal.

So far, the basic operation is finished, you can freely play in the sea of Swift, pay attention to the volume ~ hahaha ~

4. Analysis of the cause of construction failure

  • The probability of clone failure is network problems

  • Make sure you use the correct version of Xcode.

  • If you have changed the Xcode version and still experience errors related to the Xcode version, try passing –clean to build-script.

  • When you release a new version of Xcode, you can update the build by passing the –reconfigure option without recompiling the entire project.

  • Make sure all repositories are the latest in the update-checkout command above

Thank you

Swift source code -Github address

  • github.com/apple/swift
  • lldb.llvm.org/index.html
  • Forums.swift.org/t/debug-loc…
  • Github.com/apple/swift…
  • www.polidea.com/blog/how-to… Github.com/vadimcn/vsc…

OK, this article is finished here, you can go to download the first taste, if you still feel good, please do not spare your likes and star