2019-05-11 19:23:20 +00:00
|
|
|
---
|
|
|
|
layout: post
|
|
|
|
title: "Elm on FreeBSD"
|
|
|
|
date: 2019-05-11
|
|
|
|
comments: true
|
|
|
|
tags: freebsd, elm, linux
|
|
|
|
---
|
|
|
|
|
|
|
|
[Elm](https://elm-lang.org/) is a purely functional, strongly typed language for
|
|
|
|
building web-apps. I recently started playing with elm[^1] and so far love it!
|
|
|
|
|
|
|
|
There was a small bit of trouble though, Elm doesnt officially support
|
|
|
|
FreeBSD. The compiler is written in Haskell and
|
|
|
|
[couple](https://discourse.elm-lang.org/t/running-elm-on-freebsd/1613)
|
|
|
|
of
|
|
|
|
[people](https://gist.github.com/vyuh/ff05a20cb0f408e1fd0ac8c23d06025b)
|
|
|
|
have made it work on freebsd by compiling from source.
|
|
|
|
|
|
|
|
That's where I started, and soon gave up because compiling `elm 0.19`
|
|
|
|
needs `ghc-8.2.2`. That particular ghc version is no longer in binary
|
2019-05-11 19:26:59 +00:00
|
|
|
packages. Stack ghcs are still [broken on
|
2019-05-11 19:23:20 +00:00
|
|
|
FreeBSD](https://blog.dbalan.in/blog/2019/01/08/recurse-center-day-%23-2/index.html)
|
|
|
|
to try that route. All of the solutions I encountered builds ghc from
|
|
|
|
source and that was going take an eternity on my thinkpad.
|
|
|
|
|
|
|
|
Luckily elm project provides binaries for Linux - and FreeBSD
|
|
|
|
[can pretend to be
|
|
|
|
linux](https://www.freebsd.org/doc/handbook/linuxemu.html) pretty
|
|
|
|
well. Thats what I ended up doing!
|
|
|
|
|
|
|
|
1. Load the kernel module for linux emulation.
|
|
|
|
|
|
|
|
```
|
|
|
|
kldload linux64.ko
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Get elm [linux binary from github](https://github.com/elm/compiler/releases).
|
|
|
|
|
|
|
|
```
|
|
|
|
wget \
|
|
|
|
https://github.com/elm/compiler/releases/download/0.19.0/binaries-for-linux.tar.gz
|
|
|
|
tar xf binaries-for-linux.tar.gz
|
|
|
|
```
|
|
|
|
|
|
|
|
3. Then [brand the ELF
|
|
|
|
binary](https://www.freebsd.org/cgi/man.cgi?query=brandelf&sektion=1&manpath=freebsd-release-ports)
|
|
|
|
as type `Linux`. Kernel uses this information check decide runtime
|
|
|
|
to use, in our case Linux emulation.
|
|
|
|
|
|
|
|
```
|
|
|
|
brandelf -t Linux ./elm
|
|
|
|
```
|
|
|
|
|
|
|
|
..and there we have it
|
|
|
|
```
|
|
|
|
$ file elm
|
|
|
|
elm: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, with debug_info, not stripped
|
|
|
|
|
|
|
|
$ ./elm
|
|
|
|
Hi, thank you for trying out Elm 0.19.0. I hope you like it!
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
[^1]: Shout-out to Tenor and Liz for introducing me to Elm.
|