I am trying to use the aantron/luv library to try to build something and I ran into all kinds of build system issues mostly because I still haven't grokked the reason-native build system yet. That's ok. This note is my way of getting better and having a reference I understand when I need to come back to it. The reason-native build environment has a list of great tools you can use. Most prominent among them are Dune, Esy/Pesy and Spin. The last two use dune so you end up learning about dune whatever you do.
Let's start with dune. Assuming you have opam and dune installed this is easy. Go here if you don't then head back.
Make a directory and cd into it.
mkdir straight-dune-luv && cd straight-dune-luv
Add a .gitignore file for ocaml using the gitignore-cli.
gi ocaml > .gitignore
Create a switch with ocaml 4.08.1. luv requires at least that.
opam switch create . ocaml-base-compiler.4.08.1
Add reason and luv. dune will tell you nicely if you forget to do this.
opam install reason luv
Create you dune file and run install.
touch dune && dune install
Create a Makefile, optional. I just copied the one from a previous post here.
touch Makefile
Which didn't work because of the tabs being off from the paste. Ran cat -e -t -v Makefile which I found on stackoverflow.
Add the code from aantron/luv/example/progress.ml.
touch progress.ml
Convert it to .re and delete the .ml version.
bsrefmt --parse ml progress.ml --print re > progress.re
rm progress.ml
Run make to build it.
make
Run progress.exe.
dune exec ./progress.exe
Output:
❯ dune exec ./progress.exe
33%
66%
Done
Honestly, that was very easy. This has to be your go to build for a simple project. Source can be found here
Let's try with Pesy next.
Top comments (4)
That's super cool, Michael! I love the JSX-like syntax for the string formatting. Btw, one of the images in the post is not rendering. It looks like it's not hosted right now, for whatever reason. But overall that's a great intro to building CLI apps. :)
Nice! I've been meaning to dive into native ReasonML soon, so it's nice to see some simple, straightforward tutorials on stuff like build tools.
There is no ReasonML without OCaml, brother. That is the truth of it for me so I have to make these notes to figure out/remember how to do some thing. OCaml ecosystem is deep. I haven't even touched
oasisocamlbuildetc. Once you get a little bit of a hold on it though, you get how powerful it is and you want more! Have at it. Share what you learn, please.@austin what image is not rendering, brother?