From 5689d020c98da3129bc49c9af1f5d74591538c85 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 16 Aug 2025 17:47:21 -0400 Subject: [PATCH 1/8] Use a curlbash script for installing swiftly --- _data/new-data/install/linux/releases.yml | 15 +-------- _data/new-data/install/macos/releases.yml | 15 +-------- install/linux/index.md | 2 +- install/macos/index.md | 2 +- swiftly-install | 38 +++++++++++++++++++++++ 5 files changed, 42 insertions(+), 30 deletions(-) create mode 100755 swiftly-install 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..42fdd696f --- /dev/null +++ b/swiftly-install @@ -0,0 +1,38 @@ +#!/bin/bash -e +# Install script for Swiftly +# Usage: curl -fsSL https://swift.org/swiftly-install | sh +OS_NAME=$(uname -s) +OS_ARCH=$(uname -m) +TMPDIR=$(mktemp -d) + +cd ${TMPDIR} + +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 + From e8a53596fb47eb1d96959d90c2227fa4debaaaba Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 16 Aug 2025 20:49:36 -0400 Subject: [PATCH 2/8] Add header to swiftly-install script to satisfy soundness.sh --- swiftly-install | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/swiftly-install b/swiftly-install index 42fdd696f..61062709e 100755 --- a/swiftly-install +++ b/swiftly-install @@ -1,4 +1,18 @@ -#!/bin/bash -e +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## 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 +## +##===----------------------------------------------------------------------===## + # Install script for Swiftly # Usage: curl -fsSL https://swift.org/swiftly-install | sh OS_NAME=$(uname -s) From f4a9338e850b79ed6288dfa425f0577efa8f00f5 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 16 Aug 2025 23:26:23 -0400 Subject: [PATCH 3/8] Use /bin/sh for maximum portability --- swiftly-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swiftly-install b/swiftly-install index 61062709e..7a10647b5 100755 --- a/swiftly-install +++ b/swiftly-install @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ##===----------------------------------------------------------------------===## ## ## This source file is part of the Swift.org open source project From 9b36b3e433816b41d64c9678a6594db45571a0d1 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sun, 17 Aug 2025 09:52:58 -0400 Subject: [PATCH 4/8] Update swiftly-install Co-authored-by: Jake Petroules --- swiftly-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swiftly-install b/swiftly-install index 7a10647b5..64bd04c09 100755 --- a/swiftly-install +++ b/swiftly-install @@ -12,7 +12,7 @@ ## SPDX-License-Identifier: Apache-2.0 ## ##===----------------------------------------------------------------------===## - +set -eu # Install script for Swiftly # Usage: curl -fsSL https://swift.org/swiftly-install | sh OS_NAME=$(uname -s) From 62c93ee0801758157717f463c3539901482f5618 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sun, 17 Aug 2025 09:53:07 -0400 Subject: [PATCH 5/8] Update swiftly-install Co-authored-by: Jake Petroules --- swiftly-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swiftly-install b/swiftly-install index 64bd04c09..903b01720 100755 --- a/swiftly-install +++ b/swiftly-install @@ -19,7 +19,7 @@ OS_NAME=$(uname -s) OS_ARCH=$(uname -m) TMPDIR=$(mktemp -d) -cd ${TMPDIR} +cd "${TMPDIR}" case "$OS_NAME" in "Linux") From 42653b54e1ec3db0948224bdf978728a3f864f2e Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sun, 17 Aug 2025 09:53:17 -0400 Subject: [PATCH 6/8] Update swiftly-install Co-authored-by: Jake Petroules --- swiftly-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swiftly-install b/swiftly-install index 903b01720..3acda7a1d 100755 --- a/swiftly-install +++ b/swiftly-install @@ -23,7 +23,7 @@ cd "${TMPDIR}" case "$OS_NAME" in "Linux") - curl -fsSLO https://download.swift.org/swiftly/linux/swiftly-${OS_ARCH}.tar.gz + 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} From fe5af9dbc572b2ed97a3ce557d685cf9b9d85b3f Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sun, 17 Aug 2025 09:53:25 -0400 Subject: [PATCH 7/8] Update swiftly-install Co-authored-by: Jake Petroules --- swiftly-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swiftly-install b/swiftly-install index 3acda7a1d..8b6ddd5b0 100755 --- a/swiftly-install +++ b/swiftly-install @@ -24,7 +24,7 @@ cd "${TMPDIR}" 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 + tar zxf "swiftly-${OS_ARCH}.tar.gz" ./swiftly init SWIFTLY_HOME_DIR=${SWIFTLY_HOME_DIR:-$HOME/.swiftly} ;; From 6b83669c3cede51f4073c73a58627e38f7e81459 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sun, 17 Aug 2025 09:55:17 -0400 Subject: [PATCH 8/8] Check for existence of curl, ps, and tar before running script --- swiftly-install | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/swiftly-install b/swiftly-install index 8b6ddd5b0..14fe069dd 100755 --- a/swiftly-install +++ b/swiftly-install @@ -15,11 +15,17 @@ 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) -TMPDIR=$(mktemp -d) +TEMP_DIR=$(mktemp -d) -cd "${TMPDIR}" +cd "${TEMP_DIR}" case "$OS_NAME" in "Linux")