Native Image

Elide bundles Native Image and can compile your JVM program to a standalone native executable or native shared library. You can invoke the compiler directly with the elide native-image drop-in, or declare a Native Image artifact in your elide.pkl manifest and build it with elide build.

The Native Image artifact

Declare a Native Image in the artifacts block using the NativeImage type from elide:NativeImage.pkl. An image is built from one or more upstream artifacts (typically a JAR):

pkl
amends "elide:project.pkl"
import "elide:Jvm.pkl" as Jvm
import "elide:NativeImage.pkl" as Native

artifacts {
  ["app-jar"] = new Jvm.Jar {
    sources { "main" }
  }
  ["app"] = new Native.NativeImage {
    from { "app-jar" }
    entrypoint = "com.example.Main"
    type = "binary"
  }
}

Artifact fields

FieldTypeDefaultDescription
fromListing<String>{}Artifact names to build the image from
nameString?computedOutput name (binary or library); computed if omitted
entrypointString?noneEntry (main) class; use moduleName if it lives in a JPMS module
typeImageType"binary"binary (executable) or library (shared library)
moduleNameString?noneJPMS module holding the entrypoint, if applicable
optionsNativeImageOptions{}Compiler options for this artifact (see below)
A Native Image builds from other artifacts; there is no sources field on it (sources belongs to the JAR artifacts).

Compiler options

Set compiler options per artifact, inside that artifact's options block. The available options are:
OptionTypeDefaultDescription
verboseBooleanfalseVerbose compiler output
driverMode"embedded" \"external""embedded"Run Native Image in-process or as a sub-process
optimizationOptimizationLevel"auto"Optimization level (see below)
linkAtBuildTimeblockenabledLink-at-build-time default plus specific packages
classInitblockbuild-timeClass-initialization policy plus per-class/package overrides
pgoblockenabled with profilesProfile-Guided Optimization settings
exclusionsblockcompiler internalsMaven coordinates excluded from classpath/modulepath
featuresListing<JvmClass>{}Native Image Feature classes to enable
flagsListing<String>{}Extra flags for the Native Image compiler
cflagsListing<String>{}Extra flags for the C compiler
ldflagsListing<String>{}Extra flags for the native linker
defsMapping<String, String>{}System properties defined at build time

Project-wide settings

> The top-level nativeImage { } block is parsed but not currently applied — > its settings are not consumed by the build. Set all Native Image options **per > artifact**, inside that artifact's options { } block (above).

Optimization levels

The optimization value is one of auto (default), b (optimize for build speed), s (optimize for size), or 04 (increasing runtime performance). All values are strings.

Class initialization

Classes initialize at build time by default. Override the policy per class or package with the buildtime and runtime listings inside classInit.

Profile-Guided Optimization

PGO activates only when profiles are present. Build an instrumented image (pgo { instrument = true }) to produce a profile, then supply the collected profile file(s) via pgo { profiles { ... } } for the optimized build.