Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM native-image build support #337

Merged
merged 29 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4f4bdf1
Use konserve synchronous IO. Support native-image compilation.
whilo Oct 20, 2022
59dbc32
Remove sleeping to make times match.
whilo Oct 20, 2022
d5c13a9
Handler InterruptedException.
whilo Oct 20, 2022
2eacfe0
ci: add pipeline for native-image
TimoKramer Oct 21, 2022
b0fe304
fixup! ci: add pipeline for native-image
TimoKramer Oct 21, 2022
28494cb
336 native image cli (#568)
TimoKramer Oct 24, 2022
e2c4b9f
ci: correct env backward-compatibility-tests (#569)
TimoKramer Oct 26, 2022
e469fdf
changed ci and script to improve local run (#570)
TimoKramer Oct 26, 2022
b239761
from-datom slipped in again during rebase; remove.
whilo Oct 27, 2022
31055b9
Use released versions of hh-tree and konserve.
whilo Oct 28, 2022
b8c1e32
ci: add native-image test (#573)
TimoKramer Oct 28, 2022
063bdc2
Try konserve version that detects small headers for backwards compat.
whilo Nov 3, 2022
57cce0a
Use release version of konserve
jsmassa Nov 4, 2022
19f9520
Merge main.
whilo Nov 19, 2022
04b5f23
Fix reflection error.
whilo Nov 19, 2022
45b55e0
Merge branch 'main' into 336-native-image-cli
whilo Nov 19, 2022
a09170c
Update Java API, export as native shared lib, update native cli.
whilo Nov 22, 2022
75ac81c
Add resources.
whilo Nov 22, 2022
4f49b08
Complete CLI interface.
whilo Nov 24, 2022
c82c41a
Update help for cli.
whilo Nov 24, 2022
4eb5a39
Add CBOR serialization.
whilo Nov 27, 2022
64a3bb8
Fix format.
whilo Nov 27, 2022
e828a8d
Support different formats for transact piping and inputs.
whilo Nov 27, 2022
8c4eabb
Handle variable input/output formats, exceptions in shared library.
whilo Dec 5, 2022
bc79b05
Handle memory of return type through callback.
whilo Dec 8, 2022
5beae77
Complete first stage shared library and cli.
whilo Dec 9, 2022
2f7eb05
Fix cicrcleci path to cli.
whilo Dec 9, 2022
a741c26
Ensure UTF8 encoding.
whilo Dec 9, 2022
6438662
Use base64 encoding for CBOR for now to avoid char* truncation.
whilo Dec 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 64 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- deps-
- run:
name: resolve deps
command: clojure -P
command: clojure -A:dev:test:build -P
jsmassa marked this conversation as resolved.
Show resolved Hide resolved
- save_cache:
key: deps-{{ checksum "deps.edn" }}
paths:
Expand Down Expand Up @@ -59,19 +59,64 @@ jobs:
at: /home/circleci
- run:
name: clean
command: clojure -Sthreads 1 -T:build clean
command: clojure -T:build clean
- run:
name: compile
command: clojure -Sthreads 1 -T:build compile
command: clojure -T:build compile
- run:
name: jar
command: clojure -Sthreads 1 -T:build jar
command: clojure -T:build jar
- persist_to_workspace:
root: /home/circleci/
paths:
- .m2
- .npm
- replikativ
native-image:
machine:
image: ubuntu-2004:202010-01
resource_class: large
steps:
- attach_workspace:
at: /home/circleci
- run:
name: install graalvm
command: |
cd /home/circleci
wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.2.0/graalvm-ce-java17-linux-amd64-22.2.0.tar.gz
tar -xzf graalvm-ce-java17-linux-amd64-22.2.0.tar.gz
export PATH=/home/circleci/graalvm-ce-java17-22.2.0/bin:$PATH
export JAVA_HOME=/home/circleci/graalvm-ce-java17-22.2.0/
gu install native-image
- run:
name: install clojure
command: |
cd /home/circleci
curl -O https://download.clojure.org/install/linux-install-1.11.1.1165.sh
chmod +x linux-install-1.11.1.1165.sh
./linux-install-1.11.1.1165.sh --prefix /home/circleci/clojure
- run:
name: build native-image
command: |
cd /home/circleci/replikativ
export PATH=/home/circleci/graalvm-ce-java17-22.2.0/bin:/home/circleci/clojure/bin:$PATH
export JAVA_HOME=/home/circleci/graalvm-ce-java17-22.2.0/
./bin/build-native-image
- persist_to_workspace:
root: /home/circleci/
paths:
- replikativ/dhi
native-image-test:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: Run native-image test
command: |
cd /home/circleci/replikativ
./bin/run-native-image-tests
no_output_timeout: 5m
backward-compatibility-test:
executor: tools/clojurecli
steps:
Expand All @@ -96,7 +141,7 @@ jobs:
at: /home/circleci
- run:
name: deploy
command: clojure -Sthreads 1 -T:build deploy
command: clojure -T:build deploy

workflows:
build-test-and-deploy:
Expand All @@ -108,6 +153,10 @@ workflows:
context: dockerhub-deploy
requires:
- setup
- native-image:
context: dockerhub-deploy
requires:
- setup
- tools/format:
context: dockerhub-deploy
requires:
Expand All @@ -116,14 +165,22 @@ workflows:
context: dockerhub-deploy
requires:
- build
- native-image
- native-image-test:
context: dockerhub-deploy
requires:
- build
- native-image
- backward-compatibility-test:
context: dockerhub-deploy
requires:
- build
- native-image
- tools/integrationtest:
context: dockerhub-deploy
requires:
- build
- native-image
- deploy:
context:
- dockerhub-deploy
Expand All @@ -136,6 +193,7 @@ workflows:
- tools/format
- tools/unittest
- backward-compatibility-test
- native-image-test
- tools/integrationtest
- tools/release:
context:
Expand All @@ -145,4 +203,4 @@ workflows:
branches:
only: main
requires:
- deploy
- deploy
2 changes: 1 addition & 1 deletion .dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
((clojure-mode . ((cider-preferred-build-tool . clojure-cli)
(cider-clojure-cli-aliases . ":dev:test"))))
(cider-clojure-cli-aliases . ":dev:test:libdatahike"))))
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ out/
/.settings
.classpath
/.clj-kondo
/datahike
datahike.build_artifacts.txt
tests.user.edn
/libdatahike/target
9 changes: 9 additions & 0 deletions bin/build-native-image
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

if ! $(builtin type -P native-image &> /dev/null); then
echo "PATH does not contain native-image. Make sure to add your GraalVM to it."
exit 1
else
clojure -T:build compile
clojure -M:native-cli --no-fallback "-J-Xmx4g"
fi
41 changes: 41 additions & 0 deletions bin/run-native-image-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

TMPSTORE=/tmp/dh-test-store

trap "rm -rf $TMPSTORE" EXIT

./dhi delete-database bin/testconfig.edn
./dhi create-database bin/testconfig.edn

./dhi database-exists bin/testconfig.edn

./dhi benchmark conn:bin/testconfig.edn 0 100000 10000
./dhi transact conn:bin/testconfig.edn '[[:db/add -1 :name "Judea"]]'
QUERY_OUT=`./dhi query '[:find (count ?e) . :where [?e :name _]]' db:bin/testconfig.edn`

if [ $QUERY_OUT -eq 100001 ]
then
echo "Test successful."
else
echo "Exception: Query did not return correct value."
fi

# test history input parsing
./dhi query '[:find (count ?e) . :where [?e :name _]]' history:bin/testconfig.edn
./dhi query '[:find (count ?e) . :where [?e :name _]]' since:0:bin/testconfig.edn
./dhi query '[:find (count ?e) . :where [?e :name _]]' asof:0:bin/testconfig.edn

# other calls
./dhi pull db:bin/testconfig.edn "[:db/id, :name]" "1"
./dhi pull-many db:bin/testconfig.edn "[:db/id, :name]" "[1]"
./dhi entity db:bin/testconfig.edn "1"
./dhi datoms db:bin/testconfig.edn "{:index :eavt :components [1]}"
./dhi schema db:bin/testconfig.edn
./dhi reverse-schema db:bin/testconfig.edn
./dhi metrics db:bin/testconfig.edn

# test serialization
./dhi query '[:find ?e . :where [?e :name ?n]]' db:myconfig.edn --format cbor >> /tmp/test
./dhi query '[:find ?i :in $ ?i . :where [?e :name ?n]]' db:myconfig.edn cbor:/tmp/test # => 1

./dhi delete-database bin/testconfig.edn
4 changes: 4 additions & 0 deletions bin/testconfig.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:store {:backend :file
:path "/tmp/dh-test-store" }
:keep-history? true
:schema-flexibility :read}
24 changes: 23 additions & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) version))
(def native-shared-library-file (format "target/%s-%s-native-shared-library.jar"
(name lib) version))

