Compile environment
- Xcode: delivered with the Mac OS
- Python: It comes with the Mac OS
- Cmake:
brew list
The command is not executed to check whether the installation is performedbrew install cmake
- Ninja:
brew list
The command is not executed to check whether the installation is performedbrew install ninja
compile
Clone swift source
- Execute the command
git clone --branch swift-x.x.x-RELEASE https://github.com/apple/swift.git
- Can be achieved by
xcrun swift -version
View current computerswift
The version of the - What I’m compiling here is
Swift - 5.2.4 - Release
If you want to compile the latest source code, you can go to the official website to find the latestbranch.Xcode
.swift
.macOS
It is best to use the corresponding version. clone
The finished file is around 700 megabytes
update-checkout
- Execute the command in the folder directory above
./swift/utils/update-checkout --tag swift-x.x.x-RELEASE --clone
- The purpose of this step is to pull the other branch files that we need to compile the source code. If you do not pull the swift source code in the following step, it will fail.
- The finished file size is about 3 gigabytes
Compile the source code
- It can be used during compilation
ninja
, can also be usedXcode
. But in the actual testing processXcode
The support after compilation is not particularly good. It is recommended to useninja
As a compilation tool. - perform
./swift/utils/build-script -r --debug-swift-stdlib --lldb
, may need to wait for a period of time, the final compiled file is about 50GB
Debug Swift using VSCode
- Download a
VSCode
- Install the plug-in when complete
CodeLLDB
,Code Runner
- Next configuration
Json
file
- Modify the
program
for${workspaceFolder}/build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-x86_64/bin/swift
The path to swift compiled for you - Once it’s up and running
- Past the breakpoint
- Debugging code
- When debugging the code, the possible region 3 does not show anything (because the CodeLLDB plugin does not support swift). The solution is as follows
- You are advised to back up data before performing the following steps to prevent misoperations.
- find
CodeLLDB
Installation directory of
- And then find the compiled one
lldb
File directory, copy all files in the directory to the directory above
- Compile swift
lldb
File copy tovscode lldb/lib
Directory, delete existingliblldb.dylib
File, and willlldb
Rename the file toliblldb.dylib
.