macOS ClangdXPC build error

Hi all,

I’m new to this list, so apologies if this is the wrong place to post clang/CMake build issues.

I'm trying to build the LLVM 8.0.0 final release on macOS High Sierra 10.13.6 using Xcode 9.4.1. But I'm seeing an error while creating the ClangdXPC Framework. It appears to be trying to copy the dylib from the wrong location (not where it was built):

Creating ClangdXPC framework
/Applications/ -E copy llvm/llvmorg-8.0.0/src/LLVM-build/tools/clang/tools/extra/clangd/xpc/ClangdXPC.Info.plist llvm/llvmorg-8.0.0/src/LLVM-build/lib/ClangdXPC.framework/Versions/A/Resources/Info.plist
/Applications/ -E copy llvm/llvmorg-8.0.0/src/LLVM-build/lib/libClangdXPCLib.dylib llvm/llvmorg-8.0.0/src/LLVM-build/lib/ClangdXPC.framework/Versions/A/ClangdXPC
Error copying file "llvm/llvmorg-8.0.0/src/LLVM-build/lib/libClangdXPCLib.dylib" to "llvm/llvmorg-8.0.0/src/LLVM-build/lib/ClangdXPC.framework/Versions/A/ClangdXPC".
make[1]: *** [llvm/llvmorg-8.0.0/src/LLVM-build/lib/ClangdXPC.framework] Error 1
Command /bin/sh failed with exit code 2

But my actual build location is here:


Note the Debug config in the path. I’ve set up the generated project such that I can build both the Debug and Release into separate directories. That way both can coexist.

I don't need XPC, so I tried disabling it by passing CLANGD_BUILD_XPC as off. But it looks like it gets forced to on at CMake config time when the platform is Darwin. We’re pulling in LLVM as an ExternalProject, so this results in a build error the first time we build our own project.

Popping up a layer, I tried disabling the clang build tools via CLANG_BUILD_TOOLS (since there doesn't seem to be build granularity for disabling the clang extra tools), but that resulted in a different build error.

At this point I had already spent too much time on work arounds, so I started digging into the actual issue. The problem is that CreateClangdXPCFramework.cmake seems to be using the wrong directory, both for where it’s creating the framework and where the built deliverables are located.

I worked around the copy error by replacing the CreateClangdXPCFramework.cmake script's a priory knowledge of the built binary paths with a target file generator pattern:

    # Copy the framework binary.
       # PAC 2019-03-22: Work around build error on Mac

- and -

    # Copy the Clangd binary.
      # PAC 2019-03-22: Work around build error on Mac

But while this works around the build failure, I still think that the framework is being built in the wrong place. It’s here:


Instead of here:


I tried fixing that basic problem, but LLVM is a huge project and I’m new to CMake, so I wasn’t successful. But since we don’t use the ClangdXPC.framework anyway, it wasn’t critical for me to fix this the correct way.

Maybe someone else can take this the rest of the way and fix it properly.


Allen Cronce

+jkorous, +via clangd-dev

It seems that the flag CLANGD_BUILD_XPC is enforced to on for Mac, not sure the motivation, but I think making it optional on Mac is reasonable.

Currently, you could work around it by removing the cmake configs.

Hi Allen,

Thanks for reporting this.

I sent a patch for review: [clangd][xpc][cmake] Respect explicit value of CLANGD_BUILD_XPC

I will look into the support for multiple build configurations.