Skip to content

Commit 1907b12

Browse files
authored
Merge pull request #1898 from kinnison/kinnison/snapcraft
Snappy: Add support for snapcraft builds
2 parents 0e2976b + de2b7a0 commit 1907b12

File tree

6 files changed

+232
-0
lines changed

6 files changed

+232
-0
lines changed

.github/workflows/linux-builds-on-master.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ jobs:
2727
include:
2828
- target: x86_64-unknown-linux-gnu
2929
run_tests: YES
30+
snap_arch: amd64
31+
- target: aarch64-unknown-linux-gnu # skip-pr
32+
snap_arch: arm64 # skip-pr
33+
- target: armv7-unknown-linux-gnueabihf
34+
snap_arch: armhf
3035
steps:
3136
- uses: actions/checkout@v2
3237
with:
@@ -134,6 +139,25 @@ jobs:
134139
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
135140
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
136141
if: github.event_name == 'push' && github.ref == 'refs/heads/stable'
142+
- name: Build a snapcraft configuration file
143+
run: |
144+
bash ci/snapcraft.bash
145+
if: matrix.snap_arch != ''
146+
env:
147+
DO_SNAP: 1
148+
SNAP_ARCH: ${{ matrix.snap_arch }}
149+
SNAP_EDGE: 1 # skip-stable
150+
- uses: snapcore/action-build@v1
151+
id: snapcraftbuild
152+
with:
153+
path: snapcraft
154+
if: matrix.snap_arch != ''
155+
- uses: snapcore/action-publish@v1
156+
with:
157+
store_login: ${{ secrets.SNAPCRAFT_TOKEN }}
158+
snap: ${{ steps.snapcraftbuild.outputs.snap }}
159+
release: edge # skip-pr skip-stable
160+
if: matrix.snap_arch != '' # skip-pr
137161
- name: Clear the cargo caches
138162
run: |
139163
cargo install cargo-cache --no-default-features --features ci-autoclean

.github/workflows/linux-builds-on-pr.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
include:
2323
- target: x86_64-unknown-linux-gnu
2424
run_tests: YES
25+
snap_arch: amd64
26+
- target: armv7-unknown-linux-gnueabihf
27+
snap_arch: armhf
2528
steps:
2629
- uses: actions/checkout@v2
2730
with:
@@ -129,6 +132,24 @@ jobs:
129132
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
130133
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
131134
if: github.event_name == 'push' && github.ref == 'refs/heads/stable'
135+
- name: Build a snapcraft configuration file
136+
run: |
137+
bash ci/snapcraft.bash
138+
if: matrix.snap_arch != ''
139+
env:
140+
DO_SNAP: 1
141+
SNAP_ARCH: ${{ matrix.snap_arch }}
142+
SNAP_EDGE: 1 # skip-stable
143+
- uses: snapcore/action-build@v1
144+
id: snapcraftbuild
145+
with:
146+
path: snapcraft
147+
if: matrix.snap_arch != ''
148+
- uses: snapcore/action-publish@v1
149+
with:
150+
store_login: ${{ secrets.SNAPCRAFT_TOKEN }}
151+
snap: ${{ steps.snapcraftbuild.outputs.snap }}
152+
if: matrix.snap_arch == 'not-for-prs' # skip-master skip-stable
132153
- name: Clear the cargo caches
133154
run: |
134155
cargo install cargo-cache --no-default-features --features ci-autoclean

.github/workflows/linux-builds-on-stable.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ jobs:
4141
include:
4242
- target: x86_64-unknown-linux-gnu
4343
run_tests: YES
44+
snap_arch: amd64
45+
- target: i686-unknown-linux-gnu # skip-pr skip-master
46+
snap_arch: i386 # skip-pr skip-master
47+
- target: aarch64-unknown-linux-gnu # skip-pr
48+
snap_arch: arm64 # skip-pr
49+
- target: armv7-unknown-linux-gnueabihf
50+
snap_arch: armhf
51+
- target: powerpc64le-unknown-linux-gnu # skip-pr skip-master
52+
snap_arch: ppc64el # skip-pr skip-master
53+
- target: s390x-unknown-linux-gnu # skip-pr skip-master
54+
snap_arch: s390x # skip-pr skip-master
4455
steps:
4556
- uses: actions/checkout@v2
4657
with:
@@ -148,6 +159,24 @@ jobs:
148159
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
149160
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
150161
if: github.event_name == 'push' && github.ref == 'refs/heads/stable'
162+
- name: Build a snapcraft configuration file
163+
run: |
164+
bash ci/snapcraft.bash
165+
if: matrix.snap_arch != ''
166+
env:
167+
DO_SNAP: 1
168+
SNAP_ARCH: ${{ matrix.snap_arch }}
169+
- uses: snapcore/action-build@v1
170+
id: snapcraftbuild
171+
with:
172+
path: snapcraft
173+
if: matrix.snap_arch != ''
174+
- uses: snapcore/action-publish@v1
175+
with:
176+
store_login: ${{ secrets.SNAPCRAFT_TOKEN }}
177+
snap: ${{ steps.snapcraftbuild.outputs.snap }}
178+
release: beta # skip-pr skip-master
179+
if: matrix.snap_arch != '' # skip-pr
151180
- name: Clear the cargo caches
152181
run: |
153182
cargo install cargo-cache --no-default-features --features ci-autoclean

.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)