Clarify output of `crystal --version`

The crystal --version commands prints which Crystal version is being used. Currently, the output looks like this (using the latest APT package):

$ crystal --version
Crystal 0.31.1 [0e2e1d067] (2019-09-30)

LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu

It prints the release version, followed by the release commit and a date.

I’m not sure whether there is an established guideline whether this is supposed to be the release date or build date. I think this should be clarified to avoid confusions. The difference is relevant for source distribution channels where the compiler is build by the package manager instead of using the pre-built distribution binary.

When using the source tarball from GitHub for building the compiler, it does not include commit hash. This makes it difficult to include it in the build process because it needs to be manually specified additionally to the version number. This would be error prone. That’s why the Alpine Linux package has opted to exclude the commit hash from the output (see patch).

If the date is supposed to represent the commit date, this would pose a similar problem.
Maybe a solution could be to provide source tarballs including commit info, separately from the GitHub tarballs.

This came up in the package for Alpine Linux (see Discussion). The current status (no commit hash, date is build date) is certainly acceptable, but I’d like to verify whether that’s fine or we should take some kind of action to improve this.
I guess we could at least improve the version command so that Alpine package doesn’t need to be patched to disable printing the commit hash.

1 Like

Hi, is there a programmatically way to print the crystal version only?

what i expected is, crystal eval 'puts SOME_CONST', to get 1.5.0, basically the same way for ruby. ruby -e 'puts RUBY_VERSION'.

Following bash script works, but i perfer the programmatically way to avoid external dependency.

 ╰─ $ crystal version |head -n1 |cut -d' ' -f2

crystal eval puts Crystal::VERSION

1 Like
$ crystal env CRYSTAL_VERSION

Thanks, i forget to use crystal env again …