From 0589416c6ad76f747243b8c8be97d2f358bdeef1 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Wed, 12 Jun 2019 21:48:06 -0400 Subject: [PATCH] Snappy: Add support for snapcraft builds Signed-off-by: Daniel Silverstone --- .gitignore | 1 + .travis.yml | 49 +++++++++++++++--- ci/snapcraft.sh | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 ci/snapcraft.sh diff --git a/.gitignore b/.gitignore index 3db8ed7eed5..08107a6644b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /**/target /home /local-rustup +/snapcraft diff --git a/.travis.yml b/.travis.yml index aeca27409cd..0ed01c53be3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 } @@ -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 @@ -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 diff --git a/ci/snapcraft.sh b/ci/snapcraft.sh new file mode 100644 index 00000000000..bdd47bcf14b --- /dev/null +++ b/ci/snapcraft.sh @@ -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/snapcraft.yaml <> snap/snapcraft.yaml <> snap/snapcraft.yaml <> snap/snapcraft.yaml <> 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-name