you might have luck with $(xcrun -f swiftc) -emit-executable ...
technical details: I believe this is an issue in libxcselect where the macOS CLI stubs override SDKROOT. that is, /usr/bin/swiftc sets SDKROOT=/path/to/MacOSX.sdk before jumping to the actual swiftc binary.
Using swiftc reported by xcrun -f swiftc (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc) did the trick, thank you!
Manually setting the SDKROOT environment variable to iphoneos or its SDK path before calling swiftc at /usr/bin/swiftc also seems to work.