Project: FoundationDB (App Definition and Development / Database)
File: SWIFT_IDE_SETUP.md

Swift provides a language server implementation (https://github.com/apple/sourcekit-lsp) that should work with any LSP compatible editor. In this guide we'll cover how to set up VSCode for local development on a Mac, however other setups should work in the same way. Note that Swift 5.9 (or higher) is required for the build at the time of writing this guide. You can download Swift toolchains from , or by using the experimental https://github.com/swift-server/swiftly which simplifies this process. Download and install latest Swift toolchain: https://www.swift.org/download/ Use the following version: Snapshots / Trunk Development (5.9)* Note the path of the installed toolchain suffixed with `/usr` as `FOUNDATIONDB_SWIFT_TOOLCHAIN_ROOT`, e.g.: ```bash export FOUNDATIONDBSWIFTTOOLCHAIN_ROOT=/Library/Developer/Toolchains/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a.xctoolchain/usr ``` For linker and object file tools: Download LLVM toolchain: arm64: https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang+llvm-15.0.7-arm64-apple-darwin22.0.tar.xz from: https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7 Note the path of the installed LLVM toolchain + /usr as `FOUNDATIONDB_LLVM_TOOLCHAIN_ROOT`, e.g. ```bash cd ~/Downloads wget https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang+llvm-15.0.7-arm64-apple-darwin22.0.tar.xz tar xzf clang+llvm-15.0.7-arm64-apple-darwin22.0.tar.xz export FOUNDATIONDBLLVMTOOLCHAIN_ROOT=~/Downloads/clang+llvm-15.0.7-arm64-apple-darwin22.0 ``` For actor compiler: Download and install mono: , e.g. ```bash brew install mono ``` The Foundation DB will be used on the host as the system SDK/root against which to build. This is done by using docker and extracting the image You may need to make sure that you have the latest foundationdb docker image pulled: ```bash docker pull foundationdb/build:centos7-latest ``` ```bash cd mkdir fdb-build && cd fdb-build docker run -ti foundationdb/build:centos7-latest mkdir container-root && cd container-root tar -xzf ../container-root.tar ``` This Note that `FOUNDATIONDB_LINUX_CONTAINER_ROOT` becomes `~/fdb-build/container-root`. ```bash export FOUNDATIONDBLINUXCONTAINER_ROOT=~/fdb-build/container-root ``` Now that you have setup your host, and obtained `FOUNDATIONDBSWIFTTOOLCHAINROOT` , `FOUNDATIONDBLLVMTOOLCHAINROOT`, `FOUNDATIONDBLINUXCONTAINER_ROOT` you can run cmake. You need to ensure you pass in these three flags, and `-C<foundation-db-source>/cmake/toolchain/macos-to-linux.cmake` after the flags. For example: ```bash cd ~/fdb-build mkdir build && cd build xcrun cmake -G Ninja -DCMAKEMAKEPROGRAM=$(xcrun --find ninja) \ -DFOUNDATIONDBSWIFTTOOLCHAINROOT=$FOUNDATIONDBSWIFTTOOLCHAINROOT \ -DFOUNDATIONDBLLVMTOOLCHAINROOT=$FOUNDATIONDBLLVMTOOLCHAINROOT \ -DFOUNDATIONDBLINUXCONTAINERROOT=$FOUNDATIONDBLINUXCONTAINERROOT \ -C$HOME/src/foundationdb/cmake/toolchain/macos-to-linux.cmake \ $HOME/src/foundationdb ``` If you get a warning about not being able to execute `lld` or other binaries from the toolchain because they're not trusted, open `Privacy & Security` and find a button "Allow Anyway" and click it once. [Image: Screenshot 2023-04-17 at 12.47.01.png] After configuration, make sure things get pre build to be usable in IDE: ```bash xcrun cmake --build . -- prebuildforide ``` Now you should see that your source directory has a `compile_commands.json` file. Now you can open your source directory in VSCode. Setup: Install the official Swift plugin* it's the one maintained by Swift Server Work Group* For extension settings Update `Swift: Path` to point to the Swift toolchain installed in the first step (e.g. `/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-05-01-a.xctoolchain/usr/bin`) Do not omit the /usr/bin in the path (!) [Image: Screenshot 2023-03-16 at 7.25.21 PM.png] Disable the default "C++" plugin To make sure sourcekit-lsp is used for C++ files. jump-to-definition fails to open actor header files. jump-to-definition from C++ to Swift does not work. Code completion for semantic responses in Swift can be slow sometimes especially in files that import both FDBServer and FDBClient