-
Notifications
You must be signed in to change notification settings - Fork 1.4k
SR-7154: swiftpm tests fail if --debug-foundation option is used. #1544
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
Conversation
- Add a --swift-lib-dir so that tests can find libswiftSwiftOnone.so which is required by libFoundation.so - The path to the libraries in the swift build directory are passed to the test programs via the environment using LD_LIBRARY_PATH.
@@ -1052,6 +1055,9 @@ def main(): | |||
|
|||
env_cmd = ["env", "SWIFT_EXEC=" + os.path.join(bindir, "swiftc"), | |||
"SWIFTPM_BUILD_DIR=" + build_path] | |||
|
|||
if args.swift_lib_dir: | |||
env_cmd.append("LD_LIBRARY_PATH=" + args.swift_lib_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put a symlink in the fake toolchain instead of using LD_LIBRARY_PATH or that doesn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do it that way and it was the original way I had it working, however it also requires adding a symlink in Foundation's build directory as well. The other downside is that if in the future more libraries get built by the main swift repo in addition to libswiftCore.so
and libswiftSwiftOnone.so
then symlinks will also be required there.
However thinking about it, this LD_LIBRARY_PATH
could possibly be exported in the swift/utils/build-script-impl
script the same way it is setup when running TestFoundation
(see https://github.com/spevans/swift/blob/ce45ea3eeaca9a30e257be7fbe5746a67d5b2788/utils/build-script-impl#L2950) and then this change wouldnt be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have several tests in SwiftPM that build Swift packages in debug mode. I don't understand why we don't hit the same problem there. @jrose-apple said these libraries can be considered part of stdlib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it matters whether the packages that SwiftPM builds are in debug or release mode but whether the libFoundation.so
they link to is in release or debug mode. In debug mode it links to libswiftSwiftOnone.so
which it can't find in the build directories without this path.
The --debug-foundation
flag controls whether the libFoundation.so
is built in debug mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrose-apple said these libraries are required if something is being built with -Onone
and we have several test packages that are built with -Onone
. Presence of libFoundation.so shouldn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have an investigation on this behavior and why and how it affects SwiftPM tests? It is blocking Foundation adoption of @testable import
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you build with -Onone, you gain a dependency on libswiftSwiftOnoneSupport.so/.a (yes, it's silly that there are two "swift"s in there). It shouldn't have anything to do with @testable import
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a closer look tomm...
So swiftpm runs two binaries as part of its testing, The first one,
The
So it finds The second binary that is run is
This time
This time The addition of the The following could be achieved through the use of extra symlinks and this is actually the case for the loading of
Extra information about ELF library loading that may be useful: How to write shared libraries |
More options:
|
Thus far, all development on Linux that I've done has required setting a correct LD_LIBRARY_PATH. Is it something that we don't want to have to occur? |
@spevans Thanks for the detailed analysis. I like @jrose-apple's first suggestion about Foundation getting rpath to swift stdlibs when its built with |
@millenomi If I remember correctly, |
I reworked this by simply passing an
This also means that this PR is not now required as it can all be done in I think the issue with adding in runpaths into the libraries is that it makes the build process more complicated and will cause issues if not properly removed. Debugging is also made more complicated as this is now a non-obvious path added into the linking, as opposed to an explicit @millenomi I do have one question with the |
I still don't think we should use |
Note that we don't want to provide an rpath for release builds, because we might make toolchains out of those and ship them to people. |
Ive done an |
Add a --swift-lib-dir so that tests can find libswiftSwiftOnone.so
which is required by libFoundation.so
The path to the libraries in the swift build directory are passed
to the test programs via the environment using LD_LIBRARY_PATH.
When testing using
./utils/build-script -R -T --llbuild --swiftpm --xctest --debug-foundation -- --reconfigure --lit-args=-v
to build a debug version of Foundation, thelibFoundation.so
in the Foundation build directory is linked tolibswiftSwiftOnone.so
in the swift build directory. HoweverlibFoundation.so
cannot findlibswiftSwiftOnone.so
in its defaultRUNPATH
. This adds anLD_LIBRARY_PATH
to the environment so thatlibswiftSwiftOnone.so
can be found ok.This PR works in conjunction with swiftlang/swift#15498 for swift's main build script so it can pass the directory.