# Sourcekit breaks when compile\_commands.json contains /usr/bin/swiftc

**URL:** <https://forums.swift.org/t/sourcekit-breaks-when-compile-commands-json-contains-usr-bin-swiftc/83961>\
**Category:** SourceKit-LSP\
**Created:** [January 5, 2026, 4:58pm UTC](https://forums.swift.org/t/sourcekit-breaks-when-compile-commands-json-contains-usr-bin-swiftc/83961 "2026-01-05T16:58:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitayas](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/amitayas/32/44108_2.png) [@amitayas](https://forums.swift.org/u/amitayas)\
**Post date:** [January 5, 2026, 4:58pm UTC](https://forums.swift.org/t/sourcekit-breaks-when-compile-commands-json-contains-usr-bin-swiftc/83961/1 "2026-01-05T16:58:45Z")

</div>

Sourcekit lsp breaks when cmake generates a `compile_commands.json` with the swift compiler at `/usr/bin/swiftc`, logging stuff like `No language service for 'file:\/\/\/...`

Seems like this is not the actual `swiftc` binary, possibly a wrapper that points to the path produced by `xcrun --find swiftc`  
This can be solved by setting the correct swift compiler binary in cmake

```swift
if(APPLE)
    # Find the actual compiler binary, /usr/bin/swiftc doesn't work with sourcekit-lsp
    execute_process(
        COMMAND xcrun --find swiftc
        OUTPUT_VARIABLE SWIFTC_PATH
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )

    if(NOT CMAKE_Swift_COMPILER)
        set(CMAKE_Swift_COMPILER "${SWIFTC_PATH}" CACHE FILEPATH "Swift compiler path" FORCE)
    endif()
endif()

```

But this breaks compilation with errors like

```swift
<unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx26.0'
    ninja: build stopped: subcommand failed.

```

possibly because unlike `/usr/bin/swiftc`, the real binary at `xcrun --find swiftc` needs a `-sdk` flag even for the default macos sdk.  
This can be fixed either by populating `$SDKROOT` or setting `CMAKE_OSX_SYSROOT` in cmake.

```swift
if(APPLE)
    # Find the macOS SDK path, /usr/bin/swiftc compiles without a -sdk flag but the actual compiler still needs it
    execute_process(
        COMMAND xcrun --sdk macosx --show-sdk-path
        OUTPUT_VARIABLE MACOS_SDK_PATH
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    
    # Find the actual compiler binary, /usr/bin/swiftc doesn't work with sourcekit-lsp
    execute_process(
        COMMAND xcrun --find swiftc
        OUTPUT_VARIABLE SWIFTC_PATH
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )

    if(NOT CMAKE_OSX_SYSROOT)
        set(CMAKE_OSX_SYSROOT "${MACOS_SDK_PATH}" CACHE STRING "macOS SDK path" FORCE)
    endif()

    if(NOT CMAKE_Swift_COMPILER)
        set(CMAKE_Swift_COMPILER "${SWIFTC_PATH}" CACHE FILEPATH "Swift compiler path" FORCE)
    endif()
endif()

```

While the workaround is relatively straightforward, SourceKit-LSP should ideally work with `/usr/bin/swiftc` or `.swiftly/bin/swiftc` as they are the standard ways of invoking command line tools on Apple platforms.

---

<div class="post-metadata">

**Author:** ![ahoppen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ahoppen/32/36046_2.png) [@ahoppen](https://forums.swift.org/u/ahoppen)\
**Post date:** [January 5, 2026, 5:38pm UTC](https://forums.swift.org/t/sourcekit-breaks-when-compile-commands-json-contains-usr-bin-swiftc/83961/2 "2026-01-05T17:38:02Z")

</div>

I believe this should have been fixed by [Resolve `/usr/bin/*` shims on macOS by bnbarham · Pull Request #2362 · swiftlang/sourcekit-lsp · GitHub](https://github.com/swiftlang/sourcekit-lsp/pull/2362). Could you check if this is fixed in a recent Swift development snapshot? If not, could you file an issue at [GitHub - swiftlang/sourcekit-lsp: Language Server Protocol implementation for Swift and C-based languages](http://github.com/swiftlang/sourcekit-lsp)?

---

<div class="post-metadata">

**Author:** ![roopekv](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/roopekv/32/18084_2.png) [@roopekv](https://forums.swift.org/u/roopekv)\
**Post date:** [June 15, 2026, 9:03pm UTC](https://forums.swift.org/t/sourcekit-breaks-when-compile-commands-json-contains-usr-bin-swiftc/83961/3 "2026-06-15T21:03:39Z")

</div>

SourceKit Language Server 6.3.2 still doesn't seem to resolve `usr/bin/swiftc` in `compile_commands.json`. Still have to use the result of `xcrun --find swiftc` instead of just `usr/bin/swiftc` in `compile_commands.json` for the language services to work, otherwise getting `No language service for '...' found (-32001)`.
