Specifying the version of Crystal in Homebrew

Is it possible to specify an older version of Crystal in Homebrew?

I ask because I’m working on a package that currently depends on 0.31.1 which I can’t seem to download.

I know updating it to the latest version of Crystal is probably the best solution. But it concerns me that if a new version of Crystal is released it’s possible it will break my package for new downloads. I’d much rather like to specify the version of Crystal and update it safely in my own time.

As far as I’m aware, the build script is tailored specifically to building whatever version it provides you. Homebrew does keep older versions of some packages, but crystal is not one of them. I would suggest that you used crenv and crystal-build to manage your Crystal versions on your machine, rather than relying on homebrew.

That said, crystal-build is sort of in disrepair, and as far as I can tell, still has issues downloading more recent versions of Crystal, and the author doesn’t seem to be doing anything about it. I’m in the process of rewriting crystal-build, but I literally started today so it only does really basic installation of pre-packaged releases from GitHub. Because they’re pre-packaged and not compiled on your machine, you might have some weird library linking issues but it’s nothing that isn’t fixable.

If you decide you want to try it, download crenv, clone my repo into ~/.crenv/plugins, and build my project with crystal build --release src/build.cr -o bin/crenv-install. The compiled binary will need to be there in order for crenv install 0.32.1 to install properly.

That might be a lot to take in, let me know if you need help.

EDIT: Looks like the owner of the crenv and crystal-build repos literally just (10 minutes ago) posted some issues regarding looking for a new maintainer. The future is unclear, I guess.

Hi, thanks for the response :slight_smile:

I use ASDF to manage my Crystal versions - I should have mentioned, the problem is more to do with my own Homebrew package. I have a Homebrew package (https://github.com/Snipline/Snipcli) that depends on Crystal to compile.

This is the reason I’d like to be able to choose a Crystal version in Homebrew - to make sure anyone that downloads the package is getting the right version of Crystal to compile with.

It’s unfortunate to see that Homebrew only has the latest version of Crystal. I’ll have to have a think of the best way to work with this.

You could probably use GitHub’s API to grab a Crystal binary of the correct version. Just look up a release by the tag name, which is the same as a version number.

Hi @acoustep . No brew only show latest version of crystal. After 1.0, maybe there will be Major.Minor aliases but I am not sure.

The more stable source is downloading the specific .pkg or .tar.gz for Darwin from GitHub.

If you want to pin the brew formula for building is actually not that different from what the Crystal formula does.

It downloads the tar.gz from a specific url to build a binary that is installed by the formula. And the downloaded tar.gz is only temporally needed.

In your case you will need to keep the embedded gc or depend on the upstream one (as long as preview_mt is not used you should be fine with either).

Thanks for your help both :slight_smile:

I’ll look into pinning the Crystal version. For now, I’ve implemented a workaround with a compile time flag so that Homebrew can use 0.32.1 and Alpine Linux can use 0.31.1 (I use Alpine for building static Linux binaries but their version of Crystal seems to be behind).

# check current version:
$ crystal -v
Crystal 0.36.1 (2021-02-02)

LLVM: 11.0.1
Default target: x86_64-apple-macosx

# uninstall current version
$ brew unlink crystal

# delete any existing crystal formula, otherwise wget will call it crystal.rb.1 and the filename must be "crystal.rb"
$ rm ./crystal.rb

# download formula for 0.35.1 (or any older version of your choice)
$ wget https://github.com/Homebrew/homebrew-core/raw/c7ec86653662d2a92989eec744cc11d2ce59d84e/Formula/crystal.r

# verify new crystal version
$ crystal -v
Crystal 0.35.1 (2020-06-19)

LLVM: 9.0.1
Default target: x86_64-apple-macosx

# do it again for 0.31.1
$ brew unlink crystal ; rm ./crystal.rb

# download formula for 0.31.1
$ wget https://github.com/Homebrew/homebrew-core/raw/0a0246c1c8e3829862226346b27d98c47dd16925/Formula/crystal.rb

$ brew install ./crystal.rb

# verify new crystal version
$ crystal -v
Crystal 0.31.1 (2019-10-02)

LLVM: 8.0.1
Default target: x86_64-apple-macosx

browse for your version of choice: History for Formula/crystal.rb - Homebrew/homebrew-core · GitHub