Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Swift Support (#364)
Browse files Browse the repository at this point in the history
* Add Swift Dependencies

* Add Swift Version parameter to start image

* Add Swift Version to test-build

* Swift install

* Swift Env Vars Correction

* Remove extra quote mark

* Temporarily skip verification of Swift

* Reinstated GPG Swift checks

* Removed Swift keys from apt-key stages

* Unsilencing cURL

* SPM/Swift Caching

* Minor Swift changes

* Swift cachability

* Remove SWIFT_VERSION parameter

* Added Swiftenv

* Use Swiftenv as part of build

* Swiftenv fixes

* Added Swift to included software docs

* Used skip if installed swiftenv parameter

* Extracted out Docker Swift version to its own env variable

* Removed extra space from run build script

* Rehash cached Swift build

* Removed unnecessary clang dependency

* Renamed env variable to NETLIFY_BUILD_SWIFT_VERSION, to be consistent with Node

* Swift 5.2 update

* Document that versions of Swift 4.x and older will not run

Co-authored-by: Benaiah Mischenko <[email protected]>
  • Loading branch information
SimonRice and Benaiah authored Apr 24, 2020
1 parent 3a3e63f commit 1c486be
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,21 @@ ENV PATH "$PATH:/opt/buildhome/.dotnet"
ENV DOTNET_ROOT "/opt/buildhome/.dotnet"
#populate local package cache
RUN dotnet new


################################################################################
#
# Swift
#
################################################################################
USER buildbot
ENV NETLIFY_BUILD_SWIFT_VERSION 5.2
ENV SWIFTENV_ROOT "/opt/buildhome/.swiftenv"
RUN git clone --depth 1 https://github.com/kylef/swiftenv.git "$SWIFTENV_ROOT"
ENV PATH "$SWIFTENV_ROOT/bin:$SWIFTENV_ROOT/shims:$PATH"
RUN swiftenv install ${NETLIFY_BUILD_SWIFT_VERSION}
RUN swift --version

WORKDIR /

# Cleanup
Expand Down
3 changes: 3 additions & 0 deletions included_software.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ The specific patch versions included will depend on when the image was last buil
* 7.4
* Go - `GO_VERSION`
* 1.12 (default)
* Swift - `SWIFT_VERSION`, `.swift-version`
* 5.2 (default)
* Any version that `swiftenv` can install newer than `4.x`. Versions `4.x` and below will not work due to incompatible shared libraries.
* Java
* 8 (default)
* Emacs
Expand Down
63 changes: 62 additions & 1 deletion run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export GIMME_CGO_ENABLED=true

export NVM_DIR="$HOME/.nvm"
export RVM_DIR="$HOME/.rvm"
export SWIFTENV_ROOT="${SWIFTENV_ROOT:-${HOME}/.swiftenv}"

# Pipenv configuration
export PIPENV_RUNTIME=2.7
Expand All @@ -32,13 +33,15 @@ NC="\033[0m" # No Color
# language versions
mkdir -p $NETLIFY_CACHE_DIR/node_version
mkdir -p $NETLIFY_CACHE_DIR/ruby_version
mkdir -p $NETLIFY_CACHE_DIR/swift_version

# pwd caches
mkdir -p $NETLIFY_CACHE_DIR/node_modules
mkdir -p $NETLIFY_CACHE_DIR/.bundle
mkdir -p $NETLIFY_CACHE_DIR/bower_components
mkdir -p $NETLIFY_CACHE_DIR/.venv
mkdir -p $NETLIFY_CACHE_DIR/wapm_packages
mkdir -p $NETLIFY_CACHE_DIR/.build

# HOME caches
mkdir -p $NETLIFY_CACHE_DIR/.yarn_cache
Expand Down Expand Up @@ -162,6 +165,7 @@ install_dependencies() {
local defaultYarnVersion=$3
local defaultPHPVersion=$4
local installGoVersion=$5
local defaultSwiftVersion=$6

# Python Version
if [ -f runtime.txt ]
Expand Down Expand Up @@ -401,6 +405,48 @@ install_dependencies() {
fi
fi

# Swift Version
: ${SWIFT_VERSION="$defaultSwiftVersion"}
if [ -f .swift-version ]
then
SWIFT_VERSION=$(cat .swift-version)
echo "Attempting Swift version '$SWIFT_VERSION' from .swift-version"
fi

swiftenv global ${SWIFT_VERSION} > /dev/null 2>&1
export CUSTOM_SWIFT=$?

if [ -d $NETLIFY_CACHE_DIR/swift_version/$SWIFT_VERSION ]
then
echo "Started restoring cached Swift version"
rm -rf $SWIFTENV_ROOT/versions/$SWIFT_VERSION
cp -p -r $NETLIFY_CACHE_DIR/swift_version/${SWIFT_VERSION} $SWIFTENV_ROOT/versions/
swiftenv rehash
echo "Finished restoring cached Swift version"
fi

if swiftenv install -s $SWIFT_VERSION
then
echo "Using Swift version $SWIFT_VERSION"
else
echo "Failed to install Swift version '$SWIFT_VERSION'"
exit 1
fi

# SPM dependencies
if [ -f Package.swift ]
then
echo "Building Swift Package"
restore_cwd_cache ".build" "swift build"
if swift build
then
echo "Swift package Built"
else
echo "Error building Swift package"
exit 1
fi
fi

# NPM Dependencies
: ${YARN_VERSION="$defaultYarnVersion"}

Expand Down Expand Up @@ -627,7 +673,8 @@ cache_artifacts() {
cache_cwd_directory "bower_components" "bower components"
cache_cwd_directory "node_modules" "node modules"
cache_cwd_directory ".venv" "python virtualenv"
cache_cwd_directory "wapm_packages", "wapm packages"
cache_cwd_directory "wapm_packages" "wapm packages"
cache_cwd_directory ".build" "swift build"

cache_home_directory ".yarn_cache" "yarn cache"
cache_home_directory ".cache" "pip cache"
Expand Down Expand Up @@ -669,6 +716,20 @@ cache_artifacts() {
else
rm -rf $NETLIFY_CACHE_DIR/ruby_version
fi

# cache the version of Swift installed
if [[ "$CUSTOM_SWIFT" -ne "0" ]]
then
if ! [ -d $NETLIFY_CACHE_DIR/swift_version/$SWIFT_VERSION ]
then
rm -rf $NETLIFY_CACHE_DIR/swift_version
mkdir $NETLIFY_CACHE_DIR/swift_version
mv $SWIFTENV_ROOT/versions/$SWIFT_VERSION $NETLIFY_CACHE_DIR/swift_version/
echo "Cached Swift version $SWIFT_VERSION"
fi
else
rm -rf $NETLIFY_CACHE_DIR/swift_version
fi
}

move_cache() {
Expand Down
3 changes: 2 additions & 1 deletion run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ cd $NETLIFY_REPO_DIR
: ${YARN_VERSION="1.13.0"}
: ${PHP_VERSION="5.6"}
: ${GO_VERSION="1.12"}
: ${SWIFT_VERSION="5.2"}

echo "Installing dependencies"
install_dependencies $NODE_VERSION $RUBY_VERSION $YARN_VERSION $PHP_VERSION $GO_VERSION
install_dependencies $NODE_VERSION $RUBY_VERSION $YARN_VERSION $PHP_VERSION $GO_VERSION $SWIFT_VERSION

echo "Installing missing commands"
install_missing_commands
Expand Down
1 change: 1 addition & 0 deletions test-tools/start-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ docker run --rm -t -i \
-e HUGO_VERSION \
-e PHP_VERSION \
-e GO_VERSION \
-e SWIFT_VERSION \
-v ${REPO_PATH}:/opt/repo \
-v ${BASE_PATH}/run-build.sh:/usr/local/bin/build \
-v ${BASE_PATH}/run-build-functions.sh:/usr/local/bin/run-build-functions.sh \
Expand Down
2 changes: 2 additions & 0 deletions test-tools/test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fi
: ${HUGO_VERSION="0.54.0"}
: ${PHP_VERSION="5.6"}
: ${GO_VERSION="1.12"}
: ${SWIFT_VERSION="5.2"}

BASE_PATH=$(pwd)
REPO_PATH="$(cd $1 && pwd)"
Expand Down Expand Up @@ -51,6 +52,7 @@ docker run --rm \
-e NETLIFY_VERBOSE \
-e GO_VERSION \
-e GO_IMPORT_PATH \
-e SWIFT_VERSION \
-v "${REPO_PATH}:/opt/repo" \
-v "${BASE_PATH}/run-build.sh:/usr/local/bin/build" \
-v "${BASE_PATH}/run-build-functions.sh:/usr/local/bin/run-build-functions.sh" \
Expand Down

0 comments on commit 1c486be

Please sign in to comment.