Compile environment

  • Xcode: delivered with the Mac OS
  • Python: It comes with the Mac OS
  • Cmake:brew listThe command is not executed to check whether the installation is performedbrew install cmake
  • Ninja:brew listThe command is not executed to check whether the installation is performedbrew install ninja

compile

Clone swift source

  • Execute the commandgit clone --branch swift-x.x.x-RELEASE https://github.com/apple/swift.git
  • Can be achieved byxcrun swift -versionView current computerswiftThe version of the
  • What I’m compiling here isSwift - 5.2.4 - ReleaseIf you want to compile the latest source code, you can go to the official website to find the latestbranch.Xcode.swift.macOSIt is best to use the corresponding version.
  • cloneThe 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 compilationninja, can also be usedXcode. But in the actual testing processXcodeThe support after compilation is not particularly good. It is recommended to useninjaAs 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 aVSCode
  • Install the plug-in when completeCodeLLDB,Code Runner

  • Next configurationJsonfile

  • Modify theprogramfor${workspaceFolder}/build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-x86_64/bin/swiftThe 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.
  • findCodeLLDBInstallation directory of

  • And then find the compiled onelldbFile directory, copy all files in the directory to the directory above

  • Compile swiftlldbFile copy tovscode lldb/libDirectory, delete existingliblldb.dylibFile, and willlldbRename the file toliblldb.dylib.