Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building native CLI tools with Clojure on GraalVM

Building native CLI tools with Clojure on GraalVM

A long time ago in a galaxy far, far away... Clojure had garnered the reputation of being a heavy weight tool ideal only for server deployments on the JVM. Added together with its dynamic nature, full native compilation needed for fast and portable CLI tools seemed a fantasy. Until now...

Learn about using the GraalVM to build such tools while still using the best language ever.

Rahul De

June 12, 2019
Tweet

More Decks by Rahul De

Other Decks in Programming

Transcript

  1. About me (❤ FOSS) (" Diversity)
 (❤ Sustainable Living) (

    Vegan Food) (constantly [:❤ :Clojure]) Backend and Infrastructure Developer Compilers, VMs and High Performance https://github.com/lispyclouds https://twitter.com/lispyclouds
  2. CLI tools and native compilation Instant startup time ⚡ Easy

    and lightweight installation Short lived commands & Portable and easy distributions without too much system requirements Low resource consumption Simple, obvious naming convention and intuitive CLI arguments
  3. Clojure and the JVM Clojure is dynamic JVM reflection The

    JVM byte code itself is dynamic JIT and the design of the JVM
  4. Rust Immutable by default with functional features Super fast Fully

    AOT compiled GC less automatic memory management Safe Low resource consumption Slow compile times Less mature libs
  5. Haskell For me, the only other thing as cool as

    Clojure! Fast compiled binaries Very very safe Mature Slow compile times Practically zero dev tooling, slow dev iterations High memory consumption at times
  6. Python Very mature Pre installed in most *nix systems Dynamic

    Vast and mature tooling and libs Imperativeness is idiomatic Concurrency is hard Package management is hard Unpredictable resource consumption
  7. Go Super fast compile times Ubiquitous in CLI world Easy

    deployment Vast stdlib Imperative, difficult to write FP Not a productive language IMO for large projects
  8. ClojureScript Runs on Node.js (Lumo) or JavaScriptCore (Planck) Quick startup

    without JVM overhead Decent stdlib support from Node world Mature and robust libs missing from JVM world Poor parallelism High memory consumption Complex deployment and not available for archs other than AMDx64
  9. – The Oracle (probably not the one you’re thinking of)

    “When all hope was lost, there came our savior.”
  10. The one VM to rule them all? An umbrella project

    of various tools Works via the JVMCI since JDK 9 A JIT written in Java Natively available since JDK 10 Full Polyglot capabilities Truffle SDK Full native image generation with GC using SubstrateVM. (Great way to warm up your room) https://www.graalvm.org
  11. Wendy: Bob’s reference CLI and his SO Bob is a

    scalable, modular CI/CD platform (by your’s truly) 
 https://github.com/bob-cd/bob exposed via REST. Wendy should be able to: Make HTTP calls Parse JSON Parse TOML build configuration Provide a full CLI to Bob via intuitive command line args Verify the build and plan the execution order (magical to write in Clojure) Stream build status, info, logs and artifacts from Bob (think Docker CLI) https://github.com/bob-cd/wendy Was in Python 3 untill the fateful commit aba8aad
  12. Building Wendy Standard Tool Wendy’s Choice HTTP Calls clj-http clj-http-lite

    JSON Parsing cheshire cheshire TOML Parsing clj-toml Night-Config
 (really cool lib!) CLI args parsing • tools.cli • clj-matic argparse4j