Skip to content

Commit 987e798

Browse files
committed
CI: Add snapcraft support
To begin the work of supporting snaps of rustup, we need to first ensure we can build the snaps in the first place. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent ac4d4a3 commit 987e798

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
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

ci/actions-templates/linux-builds-template.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ jobs:
4949
include:
5050
- target: x86_64-unknown-linux-gnu
5151
run_tests: YES
52+
snap_arch: amd64
53+
- target: i686-unknown-linux-gnu # skip-pr skip-master
54+
snap_arch: i386 # skip-pr skip-master
55+
- target: aarch64-unknown-linux-gnu # skip-pr
56+
snap_arch: arm64 # skip-pr
57+
- target: armv7-unknown-linux-gnueabihf
58+
snap_arch: armhf
59+
- target: powerpc64le-unknown-linux-gnu # skip-pr skip-master
60+
snap_arch: ppc64el # skip-pr skip-master
61+
- target: s390x-unknown-linux-gnu # skip-pr skip-master
62+
snap_arch: s390x # skip-pr skip-master
5263
steps:
5364
- uses: actions/checkout@v2
5465
with:
@@ -156,6 +167,27 @@ jobs:
156167
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
157168
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
158169
if: github.event_name == 'push' && github.ref == 'refs/heads/stable'
170+
- name: Build a snapcraft configuration file
171+
run: |
172+
bash ci/snapcraft.bash
173+
if: matrix.snap_arch != ''
174+
env:
175+
DO_SNAP: 1
176+
SNAP_ARCH: ${{ matrix.snap_arch }}
177+
SNAP_EDGE: 1 # skip-stable
178+
- uses: snapcore/action-build@v1
179+
id: snapcraftbuild
180+
with:
181+
path: snapcraft
182+
if: matrix.snap_arch != ''
183+
- uses: snapcore/action-publish@v1
184+
with:
185+
store_login: ${{ secrets.SNAPCRAFT_TOKEN }}
186+
snap: ${{ steps.snapcraftbuild.outputs.snap }}
187+
release: edge # skip-pr skip-stable
188+
release: beta # skip-pr skip-master
189+
if: matrix.snap_arch != '' # skip-pr
190+
if: matrix.snap_arch == 'not-for-prs' # skip-master skip-stable
159191
- name: Clear the cargo caches
160192
run: |
161193
cargo install cargo-cache --no-default-features --features ci-autoclean

ci/snapcraft.bash

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

0 commit comments

Comments
 (0)