SourceKit-LSP seems to ignore `CXXSettings.unsafeFlags`


I have set up a simple project using hand-built C++ library.

I have added custom C++ header search paths outside of the Package directory using CXXSettings.unsafeFlags as follows:

cxxSettings: [.unsafeFlags(["-I\(llvmIncludePath)"])],

but SourceKit-LSP ignores those include search paths. I have also tried to add those paths to the Swift Plugin for VSCode provided by SSWG, but this didn't work either.

Is the SourceKit-LSP ignoring unsafeFlags intentionally and if so, is there any workaround?

I have tried using swift package generate-xcodeproj and Xcode project works correctly (all the include paths are configured correctly).

You are probably best posting this in the sourcekit-lsp section of the forums. The VS Code extension is not involved at this point. The only time it gets involved is when you are adding cxxSettings via the command line build arguments

I have tried that too, using the Workspace Extension Settings and it didn't work for me.

Which version of sourcekit-lsp are you using? Could you try a recent development snapshot from - Download Swift? I might have fixed the issue a couple of weeks ago with Pass manual build arguments that specified using -Xswiftc when starting sourcekit-lsp, to the fallback build system by ahoppen · Pull Request #590 · apple/sourcekit-lsp · GitHub.

I guess the sourcekit-lsp was installed alongside the Xcode Toolchain. The sourcekit-lsp program itself didn't respond for command --version.

mikolasstuchlik@Mikolas-MacBook-Pro ~ % swift --version
swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang- clang-1316.0.20.12)
Target: arm64-apple-macosx12.0
mikolasstuchlik@Mikolas-MacBook-Pro ~ % which sourcekit-lsp
mikolasstuchlik@Mikolas-MacBook-Pro ~ % ls -la /usr/bin/sourcekit-lsp 
-rwxr-xr-x  76 root  wheel  167120  9 kvě 23:30 /usr/bin/sourcekit-lsp

Ah, OK, that wouldn’t contain the fix yet.

Could you try toe following

  • Download the most recent main open source snapshot toolchain from - Download Swift
  • Point Swift: Path in the settings of the Swift VSCode plugin to /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-08-01-a.xctoolchain/usr/bin
  • See if the issue still reproduces

I have followed your steps, the settings.json has following lines:

    "swift.path": "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-08-06-a.xctoolchain/usr/bin",
    "lldb.library": "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-08-06-a.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB"

but it didn't fix the issue. (I have restarted window multiple times.)

I have also tried to build the project via

mikolasstuchlik@10 RunLib % rm -rf .build 
mikolasstuchlik@10 RunLib % /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-08-06-a.xctoolchain/usr/bin/swift build

and it started to compile the project really slowly, my M1 MacBook Pro (base model) is going 90 °C on CPU and 7200 rpm on fan. Also clangd is the most cpu% process right now. (Edit 2: It also requested 1.34 GB for project with ~ 200 lines of C++ and Swift code.) (Edit 3: Now clangd uses 624% of the CPU.)

(It is compiling 22 line .cpp file which includes #include <boost/multiprecision/cpp_int.hpp> ~ 10 minutes and isn't finished yet :D

I have aborted the build, restarted the VSCode window, and another clangd process appeared, but it still uses 700% CPU.

Snímek obrazovky 2022-08-08 v 20.44.36

Closing VSCode would not help, so I have killed all the clangd task manually.

Thanks for checking. Looks like there’s another issue then. Could you file a bug report at Issues · apple/sourcekit-lsp · GitHub for this issue?

clangd using so much CPU is definitely an unrelated bug and probably an issue of clangd itself and not sourcekit-lsp. Anyway, could you file a separate bug report for that issue and include a project that reproduces the issue (if possible)?

1 Like

Here it is: SourceKit-LSP seems to ignore `CXXSettings.unsafeFlags` · Issue #609 · apple/sourcekit-lsp · GitHub :slight_smile:

1 Like