Skip to content

Commit 7d14248

Browse files
committed
[linux] snap package
1 parent a4d2672 commit 7d14248

File tree

6 files changed

+259
-0
lines changed

6 files changed

+259
-0
lines changed

.github/workflows/snap.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Main doc: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/introduction-to-github-actions
2+
# Runners spec: https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners
3+
# Glob expressions: https://github.com/actions/toolkit/tree/main/packages/glob
4+
5+
name: Snap package
6+
7+
###############################################################################
8+
# Schedule:
9+
# - push on any branch whose name matches v** or master
10+
# - any pull request
11+
# - once a day
12+
# - manually with parameters (see also github_actions/run_snap.sh)
13+
###############################################################################
14+
on:
15+
push:
16+
branches:
17+
- v**
18+
- master
19+
pull_request:
20+
branches:
21+
- '**'
22+
schedule:
23+
- cron: '0 0 * * *'
24+
workflow_dispatch:
25+
inputs:
26+
save:
27+
description: 'Save artifact for download'
28+
default: false
29+
upload:
30+
description: 'Upload artifact to snap store'
31+
default: false
32+
platform:
33+
description: 'Arguments for the platform script'
34+
required: true
35+
default: '-extent=f -parallel=p -jobs=2 -vst=y -compcert=f'
36+
37+
###############################################################################
38+
# Platform script options shared among all jobs
39+
#
40+
# Default values when the job is run automatically
41+
###############################################################################
42+
env:
43+
COQREGTESTING: y
44+
PLATFORM: -extent=i -parallel=p -jobs=2
45+
SAVE_ARTIFACT: true
46+
47+
jobs:
48+
###############################################################################
49+
# Snap
50+
#
51+
# CAVEATS:
52+
# - bubblewrap does not work inside lxd (used by snap)
53+
# - uploading requires a secret in GH https://github.com/snapcore/action-publish
54+
###############################################################################
55+
56+
Ubuntu_snap:
57+
name: Snap package
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- name: Git checkout
62+
uses: actions/checkout@v2
63+
64+
- name: Set PLATFORM
65+
if: ${{ github.event.inputs.platform != '' }}
66+
run: echo "PLATFORM=${{ github.event.inputs.platform }}" >> $GITHUB_ENV
67+
68+
- name: Set SAVE_ARTIFACT
69+
if: ${{ github.event.inputs.save != '' }}
70+
run: echo "SAVE_ARTIFACT=${{ github.event.inputs.save }}" >> $GITHUB_ENV
71+
72+
- name: Install opam
73+
env:
74+
OPAM_VERSION: 2.0.7
75+
run: |
76+
curl -L https://github.com/ocaml/opam/releases/download/${OPAM_VERSION}/opam-${OPAM_VERSION}-x86_64-linux > opam.${OPAM_VERSION}
77+
chmod a+x opam.${OPAM_VERSION}
78+
sudo cp opam.${OPAM_VERSION} /usr/local/bin/opam.${OPAM_VERSION}
79+
sudo ln -s /usr/local/bin/opam.${OPAM_VERSION} /usr/local/bin/opam
80+
opam init --bare --disable-sandboxing -y
81+
opam switch create default --empty -y
82+
opam repo add coq-released https://coq.inria.fr/opam/released
83+
opam repo add coq-dev https://coq.inria.fr/opam/core-dev
84+
opam repo add coq-extra https://coq.inria.fr/opam/extra-dev
85+
opam repo add coq-platform file://$PWD/opam
86+
opam repo set-repos coq-platform coq-released coq-dev coq-extra default
87+
opam update
88+
89+
- name: Generate snapcraft file
90+
run: linux/create_linux_installer.sh $PLATFORM
91+
92+
- name: Print snapcraft file
93+
run: cat snap/snapcraft.yaml
94+
95+
- name: Run snapcraft
96+
uses: snapcore/action-build@v1
97+
id: build
98+
99+
- name: Save Artifact
100+
if: ${{ env.SAVE_ARTIFACT }}
101+
uses: actions/upload-artifact@v2
102+
with:
103+
name: 'Snap package'
104+
path: ${{ steps.build.outputs.snap }}
105+
106+
- name: Upload Artifact to the Snap store
107+
if: ${{ github.event.inputs.upload }}
108+
uses: snapcore/action-publish@v1
109+
with:
110+
store_login: ${{ secrets.STORE_LOGIN }}
111+
snap: ${{ steps.build.outputs.snap }}
112+
release: edge

