Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snap target #39

Merged
merged 4 commits into from Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -6,3 +6,7 @@ omnibus/crystal-darwin-x86_64
docs/build/

darwin/build/

snapcraft/snap/snapcraft.yaml
snapcraft/*.snap
snapcraft/build/
15 changes: 15 additions & 0 deletions snapcraft/Makefile
@@ -0,0 +1,15 @@
OUTPUT_DIR = build

.PHONY: all
all: snap/snapcraft.yaml
mkdir -p $(OUTPUT_DIR)
snapcraft
mv *.snap $(OUTPUT_DIR)

.PHONY: snap/snapcraft.yaml
snap/snapcraft.yaml:
sed 's/$${CRYSTAL_RELEASE_LINUX64_TARGZ}/$(subst /,\/,$(CRYSTAL_RELEASE_LINUX64_TARGZ))/; s/$${SNAP_GRADE}/$(SNAP_GRADE)/' snap/local/snapcraft.yaml.tpl > snap/snapcraft.yaml

clean:
rm snap/snapcraft.yaml
rm -Rf $(OUTPUT_DIR)
52 changes: 52 additions & 0 deletions snapcraft/README.md
@@ -0,0 +1,52 @@
# snap for Crystal

https://snapcraft.io/crystal

## Dependencies

- [`snapcraft`](https://docs.snapcraft.io/snapcraft-overview)

## Build the snap

Define the configuration variables and use `make` to expand the `./snap/local/snapcraft.yaml.tpl`.

```sh
$ 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
```

## Snap channels usage

| Build | Channel | Version | Comments |
|-------------------|----------------------------|-----------|------------------------------------------------------|
| tagged release | latest/edge | M.m.p | manual set to beta, candidate, stable upon release |
| nighties release | latest/edge | M.m.p-dev | |
| maintenance build | latest/edge/${branch-name} | M.m.p-dev | |

### Configuration

* `CRYSTAL_RELEASE_LINUX64_TARGZ`: Url to crystal-{version}-{package}-linux-x86_64.tar.gz
* `SNAP_GRADE`: Snap grande usually `devel` for nightlies and `stable` for tagged releases

## Install the snap

1. [Have snapd installed](https://snapcraft.io/docs/core/install)

2.
```
$ sudo snap install crystal --classic
```

## Post-Install

This snap ships the compiler, all required native libraries should be available on the host.

The following are the suggested packages to be able to use the whole standard library capabilities.

```
$ sudo apt-get install gcc pkg-config git tzdata \
libpcre3-dev libevent-dev libyaml-dev \
libgmp-dev libssl-dev libxml2-dev
```

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.

30 changes: 30 additions & 0 deletions snapcraft/crystal-snap-wrapper
@@ -0,0 +1,30 @@
#!/bin/sh

if [ ! -f $SNAP_USER_COMMON/env-check-success ]; then
# check if a simple program can be compiled
# if something fails show a banner to the user

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the general wrapper which you use to run crystal in snap? Compiling even a little program would delay the actual compiler boot time and make it appear to be slow.
Can't there be a different solution to this? Maybe use the actual error code from the invoked crystal command?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be another way to do it but exec is used to run the compiler and I don't think something can be done after that.

Using exec to delegate is better so the wrapper is more transparent.

As soon as the env is verified once the check will no longer run so is a one time delay.

Unfortunately, there is no support for post-installation messages on snap for now. I would have preferred to do it that way.

$SNAP/bin/crystal eval 'puts "1"' >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
touch $SNAP_USER_COMMON/env-check-success
else
cat <<EOF

It seems that some libraries are missing in your host.
The following are the suggested packages to be able to use the whole standard library capabilities.

$ sudo apt-get install gcc pkg-config git tzdata \\
libpcre3-dev libevent-dev libyaml-dev \\
libgmp-dev libssl-dev libxml2-dev

You can find more detailed information in:

* https://crystal-lang.org/reference/installation/on_debian_and_ubuntu.html
* https://github.com/crystal-lang/crystal/wiki/All-required-libraries

EOF

fi
fi

exec $SNAP/bin/crystal "$@"
36 changes: 36 additions & 0 deletions snapcraft/snap/local/snapcraft.yaml.tpl
@@ -0,0 +1,36 @@
name: crystal
base: core
summary: A language for humans and computers
description: |
* Have a syntax similar to Ruby (but compatibility with it is not a goal)
* Statically type-checked but without having to specify the type of variables or method arguments.
* Be able to call C code by writing bindings to it in Crystal.
* Have compile-time evaluation and generation of code, to avoid boilerplate code. Compile to efficient native code.
adopt-info: crystal

grade: ${SNAP_GRADE}
confinement: classic

environment:
SHARDS_CACHE_PATH: $SNAP_USER_COMMON/.cache/shards
CRYSTAL_CACHE_DIR: $SNAP_USER_COMMON/.cache/crystal

apps:
crystal:
command: crystal-snap-wrapper
shards:
command: bin/shards

parts:
crystal:
plugin: dump
source: ${CRYSTAL_RELEASE_LINUX64_TARGZ}
override-pull: |
snapcraftctl pull
snapcraftctl set-version "$(cat $SNAPCRAFT_PART_SRC/share/crystal/src/VERSION | head -n 1)"

snap-wrapper:
plugin: dump
source: .
stage:
- crystal-snap-wrapper