Trying to build SourceKit-LSP on swift:latest Docker image

Hi! I've been trying to build the sourcekit-lsp project using the swift:latest image. I followed the instructions in the Building SourceKit-LSP section, and ran the commands below:

export PATH="/usr/bin:${PATH}"
swift package update
swift build -Xcxx -I/usr/lib/swift -Xcxx -I/usr/lib/swift/Block

But I get a bunch of missing header file errors - am I doing something obviously wrong? Any help or advice would be appreciated! I think it's a toolchain issue but the doc linked above says the Swift toolchain is located at / on the docker images.

This is the output I get from the commands above:

Building for debugging...
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/Support/circular_raw_ostream.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/circular_raw_ostream.h:17:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/raw_ostream.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/SmallVector.h:16:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/iterator_range.h:23:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
1 error generated.
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/Support/raw_ostream.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/raw_ostream.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/SmallVector.h:16:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/iterator_range.h:23:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/products/libllbuild/BuildSystem-C-API.cpp:16:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/Defer.h:16:10: fatal error: 'functional' file not found
#include <functional>
         ^~~~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/products/libllbuild/BuildDB-C-API.cpp:15:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/include/llbuild/BuildSystem/BuildKey.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/BinaryCoding.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/SmallVector.h:17:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/iterator_range.h:22:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/FilePathWatcher.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/FilePathWatcher.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/LLVM.h:24:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Casting.h:17:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/Support/YAMLTraits.cpp:9:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/YAMLTraits.h:12:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/Optional.h:19:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/Path.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/Path.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/LLVM.h:24:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Casting.h:17:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/products/libllbuild/BuildKey-C-API.cpp:16:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/include/llbuild/BuildSystem/BuildKey.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/BinaryCoding.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/SmallVector.h:17:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/iterator_range.h:22:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/Concurrency-Mac.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/Concurrency.h:17:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/StringRef.h:12:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/STLExtras.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/Optional.h:19:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/BuildSystem.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/include/llbuild/BuildSystem/BuildSystem.h:18:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/Subprocess.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/POSIXEnvironment.h:18:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/Hashing.h:48:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/Support/DataTypes.h:17:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm-c/DataTypes.h:28:10: fatal error: 'cmath' file not found
#include <cmath>
         ^~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/Logging.cpp:14:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/Logging.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/LLVM.h:24:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Casting.h:17:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
[0/640] Compiling IndexStoreDB_Support Logging.cpp
root@41fdef064d6a:~/sourcekit-lsp# export PATH="/usr/bin:${PATH}"
swift package update
swift build -Xcxx -I/usr/lib/swift -Xcxx -I/usr/lib/swift/Block
Updating https://github.com/apple/indexstore-db.git
Updated https://github.com/apple/indexstore-db.git (0.75s)
Updating https://github.com/apple/swift-package-manager.git
Updated https://github.com/apple/swift-package-manager.git (1.33s)
Updating https://github.com/apple/swift-tools-support-core.git
Updated https://github.com/apple/swift-tools-support-core.git (0.61s)
Updating https://github.com/apple/swift-llbuild.git
Updated https://github.com/apple/swift-llbuild.git (0.87s)
Updating https://github.com/apple/swift-driver.git
Updated https://github.com/apple/swift-driver.git (0.69s)
Updating https://github.com/apple/swift-system.git
Updating https://github.com/jpsim/Yams.git
Updating https://github.com/apple/swift-argument-parser.git
Updated https://github.com/jpsim/Yams.git (0.50s)
Updating https://github.com/apple/swift-collections.git
Updated https://github.com/apple/swift-system.git (0.51s)
Updating https://github.com/apple/swift-crypto.git
Updated https://github.com/apple/swift-argument-parser.git (0.55s)
Updated https://github.com/apple/swift-collections.git (0.52s)
Updated https://github.com/apple/swift-crypto.git (0.52s)
Computing version for https://github.com/apple/swift-system.git
Computed https://github.com/apple/swift-system.git at 1.1.1 (0.18s)
Computing version for https://github.com/apple/swift-crypto.git
Computed https://github.com/apple/swift-crypto.git at 1.1.7 (0.18s)
Computing version for https://github.com/jpsim/Yams.git
Computed https://github.com/jpsim/Yams.git at 5.0.1 (0.18s)
Computing version for https://github.com/apple/swift-argument-parser.git
Computed https://github.com/apple/swift-argument-parser.git at 1.0.3 (0.19s)
Computing version for https://github.com/apple/swift-collections.git
Computed https://github.com/apple/swift-collections.git at 1.0.3 (0.20s)
Everything is already up-to-date
Building for debugging...
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/Support/circular_raw_ostream.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/circular_raw_ostream.h:17:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/raw_ostream.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/SmallVector.h:16:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/iterator_range.h:23:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
1 error generated.
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/FilePathWatcher.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/FilePathWatcher.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/LLVM.h:24:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Casting.h:17:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/products/libllbuild/BuildDB-C-API.cpp:15:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/include/llbuild/BuildSystem/BuildKey.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/BinaryCoding.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/SmallVector.h:17:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/iterator_range.h:22:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/products/libllbuild/BuildSystem-C-API.cpp:16:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/Defer.h:16:10: fatal error: 'functional' file not found
#include <functional>
         ^~~~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/Path.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/Path.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/LLVM.h:24:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Casting.h:17:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/products/libllbuild/BuildKey-C-API.cpp:16:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/include/llbuild/BuildSystem/BuildKey.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/BinaryCoding.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/SmallVector.h:17:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/iterator_range.h:22:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/Support/YAMLTraits.cpp:9:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/YAMLTraits.h:12:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/Optional.h:19:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/Support/raw_ostream.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/raw_ostream.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/SmallVector.h:16:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/iterator_range.h:23:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/Logging.cpp:14:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/Logging.h:16:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/LLVM.h:24:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Casting.h:17:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/Concurrency-Mac.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/include/IndexStoreDB/Support/Concurrency.h:17:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/StringRef.h:12:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/STLExtras.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/ADT/Optional.h:19:
/root/sourcekit-lsp/.build/checkouts/indexstore-db/lib/LLVMSupport/include/llvm/Support/Compiler.h:19:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/BuildSystem.cpp:13:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/BuildSystem/include/llbuild/BuildSystem/BuildSystem.h:18:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/Subprocess.h:19:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/Basic/include/llbuild/Basic/POSIXEnvironment.h:18:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/Hashing.h:48:
In file included from /root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/Support/DataTypes.h:17:
/root/sourcekit-lsp/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm-c/DataTypes.h:28:10: fatal error: 'cmath' file not found
#include <cmath>
         ^~~~~~~
[0/640] Compiling llbuildBuildSystem BuildSystem.cpp

That’s odd. I just tried building sourcekit-lsp myself and it worked for me. Here’s what I did:

$ docker run --it swift:latest bash
# Now inside the docker container
$ git clone https://github.com/apple/sourcekit-lsp.git
$ cd sourcekit-lsp
$ export PATH="/usr/bin:${PATH}"
$ apt update
$ apt install libsqlite3-dev libncurses5-dev python3 ninja-build
$ swift build -Xcxx -I/usr/lib/swift -Xcxx -I/usr/lib/swift/Block

I’m just guessing now but maybe you’re swift:latest container isn’t up to date and you need to run docker pull swift:latest?

I think that was it... this has worked, thank you!