github_actions/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Build the snap package for the full platform
2+
3+
The web UI only lets you do this for the default branch, in order to run the
4+
`snap.yml` workflow on another branch (a git ref really) you can use the
5+
`./github_actions/run_snap.sh`.
6+
7+
First of all you need to generate (once and forall) a token from
8+
https://github.com/settings/tokens (tick the "workflow" box).
9+
10+
Then:
11+
```shell
12+
export GHTOKEN=6NDVjMDhmZDAwMGZ...
13+
export GHUSER=gares
14+
export BRANCH=v8.13
15+
export PLATFORM="-extent=f -parallel=p -jobs=2 -vst=y -compcert=f"
16+
export SAVE=true
17+
export UPLOAD=false
18+
./github_actions/run_snap.sh
19+
```
20+
The shell script prints a `curl` invocation you have to run (after inspection).

github_actions/run_snap.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
[ -z "$GHUSER" ] && echo "please set GHUSER to your github user" && exit 1
4+
[ -z "$GHTOKEN" ] && echo "please set GHTOKEN to your github access token (generate one here: https://github.com/settings/tokens)" && exit 1
5+
[ -z "$BRANCH" ] && echo "please set BRANCH to the branch to build" && exit 1
6+
[ -z "$PLATFORM" ] && echo "please set PLATFORM to the arguments for the script, eg \"-extent=f -parallel=p -jobs=2 -vst=y -compcert=f\"" && exit 1
7+
[ -z "$SAVE" ] && echo "INFO: set SAVE to true to save the artifact (default false)" && SAVE=false
8+
[ -z "$UPLOAD" ] && echo "INFO: set UPLOAD to true to upload to the snap store (default false)" && UPLOAD=false
9+
10+
function go {
11+
local obj=$(printf '{ "ref": "%s", "inputs": { "save" : "%s", "upload" : "%s", "platform" : "%s" } }' "$BRANCH" "$SAVE" "$UPLOAD" "$PLATFORM")
12+
echo curl -u $GHUSER:\$GHTOKEN -X POST \
13+
https://api.github.com/repos/coq/platform/actions/workflows/snap.yml/dispatches -d $(printf "'%s'" "$obj")
14+
}
15+
16+
echo "Run this:"
17+
echo $(go)

