Skip to content

[Windows] Build swiftly on Windows and list toolchains from Windows Installer - #619

Open
AbdAlRahmanGad wants to merge 3 commits into
swiftlang:mainfrom
AbdAlRahmanGad:windows-build
Open

AbdAlRahmanGad wants to merge 3 commits into
swiftlang:mainfrom
AbdAlRahmanGad:windows-build

Conversation

@AbdAlRahmanGad

Copy link
Copy Markdown
Member

The beginning of bringing Swiftly to Windows. See the Swift Forums proposal.

swiftly now builds and runs on Windows. The OpenAPI clients use openapi-winhttp-transport there (swift-nio-ssl doesn't compile against the Windows SDK), and installed toolchains come from Windows Installer's records of the swift.org MSIs; Linux and macOS are unchanged.

Works on Windows

  • swift build --product swiftly build Swiftly
  • swiftly init --skip-install: sets up swiftly's home directory; skips the shell profile, which Windows doesn't have
  • swiftly --version, swiftly --help
  • swiftly list: shows toolchains installed with the swift.org installer
  • swiftly list-available: fetches the release list from swift.org over WinHTTP
  • swiftly use, swiftly use <version>, swiftly use --print-location: shows or picks the in-use toolchain
    • Couldn't test picking different valid toolchain since windows doesn't support having multiple toolchains installed at once

swift-nio-ssl, which AsyncHTTPClient pulls in, doesn't compile against
the Windows SDK, so SwiftlyCore couldn't build on Windows. Keep the
same OpenAPI clients and give them openapi-winhttp-transport there,
with AsyncHTTPClient unchanged on Linux and macOS.

Each transport package is declared only on the platforms that use it:
openapi-winhttp-transport needs tools 6.4, and declaring it everywhere
would break builds with older toolchains. Resolving it moves
swift-openapi-runtime from 1.9.0 to 1.12.1.
Add a WindowsPlatform target and wire it into Swiftly.currentPlatform.
Toolchain install, lookup, signature checks and running toolchains
throw "isn't supported on Windows yet" until they go through Windows
Installer.

Give the Unix-only SwiftlyCore helpers Windows versions next to their
definitions: installSwiftlyBin does nothing (swiftly's installer puts
it in place), findSwiftlyBin returns nil (Windows proxies will be stub
executables), and proxyEnvironment throws for now.

Fix the paths that broke at runtime:
- argv[0] on Windows has backslashes and .exe, so swiftly.exe always
  took itself for a proxy. Strip both before comparing.
- TerminationStatus on Windows only has .exited(DWORD).
- Self-update throws instead of hitting fatalError or picking the Linux
  download.
- init no longer edits a Unix shell profile or prints a `. env.sh` hint;
  Windows has no profile to source.

Every change is a new #if branch, so Linux and macOS are unchanged.
Add Platform.discoverInstalledToolchains for platforms where something
other than swiftly's configuration records what's installed. It
returns nil by default, so Linux and macOS keep using config.json.

On Windows, the swift.org installers register each toolchain, SDK and
runtime with Windows Installer. List the products whose publisher is
swift.org, walk the components in the install contexts they use, and
identify each piece by its key file (swift.exe, SDKSettings.json,
swiftCore.dll). A CMsi shim declares the five msi.dll functions,
which don't import through the WinSDK module.

swiftly list now shows toolchains installed from swift.org, and
findToolchainLocation returns their real install folder.
@@ -0,0 +1,40 @@
#pragma once

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need this? Can we not use WinSDK to get the appropriate header pulled in?

This branch has not been deployed

No deployments
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.

2 participants