SourceKit-LSP and build plugins

I've been looking into SwiftPM build plugins in the last month or so. Sometimes when building a clean project that includes source code generated from a build plugin I get a load of undefined symbols link errors from code using the generated code. eg The project GitHub - adam-fowler/soto-codegenerator-plugin-test produces the following errors

Undefined symbols for architecture arm64:
  "_$s7SotoSNS0B0V0A4Core10AWSServiceAAMc", referenced from:
      _$s7SotoSNS0B0VAC0A4Core10AWSServiceAAWl in SNSTest.swift.o
  "_$s7SotoSNS0B0V11createTopic_6logger2onAC06CreateD8ResponseVAC0gD5InputV_7Logging6LoggerV7NIOCore9EventLoop_pSgtYaKF", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY0_ in SNSTest.swift.o
     (maybe you meant: _$s7SotoSNS0B0V11createTopic_6logger2onAC06CreateD8ResponseVAC0gD5InputV_7Logging6LoggerV7NIOCore9EventLoop_pSgtYaKFfA0_)
  "_$s7SotoSNS0B0V11createTopic_6logger2onAC06CreateD8ResponseVAC0gD5InputV_7Logging6LoggerV7NIOCore9EventLoop_pSgtYaKFTu", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY0_ in SNSTest.swift.o
  "_$s7SotoSNS0B0V11deleteTopic_6logger2onyAC06DeleteD5InputV_7Logging6LoggerV7NIOCore9EventLoop_pSgtYaKF", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY2_ in SNSTest.swift.o
     (maybe you meant: _$s7SotoSNS0B0V11deleteTopic_6logger2onyAC06DeleteD5InputV_7Logging6LoggerV7NIOCore9EventLoop_pSgtYaKFfA0_)
  "_$s7SotoSNS0B0V11deleteTopic_6logger2onyAC06DeleteD5InputV_7Logging6LoggerV7NIOCore9EventLoop_pSgtYaKFTu", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY2_ in SNSTest.swift.o
  "_$s7SotoSNS0B0V16CreateTopicInputV10attributes20dataProtectionPolicy4name4tagsAESDyS2SGSg_SSSgSSSayAC3TagVGSgtcfC", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY0_ in SNSTest.swift.o
  "_$s7SotoSNS0B0V16DeleteTopicInputV8topicArnAESS_tcfC", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY2_ in SNSTest.swift.o
  "_$s7SotoSNS0B0V6client6region9partition8endpoint7timeout19byteBufferAllocator7optionsAC0A4Core9AWSClientC_AK6RegionVSgAK12AWSPartitionVSSSg7NIOCore10TimeAmountVSgAT04ByteiJ0VAK16AWSServiceConfigC7OptionsVtcfC", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY0_ in SNSTest.swift.o
  "_$s7SotoSNS0B0VN", referenced from:
      _$s7SNSTest3RunV4mainyyYaKFZTY0_ in SNSTest.swift.o
      _$s7SotoSNS0B0VAC0A4Core10AWSServiceAAWl in SNSTest.swift.o
ld: symbol(s) not found for architecture arm64

I only found this issue while the project is loaded into VS Code (Xcode works fine). It appears to be because sourcekit-lsp is running on the same folder. I can kill the sourcekit-lsp process and it will start compiling fine. Is there anything that sourcekit-lsp might be doing that could break the build?

This error appears when you’re running swift build, right? AFAIK SourceKit-LSP should not be interfering with the build directory.

Yes when I run swift build. I'm not sure how it could be affected by sourcekit-lsp but it does seem to be.

So you kill sourcekit-lsp and suddenly swift build starts working again?

yes

afaik it does interfere. it share and uodate the workspace definition, just like build artifacts. it may go in a way, and SPM has no support for locking files/share with another process (last time I checked)

That’s odd. I don’t have the time to look into it right now but if you’ve got some steps that reproduce the problem reasonably often (i.e. that I could try to reproduce locally and I might have success) could you file an issue in the sourcekit-lsp repository for it? Otherwise I’ll loose track of this forum thread.

2 years ago I tried to do something about it, however it didn't find much attention.

Here is the SourceKit-LSP issue SourceKit-LSP appears to interfere with SwiftPM build plugins · Issue #676 · apple/sourcekit-lsp · GitHub