linux/create_linux_installer.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# This script creates a Linux installer based on snap
4+
cd "$(dirname "$0")/.."
5+
source shell_scripts/init_safety_debug.sh
6+
source shell_scripts/init_paths.sh
7+
source shell_scripts/init_utilities.sh
8+
source coq_platform_switch_name.sh
9+
source shell_scripts/parse_cmdline_arguments.sh
10+
source shell_scripts/ask_introduction.sh
11+
source coq_platform_packages.sh
12+
13+
# Snap versions cannot contain . nor +
14+
COQ_VERSION=${COQ_PLATFORM_VERSION//[.+]/-}
15+
16+
# Description of the snap
17+
COQ_DESCRIPTION=`mktemp`
18+
cat > $COQ_DESCRIPTION <<EOT
19+
The Coq interactive prover provides a formal language to write
20+
mathematical definitions, executable algorithms, and theorems, together
21+
with an environment for semi-interactive development of machine-checked
22+
proofs.
23+
24+
This snap contains the Coq prover version $COQ_PLATFORM_VERSION
25+
along with CoqIDE and the following packages:
26+
EOT
27+
28+
for p in $(echo ${PACKAGES} | sed -e 's/ /\n/g' | sort); do
29+
pname=`echo $p | sed 's/\..*//'`
30+
if [ "${pname##coq-}" == "$pname" ]; then continue; fi
31+
pversion="$(opam show $p -f version: | tr -d \")"
32+
plicense="$(opam show $p -f license: | tr -d \")"
33+
pdescr="$(opam show $p -f synopsis: | tr -d \")"
34+
printf " * **%s**: %s (version: %s, license: %s)\n" ${pname##coq-} "$pdescr" "$pversion" "$plicense" >> $COQ_DESCRIPTION
35+
done
36+
37+
sed \
38+
-e "s/@@COQ_VERSION@@/$COQ_VERSION/g" \
39+
-e "s/@@PLATFORM_ARGS@@/$*/g" \
40+
-e "/@@COQ_DESCRIPTION@@/r $COQ_DESCRIPTION" -e "/@@COQ_DESCRIPTION@@/d" \
41+
snap/local/snapcraft.yaml.in > snap/snapcraft.yaml
42+
43+
echo "INFO: filled in snap/snapcraft.yaml"
44+
45+
mkdir -p snap/gui/
46+
47+
sed \
48+
-e "s/@@COQ_VERSION@@/$COQ_VERSION/g" \
49+
snap/local/gui/coqide.desktop.in > snap/gui/coqide.desktop
50+
51+
echo "INFO: filled in snap/gui/coqide.desktop"
52+
53+
echo -e "Done, now run:\n\tsnapcraft snap"
54+
55+
rm -f $COQ_DESCRIPTION

snap/local/gui/coqide.desktop.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[Desktop Entry]
2+
Name=CoqIDE
3+
Exec=coqide %F
4+
Icon=${SNAP}/coq-platform/@@COQ_VERSION@@/share/coq/coq.png
5+
Type=Application
6+
MimeType=text/x-verilog

snap/local/snapcraft.yaml.in

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: coq-prover
2+
base: core18
3+
version: '@@COQ_VERSION@@'
4+
summary: Coq
5+
description: |
6+
@@COQ_DESCRIPTION@@
7+
8+
grade: stable
9+
confinement: strict
10+
11+
parts:
12+
coq:
13+
plugin: nil
14+
build-packages: [build-essential, curl, m4, unzip, git]
15+
source: .
16+
source-type: local
17+
override-build: |
18+
echo "COQ_PLATFORM_VERSION=@@COQ_VERSION@@" >> coq_platform_switch_name.sh
19+
echo "COQ_PLATFORM_SWITCH_NAME=@@COQ_VERSION@@" >> coq_platform_switch_name.sh
20+
COQREGTESTING=y OPAMROOT=$SNAPCRAFT_PART_INSTALL/coq-platform/ ./coq_platform_make.sh @@PLATFORM_ARGS@@
21+
OPAMROOT=$SNAPCRAFT_PART_INSTALL/coq-platform/ opam clean
22+
echo 'COQLIB=/snap/coq/current/coq-platform/@@COQ_VERSION@@/lib/coq' > $SNAPCRAFT_PART_INSTALL/coq-platform/@@COQ_VERSION@@/bin/coq_environment.txt
23+
echo 'OCAMLFIND=/snap/coq/current/coq-platform/@@COQ_VERSION@@/bin/ocamlfind' >> $SNAPCRAFT_PART_INSTALL/coq-platform/@@COQ_VERSION@@/bin/coq_environment.txt
24+
find $SNAPCRAFT_PART_INSTALL/coq-platform/@@COQ_VERSION@@/ \( -name '*.byte.exe' -o -name '*.byte' -o -name '*.cm[aioxt]' -o -name '*.cmxa' -o -name '*.[oa]' -o -name '*.cmti' -o -name '*.glob' \) -type f -delete
25+
find $SNAPCRAFT_PART_INSTALL/coq-platform/@@COQ_VERSION@@/bin/ -maxdepth 1 -mindepth 1 \! -name 'coq*' -exec rm -f {} \;
26+
find $SNAPCRAFT_PART_INSTALL/coq-platform/@@COQ_VERSION@@/lib/ -maxdepth 1 -mindepth 1 \! \( -name 'coq' -o -name 'stublibs' \) -exec rm -rf {} \;
27+
rm -rf $SNAPCRAFT_PART_INSTALL/coq-platform/@@COQ_VERSION@@/share/ocaml-secondary-compiler
28+
rm -rf $SNAPCRAFT_PART_INSTALL/coq-platform/repo/
29+
30+
apps:
31+
coqide:
32+
command: coq-platform/@@COQ_VERSION@@/bin/coqide
33+
plugs: [desktop, home]
34+
extensions: [gnome-3-28]
35+
desktop: ../project/snap/gui/coqide.desktop
36+
coqtop:
37+
plugs: [home]
38+
command: coq-platform/@@COQ_VERSION@@/bin/coqtop
39+
coqc:
40+
plugs: [home]
41+
command: coq-platform/@@COQ_VERSION@@/bin/coqc
42+
coq-makefile:
43+
plugs: [home]
44+
command: coq-platform/@@COQ_VERSION@@/bin/coq_makefile COQBIN = /snap/coq/current/coq-platform/@@COQ_VERSION@@/bin/
45+
coqidetop:
46+
plugs: [home]
47+
command: coq-platform/@@COQ_VERSION@@/bin/coqidetop.opt
48+
49+

0 commit comments

Comments
 (0)