Datalevin can be compiled as a GraalVM native image.
Assuming that you can build JVM Datalevin already, i.e. you have JDK and lein, here are the steps to build native Datalevin binary on your platform.
script/compile
.If the compilation is successful, two binaries will appear in this directory:
dtlv
and dtlv-test
. The former is the Datalevin command line shell, and the
latter runs all the Datalevin tests in native mode. These are standalone
executable that you can immediately run.
Same as the above, except to run script/compile.bat
instead in step 3.
If the build is successful, you will get dtlv.exe
and dtlv-test.exe
.
If your application depends on Datalevin library, and you want to compile your
application into a GraalVM native image, you need to use org.clojars.huahaiy/datalevin-native
as the dependency, instead of datalevin/datalevin
.
datalevin-native
includes GraalVM specific native
code
that are pre-compiled for various platforms.
Like all Clojure applications, class initialization needs to be done at native image
build time,
otherwise, native image build will fail due to link errors. During the native
image build time, our class initialization code extracts native libraries from
the datalevin-native
jar and put them in the GraalVM's default CLibraryPath
for the platform (e.g. ${GRAALVM_HOME}/lib/svm/clibraries/linux-amd64/
). The
files will be deleted on JVM exit.
If you are uncomfortable with writing the default location or lack the write
permission for that directory, you can set an environment variable
DTLV_LIB_EXTRACT_DIR
in the shell doing the native image build, and the native
libraries will then be put there instead. If so, you must also add
-H:CLibraryPath=${DTLV_LIB_EXTRACT_DIR}
option in your native image build command
line. The directory referred to by the environment variable must exist and is
writable.
Once built, Datalevin's native dependencies are linked into your image statically.
For CI/CD, you may want to consult our Github Action (for Linux/MacOS) and Appveoyor (for Windows) yaml files for examples.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close