Skip to content

Commit 593b35c

Browse files
committed
Snappy: Add support for snapcraft builds
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent 9e2b86d commit 593b35c

File tree

3 files changed

+179
-6
lines changed

3 files changed

+179
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/**/target
88
/home
99
/local-rustup
10+
/snapcraft

.travis.yml

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,51 @@ matrix:
2222
# These builds always run. PRs, master, staging, stable, etc.
2323
- &linuxalways
2424
os: linux
25-
env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
25+
env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1 DO_SNAP=1 SNAP_ARCH=amd64
26+
addons: &snapaddon
27+
snaps:
28+
- name: snapcraft
29+
channel: stable
30+
confinement: classic
31+
2632
# Most builds consuming this only run on the stable and staging branches
2733
- &linuxstable
2834
os: linux
29-
env: TARGET=i686-unknown-linux-gnu
35+
env: TARGET=i686-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=i386
3036
if: branch != master
37+
addons:
38+
<<: *snapaddon
39+
3140
# These builds run on non-pull-requests, so master, staging, stable...
3241
- &linuxmaster
3342
os: linux
34-
env: SKIP_TESTS=1 TARGET=aarch64-unknown-linux-gnu
43+
env: SKIP_TESTS=1 TARGET=aarch64-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=arm64
3544
if: type != pull_request
45+
addons:
46+
<<: *snapaddon
3647

3748
# Cross builds happen in the `rust-slave-linux-cross` image to ensure that
3849
# we use the right cross compilers for these targets. That image should
3950
# bundle all the gcc cross compilers to enable us to build OpenSSL
51+
4052
# Builds which occur only on stable (and staging branches) take linuxstable
4153
# Those which occur on master or any other branch (but not PRs) linuxmaster
4254
# And those which run always (PRs, master, staging, etc) linuxalways
4355
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=arm-unknown-linux-gnueabi }
4456
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=arm-unknown-linux-gnueabihf }
45-
- { <<: *linuxalways, env: SKIP_TESTS=1 TARGET=armv7-unknown-linux-gnueabihf }
57+
- <<: *linuxmaster
58+
env: SKIP_TESTS=1 TARGET=armv7-unknown-linux-gnueabihf DO_SNAP=1 SNAP_ARCH=armhf
4659
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=x86_64-unknown-freebsd }
4760
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=powerpc-unknown-linux-gnu }
4861
- { <<: *linuxmaster, env: SKIP_TESTS=1 TARGET=powerpc64-unknown-linux-gnu }
49-
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=powerpc64le-unknown-linux-gnu }
62+
- <<: *linuxmaster
63+
env: SKIP_TESTS=1 TARGET=powerpc64le-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=ppc64el
5064
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mips-unknown-linux-gnu }
5165
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mipsel-unknown-linux-gnu }
5266
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mips64-unknown-linux-gnuabi64 }
5367
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=mips64el-unknown-linux-gnuabi64 }
54-
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=s390x-unknown-linux-gnu }
68+
- <<: *linuxmaster
69+
env: SKIP_TESTS=1 TARGET=s390x-unknown-linux-gnu DO_SNAP=1 SNAP_ARCH=s390x
5570
- { <<: *linuxmaster, env: SKIP_TESTS=1 TARGET=x86_64-unknown-linux-musl }
5671
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=arm-linux-androideabi }
5772
- { <<: *linuxstable, env: SKIP_TESTS=1 TARGET=armv7-linux-androideabi }
@@ -132,6 +147,14 @@ script:
132147
133148
before_deploy:
134149
- sh ci/prepare-deploy-travis.sh
150+
- |
151+
if [ -n "$DO_SNAP" ]; then
152+
if [ "$TRAVIS_BRANCH" != "stable" ]; then
153+
export SNAP_EDGE=1
154+
fi
155+
sh ci/snapcraft.sh
156+
export SNAP_NAME=snapcraft/$(cat snap/snap-name)
157+
fi
135158
136159
deploy:
137160
- provider: s3
@@ -145,3 +168,17 @@ deploy:
145168
secret_access_key: $AWS_SECRET_ACCESS_KEY
146169
on:
147170
branch: stable
171+
- provider: snap
172+
snap: $SNAP_NAME
173+
channel: beta
174+
skip_cleanup: true
175+
on:
176+
branch: stable
177+
condition: $DO_SNAP = 1
178+
- provider: snap
179+
snap: $SNAP_NAME
180+
channel: edge
181+
skip_cleanup: true
182+
on:
183+
branch: master
184+
condition: $DO_SNAP = 1

