Hi all, I'm using alternative toolchain built from source in Xcode and I want Xcode to launch sourcekitd.framework embedded in the alternative toolchain.
But it turns out Xcode will check codesign (or macOS 's library validation?) of sourcekitd.framework.
Has anyone encountered this issue?
SourceKit error log:
error loading sourcekitd from /Users/bytedance/Library/Developer/Toolchains/my.xctoolchain: failed loading compiler framework: dlopen(/Users/bytedance/Library/Developer/Toolchains/my.xctoolchain/usr/lib/sourcekitd.framework/sourcekitd, 0x0104): tried: '/Users/bytedance/Library/Developer/Toolchains/my.xctoolchain/usr/lib/sourcekitd.framework/sourcekitd' (code signature in <4700A83D-FE76-3DC7-A19D-7D3FBD77BB9A> '/Users/bytedance/Library/Developer/Toolchains/my.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/System/Library/Frameworks/sourcekitd.framework/sourcekitd' (no such file), '/Users/bytedance/Library/Developer/Toolchains/my.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' (code signature in <4700A83D-FE76-3DC7-A19D-7D3FBD77BB9A> '/Users/bytedance/Library/Developer/Toolchains/my.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/System/Library/Frameworks/sourcekitd.framework/Versions/A/sourcekitd' (no such file)
That behavior is surprising to me and I couldn’t reproduce it for a locally-built toolchain. How did you build your toolchain?
Also, from the error messages, it looks like your toolchain is code-signed while mine isn’t. Could you try building a toolchain that is not code-signed or remove the code signature from sourcekitd.framework using codesign --remove-signature and see if that changes things?
it looks like your toolchain is code-signed while mine isn’t.
That's because I codesign the framework manually. The error log shows "/path/to/toolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.),"
in the first place, so I tried to sign it by myself and it seems Xcode needs sourcekitd to be signed by Apple or it won't load.
I couldn’t reproduce it for a locally-built toolchain
You mean you checked out the SourceKit log on your machine and the sourcekitd is loaded successfully by Xcode right? That's weird.
Hi Alex, I tried your build configuration ( -DSWIFT_SOURCEKIT_USE_INPROC_LIBRARY:BOOL=TRUE) and the error became
2022-03-22 20:46:23.688 Xcode[78934:819120] SourceKit-client: [2:toolchain:40451: 0.4599] error loading sourcekitd from
/Library/Developer/Toolchains/swift-BD-2022-03-22-standard_swift-no_assertions-no_test.xctoolchain:
failed loading compiler framework: dlopen(/Library/Developer/Toolchains/swift-BD-2022-03-22-standard_swift-no_assertions-no_test.xctoolchain/usr/lib/sourcekitd.framework/sourcekitd, 0x0104):
tried: '/Library/Developer/Toolchains/swift-BD-2022-03-22-standard_swift-no_assertions-no_test.xctoolchain/usr/lib/sourcekitd.framework/sourcekitd' (code signature in <4E011807-62F2-372A-94F5-A42AF210508B>
'/Library/Developer/Toolchains/swift-BD-2022-03-22-standard_swift-no_assertions-no_test.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd'
not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.),
'/System/Library/Frameworks/sourcekitd.framework/sourcekitd' (no such file),
'/Library/Developer/Toolchains/swift-BD-2022-03-22-standard_swift-no_assertions-no_test.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' (code signature in <4E011807-62F2-372A-94F5-A42AF210508B>
'/Library/Developer/Toolchains/swift-BD-2022-03-22-standard_swift-no_assertions-no_test.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.),
'/System/Library/Frameworks/sourcekitd.framework/Versions/A/sourcekitd' (no such file)
and
sourcekit: [2:sourcekitd_initialize:15627: 0.0000] initializing2022-03-22 20:46:23.770 Xcode[78934:819113] SourceKit-client: [2:toolchain:15627: 0.5415]
error loading sourcekitd from /Library/Developer/Toolchains/swift-5.5.3-RELEASE.xctoolchain: failed loading compiler framework: dlopen(/Library/Developer/Toolchains/swift-5.5.3-RELEASE.xctoolchain/usr/lib/sourcekitd.framework/sourcekitd, 0x0104):
tried: '/Library/Developer/Toolchains/swift-5.5.3-RELEASE.xctoolchain/usr/lib/sourcekitd.framework/sourcekitd' (code signature in <CEB13BBC-8328-3F55-BA54-D8256B7DE85E> '/Library/Developer/Toolchains/swift-5.5.3-RELEASE.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' not valid for use in process: mapping process is a platform binary, but mapped file is not),
'/System/Library/Frameworks/sourcekitd.framework/sourcekitd' (no such file), '/Library/Developer/Toolchains/swift-5.5.3-RELEASE.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' (code signature in <CEB13BBC-8328-3F55-BA54-D8256B7DE85E>
'/Library/Developer/Toolchains/swift-5.5.3-RELEASE.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/sourcekitd' not valid for use in process: mapping process is a platform binary, but mapped file is not),
'/System/Library/Frameworks/sourcekitd.framework/Versions/A/sourcekitd' (no such file)
That is very surprising. I haven’t heard any similar reports before and don’t see the issue either. Some more ideas/questions:
What do you have set in System Preferences -> Security & Privacy -> General -> Allow apps downloaded from. I suspect that this needs to be “App Store and identified developers”