I already filed a radar (rdar://FB9726200, OpenRadar) for this thinking it was an Xcode issue, but now I'm wondering it it's an issue in swiftc.
Merely adding a file to one of my targets it makes it fail to build with:
error: module name "ca.momchilov.Demo-Privileged-Helper-App.helper" is not a valid identifier
Command CompileSwiftSources failed with a nonzero exit code
Unchecking the target membership box for that file makes the project build fine again (even though the product module name hasn't changed at all in doing that).
This issue is in a small dummy project, which I'd be glad to share (what would be the best way? IDK if it's a good idea to post random Google Drive download links on a forum like this). I don't know which specific reproduction steps cause the issue, though.
Is it the first Swift file in that target? And does that target have a custom MODULE_NAME build setting? That could explain how you got into this scenario.
(As far as I understand it, all three have to be the same for a privileged helper tool.)
Though this doesn't seem to be an issue unless I add any further Swift files to the target.
Idk how safe it is to be running random Xcode projects from some random guy on the internet, but I've uploaded my source to GitLab so people can take a look. (I don't have any pre/post build scripts or anything like that)
Ahh, yeah, PRODUCT_MODULE_NAME does have to be a valid identifier. It’s weird that it’s being ignored for main.swift though. There’s a feature for single-file modules that infers the module name from the file name (sans .swift) unless it’s an invalid identifier, but that shouldn’t kick in if you explicitly provide one.
Hrm, sounds like Xcode is manually doing the same thing the compiler is doing, but it shouldn’t do that when the module name is customized. Worth filing a Feedback!
Changing the diagnostic seems like a good idea; it clearly wasn’t clear enough.
I’m not sure why the module cache mattered in this case. I guess that could be a separate Feedback. (I’m not convinced it’s something you could see with just the compiler or SwiftPM.)