How can I track down the mixed language SPM error? Why did it suddenly come up?

Hi all, running into this error on swift build:
error: target at '/blah...' contains mixed language source files; feature not supported

  • This is coming from a dependency of one of my dependencies. Is there an easy way to track down where?
  • If all the packages are cached, how could this happen? did one of them had an update that introduced this problem? I am using the .package(url: "...", from: "...") syntax, so there could have been an update, but I didn't manually update the packages. Did xcode do this on its own at some point? Should I be locking dependencies to specific versions?

This is happening on a project I added to my xcode workspace that contains a package.swift file. I'm on xcode 1.3.1

Hmm, the error suggests that you have source files for different languages (say .swift files & .c files) in one module. You could try running

find Sources/TheModuleItComplainsABout -type f | cut -d. -f2 | sort | uniq

Which should list all file extensions in that module (assuming there's only one dot in the file name). For example for SwiftNIO (where everything is fine), this looks like

johannes:~/devel/swift-nio (master)
$ find Sources/NIO -type f | cut -d. -f2 | sort | uniq
swift

So it just lists swift. If this command listed say swift & c, then that would be a problem.

That's clever, thank you, I'll definitely keep that in mind in these situations. Strangely enough this error disappeared in Xcode 11.4... I didn't really change anything else except update the Package.swift version (That I'm aware of, at least). Maybe this was just a bad error message or maybe the latest version of SwiftPM handles this better, I have no idea. :man_shrugging:

The only thing I’m aware of that changed is that .h used to be completely ignored. The addition of resource handling to master resulted in .h being inadvertently considered a resource, so it was switched to be treated as though it were a .c file, and I think that change landed early in 5.2. That means if you had .h files mixed with .swift files, it used to work (by ignoring them), but now you would get that error about mixed languages. If that is what is happening and you don’t want to move the .h file, you can specify it in the target’s exclude parameter.

[Edit: Never mind. I read your versions backwards. I thought you said the error appeared in 11.4, not that it was fixed in 11.4. I have no idea what it was then.]

Terms of Service

Privacy Policy

Cookie Policy