Skip to content

Commit

Permalink
Snappy: Add support for snapcraft builds
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Jun 18, 2019
1 parent 9e2b86d commit 0589416
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/**/target
/home
/local-rustup
/snapcraft
49 changes: 43 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,51 @@ matrix:
# These builds always run. PRs, master, staging, stable, etc.
- &linuxalways
os: linux
env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1 DO_SNAP=1 SNAP_ARCH=amd64
addons: &snapaddon
snaps:
- name: snapcraft
channel: stable
confinement: classic

# Most builds consuming this only run on the stable and staging branches
- &linuxstable
os: linux
env: TARGET=i686-unknown-linux-gnu
env: TARGET=i686-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=i386
if: branch != master
addons:
<<: *snapaddon

# These builds run on non-pull-requests, so master, staging, stable...
- &linuxmaster
os: linux
env: SKIP_TESTS=1 TARGET=aarch64-unknown-linux-gnu
env: SKIP_TESTS=1 TARGET=aarch64-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=arm64
if: type != pull_request
addons:
<<: *snapaddon

# Cross builds happen in the `rust-slave-linux-cross` image to ensure that
# we use the right cross compilers for these targets. That image should
# bundle all the gcc cross compilers to enable us to build OpenSSL

# Builds which occur only on stable (and staging branches) take linuxstable
# Those which occur on master or any other branch (but not PRs) linuxmaster
# And those which run always (PRs, master, staging, etc) linuxalways
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=arm-unknown-linux-gnueabi }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=arm-unknown-linux-gnueabihf }
- { <<: *linuxalways, env: SKIP_TESTS=1 TARGET=armv7-unknown-linux-gnueabihf }
- <<: *linuxmaster
env: SKIP_TESTS=1 TARGET=armv7-unknown-linux-gnueabihf DO_SNAP=1 SNAP_ARCH=armhf
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=x86_64-unknown-freebsd }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=powerpc-unknown-linux-gnu }
- { <<: *linuxmaster, env: SKIP_TESTS=1 TARGET=powerpc64-unknown-linux-gnu }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=powerpc64le-unknown-linux-gnu }
- <<: *linuxmaster
env: SKIP_TESTS=1 TARGET=powerpc64le-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=ppc64el
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mips-unknown-linux-gnu }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mipsel-unknown-linux-gnu }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mips64-unknown-linux-gnuabi64 }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mips64el-unknown-linux-gnuabi64 }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=s390x-unknown-linux-gnu }
- <<: *linuxmaster
env: SKIP_TESTS=1 TARGET=s390x-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=s390x
- { <<: *linuxmaster, env: SKIP_TESTS=1 TARGET=x86_64-unknown-linux-musl }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=arm-linux-androideabi }
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=armv7-linux-androideabi }
Expand Down Expand Up @@ -132,6 +147,14 @@ script:
before_deploy:
- sh ci/prepare-deploy-travis.sh
- |
if [ -n "$DO_SNAP" ]; then
if [ "$TRAVIS_BRANCH" != "stable" ]; then
export SNAP_EDGE=1
fi
sh ci/snapcraft.sh
export SNAP_NAME=snapcraft/$(cat snap/snap-name)
fi
deploy:
- provider: s3
Expand All @@ -145,3 +168,17 @@ deploy:
secret_access_key: $AWS_SECRET_ACCESS_KEY
on:
branch: stable
- provider: snap
snap: $SNAP_NAME
channel: beta
skip_cleanup: true
on:
branch: stable
condition: $DO_SNAP = 1
- provider: snap
snap: $SNAP_NAME
channel: edge
skip_cleanup: true
on:
branch: master
condition: $DO_SNAP = 1
135 changes: 135 additions & 0 deletions ci/snapcraft.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/sh

set -e

# This script encapsulates the job of crafting snaps of rustup and publishing
# them. We construct either an edge snap (builds on PRs or master)
# or a beta snap if built from a non-master branch.

