I have a build phase script in Xcode that used to build and run a Swift package. Before Xcode 11.4 I was able to build and run that package with swift run --package-path ProjectDir. Since Xcode 11.4 I get the following warning and error:
warning: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX'
error: module 'Swift' was created for incompatible target x86_64-apple-ios13.0: /var/folders/rc/y4glr2yj3xl_qk39vg4f4t_00000gn/C/org.llvm.clang.MyStuff/ModuleCache/Swift-3LLGH9HFMRPI6.swiftmodule
This only happens when I build/run the package from the build script. If I run the same command manually from the terminal, it all works great. So it's probably some environment variables the default swift build command relies on? Question is, what are they and how can I safely adjust them without affecting the xcode build process?
A Run Script build phase has a checkbox, “Show environment variables is build log”, that you can enable to investigate the script’s environment. I did a quick test here (with Xcode 11.4) and the most likely candidate is SDKROOT. Having said that, there are a lot of environment variables that reference the current SDK, so it’s easy to imagine something else tripping you up.