Issue Building All of a sudden

Get Sources/SwiftSyntaxParser/CNodes.swift:13:29 no such module '_InternalSwiftSyntaxParser'

So I was building just fine...

I added some code and then I went to build again and now I get the error in title.

I commented out all the code changes, basically reverting it when it last built, and it still now throws that error no matter what.

What would have caused this?

_InternalSwiftSyntaxParser was a hidden piece of the Swift toolchain through 5.7, secretly exposed for SwiftSyntax to use. In Swift 5.8, it no longer exists, because the corresponding release of SwiftSyntax no longer uses it.

So my guess would be you updated Swift, either directly or by switching to a different machine. Simply update SwiftSyntax and the problem should go away.

In the project navigator, under Package Dependencies, SwiftSyntax has the detailed info of 509.0.0-swift-DEV next to it.

IS that not the latest? It doesn't seem like I can update further than that.

But perhaps that isn't enough? In any case, building with that version yields the same results.

That tag was truncated and could be one of several, but the most recent match (509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-05-20-a) does not even have any Sources/SwiftSyntaxParser directory, from which your error originated:

Ergo: Is your cache stale?

I've tried clearing cache several time via File ->Packages -> Reset Package Caches but it doesn't seem to help.

I resorted to just deleting that folder as you are correct it isn't even in there and now when I build it complains that the folder is missing.

I should note I'm using this git rep. GitHub - fuziki/UnityCoreBluetooth: Unity Bluetooth Plugin for iOS & macOS Editor

I'm pretty new to Xcode and iOS/Mac native development and swift itself so I'm a bit confused between the package dependencies listed in the workspace vs the target packages. No idea where its trying to ref that old version from. Maybe a makefile or something like in the repo?

That cache just stores the fetched packages so you do not need to use the network a second time. The relevant caches would be those that store pieces of the build. For raw SwiftPM, that would be .build in the main project repository. For Xcode, that would be DerivedData (wherever your preferences and flags put it—by default /Users/[user]/Library/Developer/Xcode/DerivedData).

Is it not enough to clean build? That's what I've been doing every time before I build again.
I'll try deleting things manually I guess to see if that helps.

The Xcode workspace contains a pin of SwiftSyntax at version 0.50600.1, which can only be used with the Swift 5.6 toolchain. (Although that does not appear to be relevant to the project itself, just to its examples, etc. The main manifest has no dependencies whatsoever.)

I am trying to build the examples to test code out.

It is supposed to be, but in reality it isn’t always. Telling Xcode to clean the build makes it clean what it knows about, which does not include the destinations of severed references. Such things, if still present in the file system, might still be caught in the nets of lower level tools like the Swift compiler.

If swift test covers what you are working on so you can just ignore the Xcode workspace, that would be the simplest.

Otherwise you will need to either reconcile the versions of Swift and of SwiftSyntax or else disable the particular piece that uses SwiftSyntax while you work. (From a quick glance, it appears to be used only by SwiftLint, which is probably just there to format or to check style guide conformance in the source files, not for linking any functionality into the product. If so it would be safe to skip.)

Can you go into more detail on the recommendation to reconcile and skip?

Reconcile: Upgrade swift version? How? Downgrade Package Version? Right now I'm stuck because it says it can't find the Package I deleted in the cached area. IDK how to get it to unstuck itself here. Happens when I build.

Skip: ? No idea how to do that either.

Thanks for some leads so far though.

Never mind. I tried it myself from a fresh clone (with Xcode 14.2 and Swift 5.7.2 on macOS 12.6.6) and successfully built and tested every scheme with no changes necessary. Several of them automatically downloaded _InternalSwiftSyntaxParser as a binary.

Does it also work for you with a clean checkout? (Copy any changes you want to keep elsewhere while you try.) If so, start over from there. In this case the error cause was apparently something you changed, so reapply your changes bit by bit to see when the problem resurfaces.

If it does not work from a clean checkout, then it must be some cache issue. All I can suggest is to clear out as many as you can find. The most likely culprit is tools/.build (which is where the missing binary ended up when I asked the project to build). Otherwise, my general cache resetting script contains the following entries. It is a very broad net, so use it at your own risk.

set -x

# SwiftPM
rm -frv /Users/**/.build
swift package purge-cache

# Xcode
rm -frv /Users/*/Library/Caches/com.apple.dt.*
rm -frv /Users/*/Library/CoreSimulator/Caches/*
rm -frv /Users/*/Library/Developer/Xcode/DerivedData/*

(UnityCoreBluetooth contains script phases that ask command line SwiftPM to do things, so its caches are relevant even if you are looking at Xcode’s interface when you tell it to build.)

Thanks for that info.

I ended up commenting out make Lint in during a build phase for the target mac example and got it to build.

I'll see if a recheck out works though.