Skip to content

Add an rpath flag to disable the default of looking in the local directory for shared libraries #6947

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

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

finagolfin
Copy link
Member

This is useful when deploying build products, as most executables are not installed in the same directory as libraries and system libraries do not need it for system paths. Use the new flag when installing SwiftPM itself and the {Manifest,Plugin}API libraries on ELF platforms.

On linux, I currently see this with Swift 5.9:

> readelf -d swift-5.9-RELEASE-ubuntu20.04/usr/lib/swift/pm/*I/lib*so swift-5.9-RELEASE-ubuntu20.04/usr/bin/swift-package|ag "File:|runpath"
File: swift-5.9-RELEASE-ubuntu20.04/usr/lib/swift/pm/ManifestAPI/libPackageDescription.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:$ORIGIN/../../linux]
File: swift-5.9-RELEASE-ubuntu20.04/usr/lib/swift/pm/PluginAPI/libPackagePlugin.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:$ORIGIN/../../linux]
File: swift-5.9-RELEASE-ubuntu20.04/usr/bin/swift-package
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:$ORIGIN/../lib/swift/linux]

After applying this pull to trunk on Android, the extraneous rpath is gone:

> llvm-readelf -d build/Ninja-Release/toolchain-android-aarch64/usr/lib/swift/pm/*I/lib*so build/Ninja-Release/toolchain-android-aarch64/usr/bin/swift-package|ag "File:|runpath"
File: build/Ninja-Release/toolchain-android-aarch64/usr/lib/swift/pm/ManifestAPI/libPackageDescription.so
  0x000000000000001d (RUNPATH)      Library runpath: [$ORIGIN/../../android]
File: build/Ninja-Release/toolchain-android-aarch64/usr/lib/swift/pm/PluginAPI/libPackagePlugin.so
  0x000000000000001d (RUNPATH)      Library runpath: [$ORIGIN/../../android]
File: build/Ninja-Release/toolchain-android-aarch64/usr/bin/swift-package
  0x000000000000001d (RUNPATH)         Library runpath: [$ORIGIN/../lib/swift/android:/data/data/com.termux/files/usr/lib]

I have no idea if this is useful on Darwin too, but I went ahead and disabled adding @loader_rpath too. Let me know if that's worthwhile.


/// Disables adding $ORIGIN/@loader_path to the rpath, useful when deploying
@Flag(name: .customLong("disable-local-rpath"), help: "Disable adding $ORIGIN/@loader_path to the rpath by default")
public var shouldDisableLocalRpath: Bool = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care what the flag name is, feel free to suggest another.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call it "origin" instead of "local"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that originally but used this broader term when I disabled the Darwin @loader_path too. Do you want me to keep that disabled for Darwin and change this flag and variable name to origin? I have no preference on these two aspects of this pull.

@@ -5021,4 +5021,87 @@ final class BuildPlanTests: XCTestCase {
XCTFail("expected a Swift target")
}
}

func testBasicSwiftPackageWithoutLocalRpath() throws {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a copy and paste of testBasicSwiftPackage() above, with the rpath disabled and a few checks removed.

@finagolfin
Copy link
Member Author

@neonichu, please run the CI on this.

@neonichu
Copy link
Contributor

@swift-ci please test

…ctory for shared libraries

This is useful when deploying build products, as most executables are not installed
in the same directory as libraries and system libraries do not need it for
system paths. Use the new flag when installing SwiftPM itself and the {Manifest,Plugin}API
libraries on ELF platforms.
@finagolfin
Copy link
Member Author

Linux CI passed, while Windows CI failed spuriously.

Mac CI said it didn't find a warning diagnostic from the old test I modified, so I just updated the test to not look for that.

@finagolfin
Copy link
Member Author

@neonichu, please rerun the CI.

@finagolfin
Copy link
Member Author

@bnbarham, would you run the CI on this?

@bnbarham
Copy link
Contributor

bnbarham commented Oct 6, 2023

@swift-ci please test

@finagolfin
Copy link
Member Author

@neonichu, passed CI, ready for review.

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.

3 participants