Skip to content

Commit 34f76b4

Browse files
author
Brian J. Cardiff
authored
Add snap target (#39)
* Initial snap build support * Add output dir to snapcraft * Add banner to detect missing packages * Update readme
1 parent a9e28e7 commit 34f76b4

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ omnibus/crystal-darwin-x86_64
66
docs/build/
77

88
darwin/build/
9+
10+
snapcraft/snap/snapcraft.yaml
11+
snapcraft/*.snap
12+
snapcraft/build/

snapcraft/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
OUTPUT_DIR = build
2+
3+
.PHONY: all
4+
all: snap/snapcraft.yaml
5+
mkdir -p $(OUTPUT_DIR)
6+
snapcraft
7+
mv *.snap $(OUTPUT_DIR)
8+
9+
.PHONY: snap/snapcraft.yaml
10+
snap/snapcraft.yaml:
11+
sed 's/$${CRYSTAL_RELEASE_LINUX64_TARGZ}/$(subst /,\/,$(CRYSTAL_RELEASE_LINUX64_TARGZ))/; s/$${SNAP_GRADE}/$(SNAP_GRADE)/' snap/local/snapcraft.yaml.tpl > snap/snapcraft.yaml
12+
13+
clean:
14+
rm snap/snapcraft.yaml
15+
rm -Rf $(OUTPUT_DIR)

snapcraft/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# snap for Crystal
2+
3+
https://snapcraft.io/crystal
4+
5+
## Dependencies
6+
7+
- [`snapcraft`](https://docs.snapcraft.io/snapcraft-overview)
8+
9+
## Build the snap
10+
11+
Define the configuration variables and use `make` to expand the `./snap/local/snapcraft.yaml.tpl`.
12+
13+
```sh
14+
$ SNAP_GRADE=devel CRYSTAL_RELEASE_LINUX64_TARGZ="https://github.com/crystal-lang/crystal/releases/download/0.29.0/crystal-0.29.0-1-linux-x86_64.tar.gz" make
15+
```
16+
17+
## Snap channels usage
18+
19+
| Build | Channel | Version | Comments |
20+
|-------------------|----------------------------|-----------|------------------------------------------------------|
21+
| tagged release | latest/edge | M.m.p | manual set to beta, candidate, stable upon release |
22+
| nighties release | latest/edge | M.m.p-dev | |
23+
| maintenance build | latest/edge/${branch-name} | M.m.p-dev | |
24+
25+
### Configuration
26+
27+
* `CRYSTAL_RELEASE_LINUX64_TARGZ`: Url to crystal-{version}-{package}-linux-x86_64.tar.gz
28+
* `SNAP_GRADE`: Snap grande usually `devel` for nightlies and `stable` for tagged releases
29+
30+
## Install the snap
31+
32+
1. [Have snapd installed](https://snapcraft.io/docs/core/install)
33+
34+
2.
35+
```
36+
$ sudo snap install crystal --classic
37+
```
38+
39+
## Post-Install
40+
41+
This snap ships the compiler, all required native libraries should be available on the host.
42+
43+
The following are the suggested packages to be able to use the whole standard library capabilities.
44+
45+
```
46+
$ sudo apt-get install gcc pkg-config git tzdata \
47+
libpcre3-dev libevent-dev libyaml-dev \
48+
libgmp-dev libssl-dev libxml2-dev
49+
```
50+
51+
You can find more detailed information in the [Crystal reference](https://crystal-lang.org/reference/installation/on_debian_and_ubuntu.html) and in the [Crystal wiki](https://github.com/crystal-lang/crystal/wiki/All-required-libraries) if you want to be able to build the compiler itself.
52+

snapcraft/crystal-snap-wrapper

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
if [ ! -f $SNAP_USER_COMMON/env-check-success ]; then
4+
# check if a simple program can be compiled
5+
# if something fails show a banner to the user
6+
7+
$SNAP/bin/crystal eval 'puts "1"' >/dev/null 2>/dev/null
8+
if [ $? -eq 0 ]; then
9+
touch $SNAP_USER_COMMON/env-check-success
10+
else
11+
cat <<EOF
12+
13+
It seems that some libraries are missing in your host.
14+
The following are the suggested packages to be able to use the whole standard library capabilities.
15+
16+
$ sudo apt-get install gcc pkg-config git tzdata \\
17+
libpcre3-dev libevent-dev libyaml-dev \\
18+
libgmp-dev libssl-dev libxml2-dev
19+
20+
You can find more detailed information in:
21+
22+
* https://crystal-lang.org/reference/installation/on_debian_and_ubuntu.html
23+
* https://github.com/crystal-lang/crystal/wiki/All-required-libraries
24+
25+
EOF
26+
27+
fi
28+
fi
29+
30+
exec $SNAP/bin/crystal "$@"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: crystal
2+
base: core
3+
summary: A language for humans and computers
4+
description: |
5+
* Have a syntax similar to Ruby (but compatibility with it is not a goal)
6+
* Statically type-checked but without having to specify the type of variables or method arguments.
7+
* Be able to call C code by writing bindings to it in Crystal.
8+
* Have compile-time evaluation and generation of code, to avoid boilerplate code. Compile to efficient native code.
9+
adopt-info: crystal
10+
11+
grade: ${SNAP_GRADE}
12+
confinement: classic
13+
14+
environment:
15+
SHARDS_CACHE_PATH: $SNAP_USER_COMMON/.cache/shards
16+
CRYSTAL_CACHE_DIR: $SNAP_USER_COMMON/.cache/crystal
17+
18+
apps:
19+
crystal:
20+
command: crystal-snap-wrapper
21+
shards:
22+
command: bin/shards
23+
24+
parts:
25+
crystal:
26+
plugin: dump
27+
source: ${CRYSTAL_RELEASE_LINUX64_TARGZ}
28+
override-pull: |
29+
snapcraftctl pull
30+
snapcraftctl set-version "$(cat $SNAPCRAFT_PART_SRC/share/crystal/src/VERSION | head -n 1)"
31+
32+
snap-wrapper:
33+
plugin: dump
34+
source: .
35+
stage:
36+
- crystal-snap-wrapper

0 commit comments

Comments
 (0)