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