All Projects → taylorwood → Clj.native Image

taylorwood / Clj.native Image

Licence: mit
Build GraalVM native images with Clojure Deps and CLI tools

Programming Languages

clojure
4091 projects

Labels

Projects that are alternatives of or similar to Clj.native Image

Tmux Fzf Url
🚀 Quickly open urls on your terminal screen!
Stars: ✭ 227 (-3.81%)
Mutual labels:  cli
Bombardier
Fast cross-platform HTTP benchmarking tool written in Go
Stars: ✭ 2,952 (+1150.85%)
Mutual labels:  cli
Docker Dashboard
Console based docker dashboard
Stars: ✭ 235 (-0.42%)
Mutual labels:  cli
Ssr Helper
A CLI helper of ShadowsocksR Python
Stars: ✭ 230 (-2.54%)
Mutual labels:  cli
Wpk
a friendly, intuitive & intelligent CLI for webpack
Stars: ✭ 232 (-1.69%)
Mutual labels:  cli
Clean Css Cli
The command line interface to clean-css CSS optimizer
Stars: ✭ 231 (-2.12%)
Mutual labels:  cli
Awesomescripts
A Collection of Awesome Scripts in Python to Ease Daily-Life. Create an issue If you have some great idea for the new script. Leave a ⭐️
Stars: ✭ 228 (-3.39%)
Mutual labels:  cli
Wapm Cli
📦 WebAssembly Package Manager (CLI)
Stars: ✭ 236 (+0%)
Mutual labels:  cli
Git Deps
git commit dependency analysis tool
Stars: ✭ 232 (-1.69%)
Mutual labels:  cli
Serve
a static http server anywhere you need one.
Stars: ✭ 233 (-1.27%)
Mutual labels:  cli
Alert After
Get a desktop notification after a command finishes executing.
Stars: ✭ 230 (-2.54%)
Mutual labels:  cli
Gomi
🗑️ Replacement for UNIX rm command!
Stars: ✭ 229 (-2.97%)
Mutual labels:  cli
Forge
F# CLI tool for project, file, and solution management
Stars: ✭ 233 (-1.27%)
Mutual labels:  cli
Ten Hands
⚡ Simplest way to organize and run command-line tasks
Stars: ✭ 228 (-3.39%)
Mutual labels:  cli
Meow
🐈 CLI app helper
Stars: ✭ 2,839 (+1102.97%)
Mutual labels:  cli
Cli Prompt
Allows you to prompt for user input on the command line, and optionally hide the characters they type
Stars: ✭ 228 (-3.39%)
Mutual labels:  cli
Sequelize Auto Migrations
Migration generator && runner for sequelize
Stars: ✭ 233 (-1.27%)
Mutual labels:  cli
Figgo
👯‍♀️A cli tool makes your Figma and local design token stay in sync 👯‍♂️
Stars: ✭ 235 (-0.42%)
Mutual labels:  cli
Ncpamixer
ncurses PulseAudio Mixer
Stars: ✭ 234 (-0.85%)
Mutual labels:  cli
Ace
Node.js framework for creating command line applications
Stars: ✭ 233 (-1.27%)
Mutual labels:  cli

clj.native-image

Build GraalVM native images using Clojure Deps and CLI tools.

This should be useful for creating lightweight, native CLI executables using Clojure and deps.edn. See clj.native-cli for a starter project template.

This project depends on tools.deps.alpha and should be considered alpha itself.

Prerequisites

  • Clojure CLI tools

  • GraalVM

    NOTE: As of GraalVM 19.0.0, native-image is no longer included by default:

    Native Image was extracted from the base GraalVM distribution. Currently it is available as an early adopter plugin. To install it, run: gu install native-image. After this additional step, the native-image executable will be in the bin directory, as for the previous releases.

    ➜ $GRAALVM_HOME/bin/gu install native-image
    Downloading: Component catalog from www.graalvm.org
    Processing component archive: Native Image
    Downloading: Component native-image: Native Image  from github.com
    Installing new component: Native Image licence files (org.graalvm.native-image, version 19.0.0)
    

Usage

Assuming a project structure like this:

.
├── deps.edn
└── src
    └── core.clj

In your deps.edn specify an alias with a dependency on clj.native-image:

{:aliases {:native-image
           {:main-opts ["-m clj.native-image core"
                        "--initialize-at-build-time"
                        ;; optional native image name override
                        "-H:Name=core"]
            :jvm-opts ["-Dclojure.compiler.direct-linking=true"]
            :extra-deps
            {clj.native-image/clj.native-image
             {:git/url "https://github.com/taylorwood/clj.native-image.git"
              :sha "7708e7fd4572459c81f6a6b8e44c96f41cdd92d4"}}}}}

Where core.clj is a class with -main entrypoint, for example:

(ns core
  (:gen-class))
(defn -main [& args]
  (println "Hello, World!"))

From your project directory, invoke clojure with the native-image alias, specifying the main namespace (core in example above):

➜ clojure -A:native-image
Loading core
Compiling core
Building native image 'core' with classpath 'classes:src:etc.'

   classlist:   1,944.26 ms
   8<----------------------
     [total]:  38,970.37 ms

Note: Either GRAALVM_HOME environment variable must be set, or GraalVM's native-image path must be passed as an argument, and any additional arguments will be passed to native-image e.g.:

➜ clojure -A:native-image --verbose

You can now execute the native image:

➜ ./core
Hello, World!

See this Gist for another example.

Example Projects

There are example deps.edn projects in the lein-native-image repo:

  • jdnsmith - CLI JSON-to-EDN transformer
  • http-api - simple HTTP API server
  • clojurl - cURL-like tool using clojure.spec, HTTPS, hiccup

Caveats

The --no-server flag is passed to native-image by default, to avoid creating orphaned build servers.

Also see caveats section of lein-native-image.

References

GraalVM Native Image AOT Compilation

This project was inspired by depstar.

Contributing

You'll need Clojure CLI tooling and GraalVM installed to test locally. Just change the source of the clj.native-image dependency to a :local/root instead of :git/url.

Issues, PRs, and suggestions are welcome!

License

Copyright © 2018 Taylor Wood.

Distributed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].