swift-package-manager: [SR-14008] "Library not loaded: /usr/lib/swift/libswift_Differentiation.dylib" issue for `swift test`
Previous ID | SR-14008 |
Radar | None |
Original Reporter | @dan-zheng |
Type | Bug |
Attachment: Download
Environment
Apple Swift version 5.3-dev (LLVM bcee1b98f3b26c5, Swift dbcf7fe1bf76226)
Target: x86_64-apple-darwin19.6.0
Additional Detail from JIRA
Votes | 2 |
Component/s | Package Manager |
Labels | Bug, AutoDiff |
Assignee | None |
Priority | Medium |
md5: 4ecdf44eee77ebefd73035c76ce61be5
Issue Description:
With development snapshot toolchains, swift build
/swift run
for executable/library targets importing _Differentiation
has no problem.
However, running swift test
for test targets importing _Differentiation
fails with a dynamic linker issue:
$ swift test
[7/7] Linking SwiftDifferentiationPackageTests
* Build Completed!
2020-12-30 14:28:23.465 xctest[20739:26994456] The bundle “SwiftDifferentiationPackageTests.xctest” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2020-12-30 14:28:23.465 xctest[20739:26994456] (dlopen_preflight(/Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests): Library not loaded: /usr/lib/swift/libswift_Differentiation.dylib
Referenced from: /Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests
Reason: image not found)
Setting DYLD_LIBRARY_PATH
to the toolchain library directory containing libswift_Differentiation.dylib
does not help:
$ DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-12-23-a.xctoolchain/usr/lib/swift/macosx swift test
2020-12-30 14:29:55.586 xctest[20925:26997481] The bundle “SwiftDifferentiationPackageTests.xctest” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2020-12-30 14:29:55.586 xctest[20925:26997481] (dlopen_preflight(/Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests): Library not loaded: /usr/lib/swift/libswift_Differentiation.dylib
Referenced from: /Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests
Reason: image not found)
However, manually invoking the xctest
command from swift test -v
with DYLD_LIBRARY_PATH
does work:
$ DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-12-23-a.xctoolchain/usr/lib/swift/macosx /Applications/Xcode-beta12_3.app/Contents/Developer/usr/bin/xctest /Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest
Test Suite 'All tests' started at 2020-12-30 14:35:43.472
Test Suite 'SwiftDifferentiationPackageTests.xctest' started at 2020-12-30 14:35:43.473
Test Suite 'DifferentiationTests' started at 2020-12-30 14:35:43.473
Test Case '-[DifferentiationTests.DifferentiationTests testExample]' started.
Test Case '-[DifferentiationTests.DifferentiationTests testExample]' passed (0.112 seconds).
Test Suite 'DifferentiationTests' passed at 2020-12-30 14:35:43.585.
Executed 1 test, with 0 failures (0 unexpected) in 0.112 (0.112) seconds
Test Suite 'SwiftDifferentiationPackageTests.xctest' passed at 2020-12-30 14:35:43.585.
Executed 1 test, with 0 failures (0 unexpected) in 0.112 (0.112) seconds
Test Suite 'All tests' passed at 2020-12-30 14:35:43.585.
Executed 1 test, with 0 failures (0 unexpected) in 0.112 (0.113) seconds
Maybe this is because swift test
does not pass the DYLD_LIBRARY_PATH
environment variable to the xctest
invocation?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 34 (13 by maintainers)
That error is present on trunk snapshots, but not on 5.7 branch snapshots. For example, the 2022-05-04 and 2022-06-08 trunk snapshots produce the concurrency error. The 2022-06-04 v5.7 and 2022-06-13 v5.7 snapshots do not. I was building the package using the June 13, 2022 v5.7 Development Snapshot in https://github.com/apple/swift-package-manager/issues/4454#issuecomment-1160881425. Same behavior on the June 8 trunk snapshot though.
Terminal output (before, then after adding platforms to Package.swift)
Most dylibs whose install names are under these directories do not actually exist there as separate files; instead, the dynamic loader picks them up from the system-wide dyld shared cache.