I’m debugging a similar issue in R.swift, I think I’ve found the cause of the issue.
Xcode 13 appears to execute Run Script build phases during index builds. This can cause a file to be written to by an index pass, in parallel with a build.
To check if this is happening for you, add this to your build script: say $ACTION
On Xcode 12, it only says “build”, but in Xcode 13 I hear it saying “indexbuild” during compilation, whenever I save .swift files or otherwise navigate through my code.
To prevent your script from running during indexing, add this check:
if [ $ACTION != "indexbuild" ]; then
# your script here
fi