(defn clean
[_]
Expand All @@ -21,7 +23,8 @@
(b/javac {:src-dirs ["java"]
:class-dir class-dir
:basis basis
:javac-opts ["-source" "8" "-target" "8"]}))
:javac-opts ["-source" "8" "-target" "8"]})
(spit "resources/DATAHIKE_VERSION" version))

(defn jar
[_]
Expand All @@ -37,6 +40,25 @@
(b/jar {:class-dir class-dir
:jar-file jar-file}))

(defn native-shared-library [_]
(clean nil)
(b/delete {:path "libdatahike/target"})
(compile nil)
(b/copy-dir {:src-dirs ["src" "resources" "libdatahike/src"]
:target-dir class-dir})
(let [basis (b/create-basis {:project "deps.edn"
:aliases [:libdatahike]})]
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["libdatahike/src"]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file native-shared-library-file
:basis basis
:main 'datahike.cli})))

(defn deploy
"Don't forget to set CLOJARS_USERNAME and CLOJARS_PASSWORD env vars."
[_]
Expand Down
18 changes: 15 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,24 @@

:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main" "fix"]}

:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.1" :git/sha "7d40500"}
slipset/deps-deploy {:mvn/version "0.2.0"}
borkdude/gh-release-artifact {:git/url "https://github.com/borkdude/gh-release-artifact"
:sha "a83ee8da47d56a80b6380cbb6b4b9274048067bd"}
babashka/babashka.curl {:mvn/version "0.1.2"}
babashka/fs {:mvn/version "0.1.4"}
cheshire/cheshire {:mvn/version "5.10.2"}}
:ns-default build}}}
cheshire/cheshire {:mvn/version "5.11.0"}}
:ns-default build}
:libdatahike {:main-opts ["-e" "(set! *warn-on-reflection* true)"]
:extra-paths ["libdatahike/src"]
:extra-deps {cheshire/cheshire {:mvn/version "5.11.0"}}}
:native-cli {:main-opts ["-e" "(set! *warn-on-reflection* true)"
"-m" "clj.native-image" "datahike.cli"
"--initialize-at-build-time"
"-H:Name=dhi"]
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]
:extra-deps
{cheshire/cheshire {:mvn/version "5.11.0"}
clj.native-image/clj.native-image
{:git/url "https://github.com/taylorwood/clj.native-image.git"
:sha "7708e7fd4572459c81f6a6b8e44c96f41cdd92d4"}}}}}
Loading