diff --git a/_data/new-data/install/linux/releases.yml b/_data/new-data/install/linux/releases.yml index 5510be1f0..f8fac7846 100644 --- a/_data/new-data/install/linux/releases.yml +++ b/_data/new-data/install/linux/releases.yml @@ -3,20 +3,7 @@ latest-release: pre-code-text: | The Swiftly installer manages Swift and its dependencies. It supports switching between different versions and downloading updates. headline: Swiftly - tabs: - - label: Bash - code: |- - curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && \ - tar zxf swiftly-$(uname -m).tar.gz && \ - ./swiftly init --quiet-shell-followup && \ - . "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh" && \ - hash -r - - label: Fish - code: |- - curl -O https://download.swift.org/swiftly/linux/swiftly-(uname -m).tar.gz && \ - tar zxf swiftly-(uname -m).tar.gz && \ - ./swiftly init --quiet-shell-followup && \ - set -q SWIFTLY_HOME_DIR && source "$SWIFTLY_HOME_DIR/env.fish" || source ~/.local/share/swiftly/env.fish + code: curl -fsSL https://swift.org/swiftly-install | sh links: - href: 'https://raw.githubusercontent.com/swiftlang/swiftly/refs/heads/main/LICENSE.txt' copy: 'License: Apache-2.0' diff --git a/_data/new-data/install/macos/releases.yml b/_data/new-data/install/macos/releases.yml index 2e79670ad..e3562ad63 100644 --- a/_data/new-data/install/macos/releases.yml +++ b/_data/new-data/install/macos/releases.yml @@ -3,20 +3,7 @@ latest-release: pre-code-text: | To download toolchains from Swift.org, use the Swiftly toolchain installer. Swift.org toolchains support Static Linux SDK, include experimental features like Embedded Swift and support for WebAssembly. headline: Swiftly - tabs: - - label: Bash - code: | - curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg && \ - installer -pkg swiftly.pkg -target CurrentUserHomeDirectory && \ - ~/.swiftly/bin/swiftly init --quiet-shell-followup && \ - . "${SWIFTLY_HOME_DIR:-$HOME/.swiftly}/env.sh" && \ - hash -r - - label: Fish - code: | - curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg && \ - installer -pkg swiftly.pkg -target CurrentUserHomeDirectory && \ - ~/.swiftly/bin/swiftly init --quiet-shell-followup && \ - set -q SWIFTLY_HOME_DIR && source "$SWIFTLY_HOME_DIR/env.fish" || source ~/.swiftly/env.fish + code: curl -fsSL https://swift.org/swiftly-install | sh links: - href: 'https://raw.githubusercontent.com/swiftlang/swiftly/refs/heads/main/LICENSE.txt' copy: 'License: Apache-2.0' diff --git a/install/linux/index.md b/install/linux/index.md index 9afddbde0..3a18e235f 100644 --- a/install/linux/index.md +++ b/install/linux/index.md @@ -8,7 +8,7 @@ title: Install Swift - Linux
- {% include new-includes/components/code-box.html with-tabs = true content = site.data.new-data.install.linux.releases.latest-release.swiftly %} + {% include new-includes/components/code-box.html content = site.data.new-data.install.linux.releases.latest-release.swiftly %}
diff --git a/install/macos/index.md b/install/macos/index.md index 09f4a1677..8185a42a6 100644 --- a/install/macos/index.md +++ b/install/macos/index.md @@ -11,7 +11,7 @@ title: Install Swift - macOS
- {% include new-includes/components/code-box.html with-tabs = true content = site.data.new-data.install.macos.releases.latest-release.swiftly%} + {% include new-includes/components/code-box.html content = site.data.new-data.install.macos.releases.latest-release.swiftly%}
diff --git a/swiftly-install b/swiftly-install new file mode 100755 index 000000000..14fe069dd --- /dev/null +++ b/swiftly-install @@ -0,0 +1,58 @@ +#!/bin/sh +##===----------------------------------------------------------------------===## +## +## This source file is part of the Swift.org open source project +## +## Copyright (c) 2025 Apple Inc. and the Swift.org project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of Swift.org project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## +set -eu +# Install script for Swiftly +# Usage: curl -fsSL https://swift.org/swiftly-install | sh + +if ! command -v curl >/dev/null 2>&1 || ! command -v ps >/dev/null 2>&1 || ! command -v tar >/dev/null 2>&1 ; then + echo "Missing one of more of the following programs: curl, ps, tar" >&2 + exit 1 +fi + +OS_NAME=$(uname -s) +OS_ARCH=$(uname -m) +TEMP_DIR=$(mktemp -d) + +cd "${TEMP_DIR}" + +case "$OS_NAME" in + "Linux") + curl -fsSLO "https://download.swift.org/swiftly/linux/swiftly-${OS_ARCH}.tar.gz" + tar zxf "swiftly-${OS_ARCH}.tar.gz" + ./swiftly init + SWIFTLY_HOME_DIR=${SWIFTLY_HOME_DIR:-$HOME/.swiftly} + ;; + "Darwin") + curl -fsSLO https://download.swift.org/swiftly/darwin/swiftly.pkg + installer -pkg swiftly.pkg -target CurrentUserHomeDirectory + ~/.swiftly/bin/swiftly init + SWIFTLY_HOME_DIR=${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly} + ;; + *) + echo "Unknown platform: $OS_NAME" + echo "This script supports Linux and Darwin/macOS only" + exit 1 + ;; +esac + +echo "Swiftly installed! Run the following command to set up your environment:" +PARENT_SHELL=$(ps -o comm= -p "$PPID") +if [ "$PARENT_SHELL" = "fish" ]; then + echo "source ${SWIFTLY_HOME_DIR}/env.fish" +else + # Not fish: assume sh-compatible (bash/zsh) + echo "source ${SWIFTLY_HOME_DIR}/env.sh" +fi +