ci/snapcraft.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# This script encapsulates the job of crafting snaps of rustup and publishing
6+
# them. We construct either an edge snap (builds on PRs or master)
7+
# or a beta snap if built from a non-master branch.
8+
9+
# If built on master, we will publish the edge snap
10+
# If built on stable, we will publish the beta snap
11+
12+
# To parameterise the build, the following environment variables are needed:
13+
# DO_SNAP=1 <-- without this, we don't run
14+
# SNAP_EDGE=1 <-- with this, we build an edge/devel snap, otherwise a release snap
15+
# SNAP_ARCH=... <-- without this we cannot built, this is the snap architecture we're building
16+
17+
if [ -z "$DO_SNAP" ]; then
18+
echo "SNAP: Not attempting to snap"
19+
exit 0
20+
fi
21+
22+
if ! command -v snapcraft >/dev/null; then
23+
echo "SNAP: Unable to find snapcraft, cannot run"
24+
exit 1
25+
fi
26+
27+
if [ -z "$SNAP_ARCH" ]; then
28+
echo "SNAP: Unable to generate snap, architecture unset"
29+
exit 1
30+
else
31+
echo "SNAP: Constructing snap for architecture $SNAP_ARCH"
32+
fi
33+
34+
if [ -n "$SNAP_EDGE" ]; then
35+
echo "SNAP: Generated snap will be an grade:devel snap"
36+
GRADE=devel
37+
else
38+
echo "SNAP: Generated snap will be a grade:stable snap"
39+
GRADE=stable
40+
fi
41+
42+
43+
# This is the list of proxies which the snap will contain. This needs to match
44+
# the set of aliases which the snap has been allocated. If we add to this
45+
# list but don't get the aliases added, then people won't see the proxy except
46+
# as rustup.$PROXY. If we have an alias which is not a supported proxy name
47+
# then rustup might get sad.
48+
49+
PROXIES="cargo cargo-clippy cargo-fmt cargo-miri clippy-driver rls rustc rustdoc rustfmt"
50+
51+
# From now on, things should be automagic
52+
53+
VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d\" -f2)
54+
55+
rm -rf snapcraft
56+
57+
mkdir -p snapcraft/snap
58+
59+
cd snapcraft
60+
61+
cat > snap/snapcraft.yaml <<SNAP
62+
name: rustup
63+
version: $VERSION
64+
confinement: classic
65+
base: core18
66+
architectures:
67+
- build-on: [amd64]
68+
run-on: [$SNAP_ARCH]
69+
description: |
70+
Rustup is the Rust Language's installer and primary front-end. You probably
71+
want this if you want to develop anything written in Rust.
72+
SNAP
73+
74+
if [ -n "$SNAP_EDGE" ]; then
75+
cat >> snap/snapcraft.yaml <<SNAP
76+
77+
Please note, this snap is experimental and functionality cannot be guaranteed
78+
to be consistent with released snaps.
79+
summary: "EXPERIMENTAL: The Rust Language Installer"
80+
grade: $GRADE
81+
SNAP
82+
else
83+
cat >> snap/snapcraft.yaml <<SNAP
84+
summary: "The Rust Language Installer"
85+
grade: $GRADE
86+
SNAP
87+
fi
88+
89+
cat >> snap/snapcraft.yaml <<SNAP
90+
parts:
91+
acquire:
92+
plugin: dump
93+
source: inputs
94+
prime:
95+
- "-rustup-init"
96+
link:
97+
plugin: nil
98+
build-attributes: [no-patchelf]
99+
after: [acquire]
100+
override-pull: |
101+
cp \$SNAPCRAFT_STAGE/rustup-init .
102+
override-build: |
103+
mkdir -p \$SNAPCRAFT_PART_INSTALL/bin
104+
cp rustup-init \$SNAPCRAFT_PART_INSTALL/bin/rustup
105+
SNAP
106+
107+
for PROXY in $PROXIES; do
108+
cat >> snap/snapcraft.yaml <<SNAP
109+
ln \$SNAPCRAFT_PART_INSTALL/bin/rustup \$SNAPCRAFT_PART_INSTALL/bin/$PROXY
110+
SNAP
111+
done
112+
113+
cat >> snap/snapcraft.yaml << 'SNAP'
114+
prime:
115+
- "-rustup-init"
116+
117+
environment:
118+
RUSTUP_HOME: "$SNAP_USER_DATA/rustup"
119+
120+
apps:
121+
rustup:
122+
command: bin/rustup
123+
SNAP
124+
125+
for PROXY in $PROXIES; do
126+
cat >> snap/snapcraft.yaml <<SNAP
127+
$PROXY:
128+
command: bin/$PROXY
129+
SNAP
130+
done
131+
132+
mkdir inputs
133+
cp ../target/"$TARGET"/release/rustup-init inputs/
134+
snapcraft --destructive-mode
135+
echo "rustup_${VERSION}_${SNAP_ARCH}.snap" > snap-name

0 commit comments

Comments
 (0)