Skip to content
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

[bootstrap] Add rpath for macOS. #2692

Closed
wants to merge 1 commit into from
Closed

Conversation

dan-zheng
Copy link
Contributor

Add an extra rpath for macOS: @executable_path/../../../lib/swift/macosx.

This rpath is necessary for swiftpm-xctest-helper, which is invoked by
swift test --filter.

I believe this resolves SR-12599 and SR-12600:

$ swift test --filter blah
error: signalled(6): /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2020-04-07-a.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper /private/tmp/bug/.build/x86_64-apple-macosx/debug/bugPackageTests.xctest /var/folders/z0/4612twmx5wbfrsp0jxbcvwrm00qbwx/T/TemporaryFile.0ZEehg output:
    dyld: Library not loaded: @rpath/libswiftCore.dylib
      Referenced from: /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2020-04-07-a.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper
      Reason: image not found

I'm verifying the fix via build-toolchain now.


I believe this SwiftPM regression occurred in #2462, which revamped the bootstrap script.
Related issue: tensorflow/swift#347

Add an extra rpath for macOS: `@executable_path/../../../lib/swift/macosx`.

This rpath is necessary for swiftpm-xctest-helper, which is invoked by
`swift test --filter`.

Resolves SR-12599 and SR-12600.
@dan-zheng
Copy link
Contributor Author

@compnerd: could you please help review?

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test

@dan-zheng
Copy link
Contributor Author

@swift-ci Please smoke test

@abertelrud
Copy link
Contributor

abertelrud commented Apr 16, 2020

Thanks for the fix! It looks as if this extra rpath is being added to the link of all of the tools. Would it make sense to add that rpath to just swiftpm-xctest-helper instead?

I've been looking into something similar for replacing the use of install_name_tool to add an llbuild rpath, to make it instead pass the rpath to the linker for just swift-llbuild. For the change in this PR, would it be possible to add the rpath in Sources/swiftpm-xctest-helper/CMakeLists.txt?

Something like:

if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
    target_link_options(swiftpm-xctest-helper PRIVATE "-Xlinker -rpath -Xlinker @executable_path/../../../lib/swift/macosx")
endif()

@dan-zheng
Copy link
Contributor Author

Thanks for the fix! It looks as if this extra rpath is being added to the link of all of the tools. Would it make sense to add that rpath to just swiftpm-xctest-helper instead?

Thanks for the idea! That definitely seems preferable, if it works.
Done in #2694, testing it now.

@neonichu
Copy link
Member

I believe this can be closed now since #2785 superseded it.

@neonichu neonichu closed this Jun 25, 2020
@dan-zheng dan-zheng deleted the fix-rpaths branch June 25, 2020 21:40
@adam-rocska
Copy link

adam-rocska commented Sep 3, 2021

@dan-zheng @neonichu @abertelrud

I know this is an old dead and gone thread, but it looks like this issue's still lurking somewhere.

I've got the following on my plate right now:

MacBook-Pro:myProject rocskaadam$ swift package --version
Swift Package Manager - Swift 5.4.0
MacBook-Pro:myProject rocskaadam$ swift --version
Apple Swift version 5.4.2 (swift-5.4.2-RELEASE)
Target: x86_64-apple-darwin20.6.0
MacBook-Pro:myProject rocskaadam$ which swift
/Library/Developer/Toolchains/swift-5.4.2-RELEASE.xctoolchain/usr/bin//swift
MacBook-Pro:myProject rocskaadam$ 

but of-course, the same happens with the new'n'tasty Swift 5.5 Aug 30 snapshot, and a few older versions like 5.3
UPDATE: All my toolchains come from swift.org

When I run swift test --list-tests, I get:

MacBook-Pro:myProject rocskaadam$ swift test --list-tests
[0/0] Build complete!
error: signalled(6): /Library/Developer/Toolchains/swift-5.4.2-RELEASE.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper /Users/rocskaadam/tmp/myProject/.build/x86_64-apple-macosx/debug/myProjectPackageTests.xctest /var/folders/r1/5_y8gt9931l0084_1wxg8mw40000gn/T/TemporaryFile.w3juCp output:
    dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest
      Referenced from: /Library/Developer/Toolchains/swift-5.4.2-RELEASE.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper
      Reason: image not found

And poor swiftpm-xctest-helper is lost here, cuz' if I just randomly run it, I get:

MacBook-Pro:myProject rocskaadam$ /Library/Developer/Toolchains/swift-5.4.2-RELEASE.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper
dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest
  Referenced from: /Library/Developer/Toolchains/swift-5.4.2-RELEASE.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper
  Reason: image not found
Abort trap: 6

I've been chasing this issue for more than a week now, and I started to lose my nice long hair 😢

Can anyone give me some hope, please?

@neonichu
Copy link
Member

neonichu commented Sep 3, 2021

Do you have Xcode installed? The toolchain on macOS does not contain XCTest and requires an Xcode installation for anything involving it.

@adam-rocska
Copy link

adam-rocska commented Sep 3, 2021

@neonichu Yup, I do.

@adam-rocska
Copy link

adam-rocska commented Sep 3, 2021

And of-course export TOOLCHAINS=org.swift.542202106241a is also fine ¯\(ツ)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants