Skip to content

[SR-14008] "Library not loaded: /usr/lib/swift/libswift_Differentiation.dylib" issue for swift test #4454

Open
@dan-zheng

Description

@dan-zheng
Previous ID SR-14008
Radar None
Original Reporter @dan-zheng
Type Bug

Attachment: Download

Environment

https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2020-12-23-a/swift-DEVELOPMENT-SNAPSHOT-2020-12-23-a-osx.pkg

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 bundleSwiftDifferentiationPackageTests.xctestcouldnt 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugswift testChanges impacting `swift test` tool

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions