Skip to content
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

Streamline the swiftly init process #177

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

cmcgee1024
Copy link
Member

@cmcgee1024 cmcgee1024 commented Oct 20, 2024

The init process just installs swiftly itself at the moment. Most
users will immediately install a swift toolchain, most likely the
latest available one. On Linux, there's confusing gpg messages that
most users don't need to be aware.

The init process will provide a summary of things that are going
to happen to the user's system, including the addition of GnuPG keys
on Linux, and the installation of the latest swift toolchain so that
they can agree, or abort the entire process. When the process runs
the user is given line-level and high level processes, not internal
details. Add a verbose mode for more details, such as the messages
that come from GnuPG on Linux.

Add an option to the init subcommand to allow swiftly to be
installed without the latest available swift toolchain so that
advanced users can decide how to install a toolchain themselves
after the swiftly installation.

Update the documentation with the increase in automation.

Add a design proposal for the new swiftly proxy system
…ocation

clarify the boundaries of the swiftly toolchain abstraction and elaborate on how to work around them
Change the nature of the swiftly symlinks so that they point
to the swiftly executable at install time. These do not change
when new toolchains are used. Toolchain selection happens each
time when the proxies are run. The proxies are created for a
well-known set of toolchain binaries that are constant for
a wide variety of toolchain versions and platforms.

Add support for .swift-version files for toolchain selection.
Update the use command so that it can point out which toolchain
is in use based on context, such as swift version files that are
located in the current working directory or above. The fallback
selection comes from the global default configuration's 'inUse'
setting. When querying for what's in use the global default
is shown with the "(default)" tag. If the in-use toolchain is
selected by a swift-version file the path to that file is displayed.

Provide a print location flag to the use subcommand that can print
the file path of the toolchain that is in use in the current
context.

When using a new toolchain, depending on whether a swift version
is selecting the current one, update the swift version file with
the selected toolchain version. If no swift version file can be
located, attempt to create a new one at the top of the git worktree.
If there is no git worktree, then fallback to updating the global
default in the configuration.

Provide a global default flag for the use subcommand so that only
the global default in-use toolchain is considered and not any of
the swift version files.
Provide a run command that allows arbitrary commands to be run in the context of the selected toolchain.

Provide a one-off selection mechanism with a special syntax on the run command.
With no arguments the install subcommand will install the currently
selected toolchain from the `.swift-version` files.
…swiftly install`.

Guard automatic creation of .swift-version file from `swiftly use` around a prompt overridable using an `--assume-yes`.

Minor cleanup
Fix all of the swift.org urls so that they use www.swift.org to avoid redirection
Fix symlink target selection for swiftly when it is system managed
Add support for these new platforms to swiftly, the autodetection,
the tests, and docker support.

Remove the swiftly installer portion of the code.
@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024
Copy link
Member Author

macOS tests are passing:

Test Suite 'All tests' passed at 2024-10-20 21:52:52.505.
	 Executed 67 tests, with 0 failures (0 unexpected) in 291.251 (291.260) seconds

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

Provide more verbose untarring messages in Linux behind the verbose flag
@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024 cmcgee1024 marked this pull request as ready for review November 21, 2024 15:12

```
curl -L https://swiftlang.github.io/swiftly/swiftly-install.sh | bash
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason we can't offer the script as an alternative? Removing it completely makes install Swiftly and Swift a reasonably amount more complicated as it puts the onus on the user to work out what OS and architecture they're using, which they can get wrong and make it seem like Swift doesn't work.

Additionally this makes building tooling on top of Swiftly significantly more complicated and each tool has to do the same logic of working out what system it's running on and going to find the correct binary which is a lot of duplicated work. It would be good to have that centralised in the tool.

Finally, this reduces the 'copy and paste this one line' installation for Swift that we have had up to now, making the experience on installing Swift on different systems a step back IMO compared to say rustup.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are number of ways that we're hoping to address these as we can't use a curl | bash approach.

For the regular user install workflow, the website can help to find them the most likely swiftly download candidate for their OS and architecture. More details can be found in the PR here: swiftlang/swift-org-website#830

