macOS: Toolchains are not installed in SWIFTLY_HOME_DIR
After installing the pkg to bootstrap from, setting both SWIFTLY_BIN_DIR and SWIFTLY_HOME_DIR does not impact where toolchains are installed.
(venv) andrew@Andrews-MacBook-Pro-2:~/Source/test/swiftly-install$ SWIFTLY_BIN_DIR=$PWD/bin SWIFTLY_HOME_DIR=$PWD/share ~/.swiftly/bin/swiftly init --no-modify-profile --quiet-shell-followup
Swiftly will be installed into the following locations:
/Users/andrew/Source/test/swiftly-install/share - Data and configuration files directory including toolchains
/Users/andrew/Source/test/swiftly-install/bin - Executables installation directory
These locations can be changed with SWIFTLY_HOME_DIR and SWIFTLY_BIN_DIR environment variables and run this again.
Once swiftly is installed it will install the latest available swift toolchain.
Proceed? (Y/n):
y
Installing swiftly in /Users/andrew/Source/test/swiftly-install/bin/swiftly...
Creating shell environment file for the user...
The initial toolchain was already installed by a previous "init" call, but installing a new toolchain still doesn't put it in my set SWIFTLY_HOME_DIR.
(venv) andrew@Andrews-MacBook-Pro-2:~/Source/test/swiftly-install$ SWIFTLY_BIN_DIR=$PWD/bin SWIFTLY_HOME_DIR=$PWD/share ./bin/swiftly install main-snapshot-2025-03-25
Installing main-snapshot-2025-03-25
Downloading main-snapshot-2025-03-25
100% [================================================================================================================]
Downloaded 1616.8 MiB of 1616.8 MiB
Installing package in user home directory...
The global default toolchain has been set to `main-snapshot-2025-03-25`
main-snapshot-2025-03-25 installed successfully!
NOTE: We have updated some elements in your path and your shell may not yet be
aware of the changes. You can run this command to update your shell.
hash -r
(venv) andrew@Andrews-MacBook-Pro-2:~/Source/test/swiftly-install$ ls share
config.json env.sh
(venv) andrew@Andrews-MacBook-Pro-2:~/Source/test/swiftly-install$ cat share/env.sh
export SWIFTLY_HOME_DIR="/Users/andrew/Source/test/swiftly-install/share"
export SWIFTLY_BIN_DIR="/Users/andrew/Source/test/swiftly-install/bin"
if [[ ":$PATH:" != *":$SWIFTLY_BIN_DIR:"* ]]; then
export PATH="$SWIFTLY_BIN_DIR:$PATH"
fi
Seems like they're placed in /Users/andrew/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-03-25-a.xctoolchain instead?
These env vars control where Swiftly itself is configured/installed, not where toolchains are stored. Toolchain locations vary between Linux and macOS. For macOS they're installed in Library/Developer/Toolchains, while Linux installs them to ~/.local/share/swiftly/toolchains, or $XDG_DATA_HOME/toolchains if $XDG_DATA_HOME is set.
Really? That's strange. I was expecting there to be an environment variable to control where toolchains are installed no matter what platform I'm installing on, similar to RUSTUP_HOME
The macOS toolchains are offered in the .pkg installer format on swift.org and typically, people would install them in the root volume under /Library/Developer/Toolchains. Since swiftly is a user-level toolchain manager, it installs them in the current user's home directory volume, so they go under the same location, but relative to the user's home directory, so ~/Library/Developer/Toolchains. Putting the toolchains in a standard location also means that tools like Xcode can find them.
There is an effort to make the initial prompt screen much more transparent in PR #273
Since swiftly is a user-level toolchain manager, it installs them in the current user's home directory volume, so they go under the same location, but relative to the user's home directory, so ~/Library/Developer/Toolchains.
I would prefer if swiftly were treated as a "Developer toolchain manager", rather than a "user-level toolchain manager", personally. Not having full control over where files are installed and downloaded is unfortunate.
If my home directory starts filling up, and I want to install toolchains on a fast external drive, this limitation of swiftly would prevent that. I also dislike global programming language toolchain state, and would prefer to segregate toolchains per project as much as possible. If I could guarantee that all toolchain files were installed in a location I specified, I could make my builds at least feel more hermetic by placing my toolchain under MyProject/Toolchains/Local/swift or some such.
I don't see swiftly as an application to install, but as a command line tool to abstract away complications of downloading and managing extra toolchains. Having a GUI installer to drop one file in my home directory just so I can run the init command in my terminal provides no value to me 🤷 .
There's been some developments in this area. The toolchain directory can be specified with the SWIFTLY_TOOLCHAINS_DIR on both macOS and Linux after #326 is released. Also, the swiftly pkg can be extracted in an arbitrary location with some details in https://github.com/swiftlang/swiftly/issues/323#issuecomment-2815422795