swift: Regression: Xcode 15 cannot build correctly for macOS versions older than 10.15

Description According to the documentation, Xcode is supposed to be able to build for macOS 10.13 and up. However, this does not seem to be the case in practice; my testers on 10.14.6 have reported random crashes when trying to test my app when built with Xcode 15 beta. I’ve isolated the code that crashes to a simple test case, and posted it on GitHub Issues, but it seems to have attracted no attention:

https://github.com/apple/swift/issues/67614

I’ve reproduced the bug in Xcode 15 beta 5, beta 6, and beta 7.

What’s more, I decided to spin up a macOS 10.13 VM in UTM to see what would happen there. On 10.13 it doesn’t even launch:

dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /Users/csrstka/Desktop/crashtest
  Reason: image not found
Abort trap: 6

It seems that Xcode 15 is not correctly including the embedded Swift libraries for use on macOS versions older than 10.15. On macOS 10.14.6, it seems there are embedded Swift libraries in /usr/lib/swift, but they are apparently buggy and not compatible with modern Swift code. The net result is that although it claims to be able to build for 10.13, the effective minimum target is 10.15, and this should either be fixed before release, or the documentation should be updated to reflect the change.

Steps to reproduce

Write this code to a file called crashexample.swift:

class MyObject {
    var dict: [String : String] = [:]
}

print("creating object")
let obj = MyObject() // crashes here
print("created object") // will never be logged
print("object is \(obj)")

Then compile it with the following command:

swiftc -O -target x86_64-apple-macos10.13 crashexample.swift

Now copy the resulting binary to a Mac running an older macOS version. On 10.14.6 it will crash. On 10.13 it will not even start up.

Expected behavior Code should work, and not crash, or Xcode should be updated to reflect that its actual minimum target is 10.15.

Environment

  • Swift compiler version info
$ swiftc -version
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.106 clang-1500.0.40.1)
Target: arm64-apple-macosx13.0
  • Xcode version info 15 beta 7 (15A5229h) but it has also happened in betas 5 and 6
  • Deployment target: macOS 10.13

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 2
  • Comments: 26 (7 by maintainers)

Most upvoted comments

Solved in Xcode 15.1 beta

Solved in Xcode 15.1 beta

The Xcode 15.1 beta release notes don’t actually say that.

The release notes of Xcode 15.0 at least list that as a known issue:

Better than nothing. But if Xcode 15 officially supports macOS 10.13, then it shouldn’t take so long to fix the issue. Since it was known from the beginning, Xcode 15 should have removed support for 10.13 at least as long as the issue wasn’t fixed. Not everybody reads the release notes.

@nickasd No. However, I found a workaround. It might not work with you, but it worths trying.

The workaround is: Disable “Generate asset symbols” for SwiftUI. This option generates symbols for SwiftUI which creates SwiftUI dependencies.

@michaeljtsai the issue was finally confirmed with a workaround in the Xcode 15.1 Beta 2 release notes: https://forums.swift.org/t/regression-xcode-15-cant-build-swift-for-macos-earlier-than-10-15/66986/8 The Beta 3 release notes state “Fixed: Swift apps built with Xcode 15.0 crash on launch on macOS 10.13. (114820860)”

Thanks, I’m able to replicate that problem as well. Filed this internally, and I’ll get it to the right people: rdar://114820860

Thank you for the report. Both reports, that is, and sorry we missed the earlier one.

I believe there are two separate problems here. The dyld error on 10.13 is due to the runtime not being present on that OS. Xcode will copy the back-deployment runtime into a .app, but if you’re building a bare executable, there’s no place to put it. You can install this to allow bare Swift executables to work: https://support.apple.com/kb/DL1998?locale=en_US

The crash on 10.14.6 looks like a codegen problem. I was able to reproduce it here with your example. I’m fairly ignorant of compiler matters but I’ll be sure this gets attention from the right folks.

I’ve filed a matching issue internally: rdar://114699006.

Same bug here with Xcode 15.2/15.3 - app crashing on customer systems with 10.13 and 10.14 due to SwiftUI being referenced.

The app uses AppKit, Obj-C, and Swift. No SwiftUI whatsoever. Referenced nowhere, imported nowhere, nothing in the build log… Still it’s randomly referenced in the binary according to otool -L

The asset symbol workaround appears to work - so far…

I can confirm that it still happens with Xcode 15.0. I got alerted after receiving a negative review for my App Store app after publishing an update built with Xcode 15.0, which I thought still supported macOS 10.13. Why does it take so long to fix this issue?

I believe there are two separate problems here. The dyld error on 10.13 is due to the runtime not being present on that OS. Xcode will copy the back-deployment runtime into a .app, but if you’re building a bare executable, there’s no place to put it. You can install this to allow bare Swift executables to work: https://support.apple.com/kb/DL1998?locale=en_US

Unfortunately the linker errors occur on 10.13 even with an .app, although it is a little different. On 10.13 with an app, I get:

dyld: Library not loaded: @rpath/libswiftAppKit.dylib
  Referenced from: /Users/_redacted_/Desktop/test.app/Contents/MacOS/test
  Reason: Incompatible library version: test requires version 45.0.0 or later, but libswiftAppKit.dylib provides version 1.0.0
Abort trap: 6

I’m attaching the Xcode project for the test app, although there’s nothing special about it—it’s just a stock app built for 10.13.

test.zip