Skip to content

Swift script importing Cocoa frameworks (Cocoa, AppKit, CryptoKit) fails with Symbols not found (macOS 14) #68785

@rdj

Description

@rdj

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

 $ printf 'import AppKit\n\nprint( NSScreen.main!.frame.size )' > a.swift && swift a.swift
JIT session error: Symbols not found: [ _OBJC_CLASS_$_NSScreen ]
Failed to materialize symbols: { (main, { _$sSoMXM, __swift_FORCE_LOAD_$_swiftDarwin_$_a, __swift_FORCE_LOAD_$_swiftObjectiveC_$_a, __swift_FORCE_LOAD_$_swiftDispatch_$_a, __swift_FORCE_LOAD_$_swiftXPC_$_a, _$ss5print_9separator10terminatoryypd_S2StFfA0_, _$ss27_finalizeUninitializedArrayySayxGABnlF, _got.$s12CoreGraphics7CGFloatVMn, __swift_FORCE_LOAD_$_swiftos_$_a, _symbolic _____ So6CGSizeV, _symbolic _____ 12CoreGraphics7CGFloatV, _$ss5print_9separator10terminatoryypd_S2StFfA1_, _$sSo6CGSizeVwst, __swift_FORCE_LOAD_$_swiftCoreImage_$_a, _$sSa12_endMutationyyF, __swift_FORCE_LOAD_$_swiftCoreGraphics_$_a, _$sSo6CGSizeVMF, $.a.__inits.0, __swift_FORCE_LOAD_$_swiftQuartzCore_$_a, __swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_a, __swift_FORCE_LOAD_$_swiftMetal_$_a, _$sSo6CGSizeVMn, _$sSo6CGSizeVMf, __swift_FORCE_LOAD_$_swiftCoreFoundation_$_a, _$sSo6CGSizeVML, _$sSo6CGSizeVMB, __swift_FORCE_LOAD_$_swiftFoundation_$_a, _main, _$sSo6CGSizeVwet, _$sSo6CGSizeVMa, __swift_FORCE_LOAD_$_swiftOSLog_$_a, _$sSo6CGSizeVWV, ___swift_noop_void_return, ___swift_memcpy16_8, __swift_FORCE_LOAD_$_swiftIOKit_$_a }) }

 $ swiftc a.swift && ./a
(2560.0, 1440.0)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.regressionswift 5.9triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions