I’ve used a local variation of this script when Xcode has gotten very tangled:
… https://gist.github.com/maciekish/66b6deaa7bc979d0a16c50784e16d697
#!/bin/bash
killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
open /Applications/Xcode.app
I haven’t met the clang paths in recent years, and there’s a build data path that might need to be targeted in the same place as that com.apple.dt.Xcode cache path.
No warranties, have solid backups beforehand, YMMV, etc.