Recommended way to develop a command-line app in Clojure

94 views
Skip to first unread message

Alex Corcoles

unread,
Jun 21, 2021, 2:58:18 PMJun 21
to Clojure

I want to develop a CLI tool based on instaparse; basically I want to do:

$ instaparse-cli my-grammar.abnf random-file

And have that command spout a JSON AST of random-file according to my-grammar. I would like to distribute this in a convenient way for my team-mates, without spending a ton of effort in setting up a development environment + project build system (I'm guessing this will be a very very short program).

My understanding is that Graal + Clojure is not easy right now (from checking the docs), so although I'm much more familiar with the Java ecosystem than with the JavaScript ecosystem, I'm thinking ClojureScript + nexe is the way to go? That would let me produce macOS + Linux + Windows static binaries that my team-mates can just drop in their path without installing anything else, I believe.

If I go ClojureScript + nexe, is there a good project template for that or a sample project I can replicate that does something like this? I see lein, boot, lumo, and others, and it's a bit hard to choose which one is easiest to use.

Thanks,

Álex

Alex Corcoles

unread,
Jun 21, 2021, 3:01:51 PMJun 21
to Clojure
Actually, while doing some more research I stumbled into:


Which is basically what I want to do- and it points to yet-another-build-tool: https://github.com/thheller/shadow-cljs

Christopher Small

unread,
Jun 22, 2021, 1:28:09 AMJun 22
to Clojure
If you want quick-running (sans JVM/Clojure startup time) and would rather stick with the JVM Clojure paradigm over Cljs, I'd highly recommend looking at babashka:


The setup is super easy, you get access to a lot of the basic JVM classes, and it comes with quite a few batteries included. I don't know if instaparse is compatible, but there's a good chance that with a little bit of work it could be made to be (assuming it isn't already).

I have absolutely loved using it lately for all manner of sundry scripting tasks.

Chris

Alex Corcoles

unread,
Jun 23, 2021, 2:57:19 AMJun 23
to Clojure
On Tuesday, June 22, 2021 at 7:28:09 AM UTC+2 metas...@gmail.com wrote:
If you want quick-running (sans JVM/Clojure startup time) and would rather stick with the JVM Clojure paradigm over Cljs, I'd highly recommend looking at babashka:


Thanks!

In the end, I decided to try the GraalVM route and got something working:


I can build binaries for Windows/macOS/Linux using GitHub Actions. The GraalVM compilation process is very resource-intensive, but the resulting binary (while huge ~40mb), seems very very fast.

Cheers,

Álex

matthew...@gmail.com

unread,
Jun 23, 2021, 10:53:04 AMJun 23
to Clojure
It's also probably worth testing out writing something in "normal" Clojure and compiling it to an uberjar instead of running it via lein / clj, because depending on what "fast" means to you, a normal jar will often fit the bill, since the JVM itself starts in ~100ms.   

Alex Corcoles

unread,
Jun 23, 2021, 11:55:04 AMJun 23
to Clojure
Hi,

On Wednesday, June 23, 2021 at 4:53:04 PM UTC+2 matthew...@gmail.com wrote:
It's also probably worth testing out writing something in "normal" Clojure and compiling it to an uberjar instead of running it via lein / clj, because depending on what "fast" means to you, a normal jar will often fit the bill, since the JVM itself starts in ~100ms.

Actually, during testing I run using the JVM, because creating the binary is *REALLY* slow and unsuitable for development. Even for a very simple program, it takes around 2s to run the uberjar. Which is decent for development purposes, but it mean I'd need extra complexity for my target use.

The GraalVM binary runs in about one tenth of a second, which is really impressive. The other advantage is that I need to distribute this on a couple of workstations, including Windows/macOS/Linux, and a single binary is *easier* (but not really *better* in all senses).

I'm wondering if ClojureScript + nexe would work better (faster compiles, smaller binaries?), but now that I have something working I'm not really in the mood for further investigation.

Cheers,

Álex
Reply all
Reply to author
Forward
0 new messages