New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swift script importing Cocoa frameworks (Cocoa, AppKit, CryptoKit) fails with Symbols not found (macOS 14) #68785
Comments
+1 - Sonoma has bricked my lil' command line scripts I was using fine on Ventura Except with swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
|
Also works as expected from REPL:
|
That command is invoking the Swift compiler and instead of running the script directly using the Based on my experience, this issue still exists. Hopefully someone from Apple will see this and provide a fix real soon. 🤞 🙏 |
I have many similar little scripts that fail from importing Cocoa. Started off as an easy way to get familiar with the language. Now that they're failing, I realize I relied on them a LOT! |
I have the same problem when script is using |
I am also experiencing this issue.
|
I am also seeing this issue when trying to import Core Data in a script that has worked for years. Since this may be a macOS / Swift integration issue and not a pure Swift issue, I have filed a Feedback with Apple: |
@rdj Would you be able to add the 'regression' tag to this issue? Hopefully that would help raise its visibility. |
@dempseyatgithub Nope, I think tagging issues is a privileged op. I'm just a random internet person with no special powers. |
This appears to be indirectly related to libswiftAppKit code being merged back into AppKit. Before that SDK change, we would autolink libswiftAppKit. That caused us to do:
that succeeds, and it pulls in AppKit.framework as a dependency. On 14.0 and later, we autolink AppKit.framework not the overlay dylib, and call
which fails. I think the right fix would be for us to actually use the path As an aside, after the SDK change we needed the following e759007 so that running on macOS < 14.0 but building against a 14+ SDK we get the right behaviour. But that's not directly relevant here. |
I found a workaround. If you manually set the system framework search path, everything works:
|
@Savjee Hm, that does not seem to work for all use cases. I have a script that imports Invoking it using
|
…times. Add DYLD_FRAMEWORK_PATH=/System/Library/Frameworks to the environment when constructing swift-frontend invocations for the interpreter so that dlopen can find autolinked frameworks. This is intended to fix #68785. As a follow-up: don't expand runtime paths to find the path to the runtime in libImmediate, but instead hard-code "/usr/lib/swift/libswiftCore.dylib" and allow any overrides to be found via DYLD_LIBRARY_PATH (this ensures that dyld treats whichever libswiftCore.dylib is found as override for the one in the shared cache, which doesn't happen if dlopen is passed a non-standard path).
@lhames So should just setting the environment have the same effect, cause it does not resolve the repro from the original bug:
|
@rdj I've been testing on top-of-tree. It's possible that there's something else going on on 5.9. Could you try running |
Hmm, no effect. Judging from Ok, I can get it to listen to the DYLD vars by invoking the xcode-installed
Oddly, it does not work through
Thank, @lhames, it does seem like this will fix the top-post repro on this issue. |
So for others on the thread, a workaround — if you have xcode installed — is to change your shebang line:
|
@rdj thank you for this! 🙌🏼 Confirmed it works for me. |
This line was accidentally dropped from 06384be, which also contained a related fix to libImmediate (see that commit for details). Resolves: apple#68785
This line was accidentally dropped from 06384be, which also contained a related fix to libImmediate (see that commit for details). Resolves: apple#68785
…times. Add DYLD_FRAMEWORK_PATH=/System/Library/Frameworks to the environment when constructing swift-frontend invocations for the interpreter so that dlopen can find autolinked frameworks. This is intended to fix apple#68785. As a follow-up: don't expand runtime paths to find the path to the runtime in libImmediate, but instead hard-code "/usr/lib/swift/libswiftCore.dylib" and allow any overrides to be found via DYLD_LIBRARY_PATH (this ensures that dyld treats whichever libswiftCore.dylib is found as override for the one in the shared cache, which doesn't happen if dlopen is passed a non-standard path).
This line was accidentally dropped from 06384be, which also contained a related fix to libImmediate (see that commit for details). Resolves: apple#68785
Description
Swift script that imports AppKit fails with "JIT session error: Symbols not found".
By "swift script" I mean a swift source file that is run directly with
/usr/bin/swift
,xcrun swift
, or as an executable script with a shebang line like#!/usr/bin/env swift
.Using
swiftc
on the same source file compiles cleanly and the executable works as expected.Steps to reproduce
Expected behavior
Should work when run directly with
swift
or as an executable with#!/usr/bin/env swift
.Environment
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
Xcode 15.0
Build version 15A240d
Related Issues
Similar to #59354
The text was updated successfully, but these errors were encountered: