Skip to content

[Swift REPL] Inherit the environment for the Swift REPL #9859

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
Jan 21, 2025

Conversation

JDevlieghere
Copy link

The Swift REPL was had rolling the ProcessLaunchInfo instead of using the one already setup by the target. While populating the launch info, it used Target::GetTargetEnvironment() which only looks at the corresponding setting, and ignoring the inherit-environment setting. The alternative of calling Target::GetInheritedEnvironment is also wrong, because that has the inverse problem: it only inherits the environment and doesn't merge it with the target's environment variables. The solution is to use Target::GetProcessLaunchInfo which populates the launch info correctly.

Propagating the environment correctly is particularly important on Windows where Path needs to be passed to the inferior to allow LoadLibraryW(L"swiftCore.dll") to succeed. Without this patch, the library is not found and the inferior exits terminating the REPL instance.

rdar://137522456
(cherry picked from commit 79d7505)

The Swift REPL was had rolling the ProcessLaunchInfo instead of using
the one already setup by the target. While populating the launch info,
it used `Target::GetTargetEnvironment()` which only looks at the
corresponding setting, and ignoring the `inherit-environment` setting.
The alternative of calling `Target::GetInheritedEnvironment` is also
wrong, because that has the inverse problem: it only inherits the
environment and doesn't merge it with the target's environment
variables. The solution is to use `Target::GetProcessLaunchInfo` which
populates the launch info correctly.

Propagating the environment correctly is particularly important on
Windows where `Path` needs to be passed to the inferior to allow
`LoadLibraryW(L"swiftCore.dll")` to succeed. Without this patch, the
library is not found and the inferior exits terminating the REPL
instance.

- Fixes: llvm#9551
- Will fix swiftlang/swift#76702 and swiftlang/swift#70005 with a
  corresponding driver change to set `inherit-environment` when invoking
  the REPL.

rdar://137522456
(cherry picked from commit 79d7505)
@JDevlieghere JDevlieghere merged commit 6aecf56 into next Jan 21, 2025
@JDevlieghere JDevlieghere deleted the rdar143212617 branch January 21, 2025 18:01
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.

Reports false positive REPL does not work in 6.0.0 release on Windows
1 participant