# If built on master, we will publish the edge snap
# If built on stable, we will publish the beta snap

# To parameterise the build, the following environment variables are needed:
# DO_SNAP=1 <-- without this, we don't run
# SNAP_EDGE=1 <-- with this, we build an edge/devel snap, otherwise a release snap
# SNAP_ARCH=... <-- without this we cannot built, this is the snap architecture we're building

if [ -z "$DO_SNAP" ]; then
echo "SNAP: Not attempting to snap"
exit 0
fi

if ! command -v snapcraft >/dev/null 2>/dev/null; then
echo "SNAP: Unable to find snapcraft, cannot run"
exit 1
fi

if [ -z "$SNAP_ARCH" ]; then
echo "SNAP: Unable to generate snap, architecture unset"
exit 1
else
echo "SNAP: Constructing snap for architecture $SNAP_ARCH"
fi

if [ -n "$SNAP_EDGE" ]; then
echo "SNAP: Generated snap will be an grade:devel snap"
GRADE=devel
else
echo "SNAP: Generated snap will be a grade:stable snap"
GRADE=stable
fi


# This is the list of proxies which the snap will contain. This needs to match
# the set of aliases which the snap has been allocated. If we add to this
# list but don't get the aliases added, then people won't see the proxy except
# as rustup.$PROXY. If we have an alias which is not a supported proxy name
# then rustup might get sad.

PROXIES="cargo cargo-clippy cargo-fmt cargo-miri clippy-driver rls rustc rustdoc rustfmt"

# From now on, things should be automagic

VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d\" -f2)

rm -rf snapcraft

mkdir -p snapcraft/snap

cd snapcraft

cat > snap/snapcraft.yaml <<SNAP
name: rustup
version: $VERSION
confinement: classic
base: core18
architectures:
- build-on: [amd64]
run-on: [$SNAP_ARCH]
description: |
Rustup is the Rust Language's installer and primary front-end. You probably
want this if you want to develop anything written in Rust.
SNAP

if [ -n "$SNAP_EDGE" ]; then
cat >> snap/snapcraft.yaml <<SNAP
Please note, this snap is experimental and functionality cannot be guaranteed
to be consistent with released snaps.
summary: "EXPERIMENTAL: The Rust Language Installer"
grade: $GRADE
SNAP
else
cat >> snap/snapcraft.yaml <<SNAP
summary: "The Rust Language Installer"
grade: stable
SNAP
fi

cat >> snap/snapcraft.yaml <<SNAP
parts:
acquire:
plugin: dump
source: inputs
prime:
- "-rustup-init"
link:
plugin: nil
build-attributes: [no-patchelf]
after: [acquire]
override-pull: |
cp \$SNAPCRAFT_STAGE/rustup-init .
override-build: |
mkdir -p \$SNAPCRAFT_PART_INSTALL/bin
cp rustup-init \$SNAPCRAFT_PART_INSTALL/bin/rustup
SNAP

for PROXY in $PROXIES; do
cat >> snap/snapcraft.yaml <<SNAP
ln \$SNAPCRAFT_PART_INSTALL/bin/rustup \$SNAPCRAFT_PART_INSTALL/bin/$PROXY
SNAP
done

cat >> snap/snapcraft.yaml << 'SNAP'
prime:
- "-rustup-init"
environment:
RUSTUP_HOME: "$SNAP_USER_DATA/rustup"
apps:
rustup:
command: bin/rustup
SNAP

for PROXY in $PROXIES; do
cat >> snap/snapcraft.yaml <<SNAP
$PROXY:
command: bin/$PROXY
SNAP
done

mkdir inputs
cp ../target/"$TARGET"/release/rustup-init inputs/
snapcraft --destructive-mode
echo "rustup_${VERSION}_${SNAP_ARCH}.snap" > snap-name

0 comments on commit 0589416

Please sign in to comment.