Package plugins cannot open libFoundation.so

I am trying to use the new package plugins feature in the latest swift-DEVELOPMENT-SNAPSHOT-2021-04-18-a-ubuntu20.04 toolchain, and i am running into the following issue whenever i try to set up a minimal example package with a package plugin:

$ SWIFTPM_ENABLE_PLUGINS=1 swift build

.build/plugins/cache/compiled-plugin: 
    error while loading shared libraries: libFoundation.so: cannot 
    open shared object file: No such file or directory

this issue didn’t happen with the older 2021-03-07-a snapshot, and packages that import Foundation with no package plugins build successfully with 2021-04-18-a. anyone know how to fix this?

found the problem, in the usr/lib/swift/pm/libPackagePlugin.so binary, the RUNPATH is set to

$ readelf -d usr/lib/swift/pm/libPackagePlugin.so

...
 0x0000000000000001 (NEEDED)     Shared library: [libFoundation.so]
...
 0x000000000000001d (RUNPATH)    Library runpath: [$ORIGIN/../../linux]

but the correct runpath for the folder structure of the nightly toolchains should be one directory lower, so changing it to

...
 0x0000000000000001 (NEEDED)     Shared library: [libFoundation.so]
...
 0x000000000000001d (RUNPATH)    Library runpath: [$ORIGIN/../linux]

makes the package plugins work.

bug filed here: https://bugs.swift.org/browse/SR-14521

I don't think so, because at test time in the build root, libXCTest.so is not adjacent to libFoundation.so , so $ORIGIN won't work.

If, however, we move to a toolchain based development model where XCTest is built against a synthesized toolchain, and it also installs libXCTest.so into that so that the built toolchain looks like an installed one, then I think we can get rid of it.

Terms of Service

Privacy Policy

Cookie Policy