Skip to content

Add some utility functions for obtaining runtime-relative paths. #62462

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

Closed
wants to merge 8 commits into from

Conversation

al45tair
Copy link
Contributor

@al45tair al45tair commented Dec 8, 2022

Adds the ability to locate files relative to the path of the Swift runtime library, libswiftCore.

rdar://103071801

@al45tair
Copy link
Contributor Author

al45tair commented Dec 8, 2022

@swift-ci Please smoke test

@al45tair al45tair requested review from mikeash and compnerd December 8, 2022 17:52
@al45tair al45tair force-pushed the eng/PR-103071801 branch 3 times, most recently from d07e570 to 7d651d5 Compare December 12, 2022 22:27
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair al45tair force-pushed the eng/PR-103071801 branch 2 times, most recently from 91e1769 to b9f513b Compare December 15, 2022 11:40
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair al45tair force-pushed the eng/PR-103071801 branch 2 times, most recently from 7f1461b to 84058ea Compare December 16, 2022 13:58
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test Windows platform

@al45tair
Copy link
Contributor Author

al45tair commented Jan 3, 2023

@swift-ci Please smoke test

@al45tair
Copy link
Contributor Author

al45tair commented Jan 3, 2023

@swift-ci Please smoke test

@al45tair al45tair force-pushed the eng/PR-103071801 branch 2 times, most recently from a33eaeb to 1529320 Compare January 12, 2023 16:33
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Adds the ability to locate files relative to the path of the Swift runtime
library, libswiftCore.

rdar://103071801
The path to the runtime should be something like

  /usr/lib/swift/libswiftCore.dylib

So we want to strip lib/swift/ off to get the Swift root.

We also want auxiliary executables in

  /usr/libexec/swift

rather than just

  /usr/libexec

(While still supporting flat layout for Windows.)

rdar://103071801
Apparently the `swiftCore.lib` file is in `%target-sdk-name/%target-arch`
within the build directory.

rdar://103071801
Windows doesn't have a "lib" prefix on the Swift DLLs.

rdar://103071801
GetMappedFilenameW() returns an NT-style path, not a Win32 path, but
we need a Win32 path.

rdar://103071801
On Windows, swift_getRootPath() should return the root path (i.e. outside
the "bin" directory).

On Linux, the path for the runtime looks like
<swift-root>/lib/swift/linux/libswiftCore.so
rather than <swift-root>/lib/swift/libswiftCore.so as you might expect.

On macOS, the path for the runtime *can* have "macosx" in it if we're using the
library from the build path.  That's not how it gets installed when it's part of
the operating system, but it's how we build it.

Also make swift_getAuxiliaryExecutablePath() actually check that the executable
exists.  This does mean it can return nullptr now, but it also means that it
can search through the various locations it supports to try to find the file
you're after, which is more robust.

rdar://103071801
Change _swift_initRootPath() to do an early return, which reduces indentation.

Add a comment to reinforce that we can't use GetFinalPathNameByHandle() in
_swift_initRuntimePath().

rdar://103071801
It turns out that the path to the runtime might also include the
architecture as well as the platform.  So we need to search

  <root>/lib/swift/<platform>
  <root>/lib/swift/<platform>/<arch>
  <root>/lib/swift
  <root>/lib/swift/<arch>
  <root>/bin/
  <root>/bin/<arch>
  <root>

in that order.

Hopefully this now covers all the possibilities.

rdar://103071801
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair
Copy link
Contributor Author

This is going to be replaced by al45tair#8 (part of the PR stack for the initial drop of the backtracing work).

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.

4 participants