We can also add a very short guide to help them on the next steps. Feedback is welcome on that PR.

The download for macOS brings them to the pkg installer for the easy flow. It can also be invoked headlessly on the command-line either in a system directory or the user's home directory. Details are in the docs.

Since swiftly is a Linux binary that can work on a wide variety of Linux distributions, it takes on the responsibility of Linux flavour detection, and configuration. The user needs only to untar it and run swiftly wherever it is to continue.

For automated systems, there's a document here that goes over how one would automatically install swiftly. Feedback is welcome on this document as part of a separate PR/issue: https://swiftpackageindex.com/swiftlang/swiftly/main/documentation/swiftlydocs/automated-install

Copy link
Member Author

Choose a reason for hiding this comment

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

In the slightly longer term, there is also the possibility of providing swiftly in system package managers to make this even easier. Swiftly is able to be run from a system location.

Choose a reason for hiding this comment

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

There are number of ways that we're hoping to address these as we can't use a curl | bash approach.
We can no longer use the install script for some reason? I agree with Tim that the one liner approach seems a bit more user friendly as it handles environment detection

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that in the near term the website can do much to ease the new user flow to compensate, such as making sure that they have the right executable, escape hatch to the full list of executables. The URL when it's finally decided for the website, can be made to be friendly to uname -m and uname -s. System packages of swiftly will be an accelerator as well, once they are available.

Copy link
Member

Choose a reason for hiding this comment

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

But what's the actual reason "we can't use a curl | bash approach"? I fully support the plan to offer an executable that does more work and make it possible to install without requiring a shell script, but removing it all together as an option feels like a step backwards

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

Copy link

@justice-adams-apple justice-adams-apple left a comment

Choose a reason for hiding this comment

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

I think the commit history looks like it needs to be cleaned up a bit post proxy merge


```
curl -L <trusted_location_of_swiftly> > swiftly
curl -L <location_of_swiftly_swift_org> > swiftly.tar.gz

Choose a reason for hiding this comment

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

location_of_swiftly_swift_org

Does this exist? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

It will once these website update PR's are merged with a released version of swiftly:

swiftlang/swift-org-website#828
swiftlang/swift-org-website#830


```
curl -L https://swiftlang.github.io/swiftly/swiftly-install.sh | bash

Choose a reason for hiding this comment

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

There are number of ways that we're hoping to address these as we can't use a curl | bash approach.
We can no longer use the install script for some reason? I agree with Tim that the one liner approach seems a bit more user friendly as it handles environment detection

$ swift --version

Swift version 5.8.1 (swift-5.8.1-RELEASE)
Swift version 6.0.1 (swift-6.0.1-RELEASE)

Choose a reason for hiding this comment

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

a few lines down the doc references swift build with a commend saying latest (5.8.1) toolchain, probably just want to update that comment to 6.0.1 too

Copy link
Member Author

Choose a reason for hiding this comment

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

I can raise another PR to fresh the version numbers in the documentation, or make them more version independent. Suggestions are welcome on how best to handle this problem of balancing accuracy and maintainability.

Sources/SwiftlyCore/Platform.swift Outdated Show resolved Hide resolved
return swiftlyHomeBin
}

if installSwiftly {

Choose a reason for hiding this comment

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

This is the code that installs swiftly, yeah, and it's wrapped around a single boolean which changes the purpose of this method, should it just be its own method? We would essentially have:

findSwiftlyBin
installSwiftly

Not a huge deal, just tripped me up when reviewing. Totally up to you

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I couldn't find a good abstraction, so maybe this deserves to have two similar functions beside each other for the locality of change, at least.

@cmcgee1024
Copy link
Member Author

I think the commit history looks like it needs to be cleaned up a bit post proxy merge

On this project I've tended to keep the full and ugly truth of the PR commit history because GitHub doesn't handle force pushes very well, and sometimes comments and their context gets fully lost. I try to compensate for this by most often using the squash and merge function when the PR is complete so that the main branch history is much cleaner.

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

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.

3 participants