Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active January 6, 2020 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sogaiu/e079cd770051685c46ab24b6658effcf to your computer and use it in GitHub Desktop.
Save sogaiu/e079cd770051685c46ab24b6658effcf to your computer and use it in GitHub Desktop.
Graal native-image Building Setup on Windows (for Clojure Programs)

Graal native-image Building Setup on Windows (for Clojure Programs)

Background

A deps.edn-based approach is currently blocked because Graal’s native-image requires being run from a special command prompt that comes with Windows SDK 7.1, while the current clojure / clj tooling appears to require being launched via PowerShell.

A work-around using Leiningen and a .bat file (using a non-PowerShell command prompt), was determined by borkdude.

This document is mostly about Java 8 based GraalVMs. For Java 11 based GraalVMs, the process is considerably simpler:

choco install visualstudio2017community --version 15.9.17.0 --no-progress --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --add Microsoft.VisualStudio.Component.VC.CMake.Project"

Requirements

  • Windows 7 or later (tested on 7 and 10)

  • Windows SDK 7.1

  • Graal 19 or later (leads to installation of native-image)

  • Leiningen

  • Some Clojure Project that’s amenable to native-image-building (e.g. clj-kondo)

Steps

1. Install Windows SDK 7.1

Installing Windows SDK 7.1 may be done via Chocolatey — the relevant command is: choco install windows-sdk-7.1. On Windows 10, an extra download and installation was required. This was unnecessary on Windows 7.

It may be that the following is enough (untested):

choco install -d windows-sdk-7.1 kb2519277

2. Install native-image

native-image is obtainable via Graal. From version 19, to make our lives interesting, after getting Graal, we are now required to run another command to get native-image :(

3. Install Leiningen

This can be done in a variety of ways. It appears doable via the Leiningen site, I was happy to do it via scoop.

4. Build Uberjar with Leiningen

In project.clj, be sure to choose :aot :all. Other things may be necessary, see clj-kondo’s project.clj.

5. Build via native-image

Use the -jar option to native-image, specifying the uberjar created in the previous step. Note that this native-image building needs to be performed via the Windows SDK 7.1 command prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment