diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml index b13d14be..2c335361 100644 --- a/.github/workflows/clojure.yml +++ b/.github/workflows/clojure.yml @@ -2,9 +2,11 @@ name: Clojure CI on: push: - branches: "*" + branches: + - 'main' pull_request: - branches: [ "main" ] + branches: + - '**' jobs: build: @@ -12,17 +14,17 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - - name: Setup Java - uses: actions/setup-java@v3 + - name: Tools setup + uses: jdx/mise-action@v2 with: - # see: https://github.com/marketplace/actions/setup-java - distribution: 'corretto' - java-version: '11' - - name: Install clojure tools - uses: DeLaGuardo/setup-clojure@12.1 - with: - # see: https://github.com/marketplace/actions/setup-clojure - cli: 1.11.1.1429 + install: true + cache: true + - name: Tools config + run: | + echo "JAVA_HOME=$(mise where java)" >> $GITHUB_ENV + echo "GRAALVM_HOME=$(mise where java)" >> $GITHUB_ENV + echo "$(mise where java)/bin" >> $GITHUB_PATH + gu install native-image - name: Run tests run: make test - name: Run coverage tests @@ -32,4 +34,8 @@ jobs: - name: Run clj-kondo linter run: make lint - name: Run build jar - run: make clean build + run: make build + - name: Run build app + run: | + make build-native + build/clara-test-app this is a test invocation of native app diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 00000000..80048e18 --- /dev/null +++ b/.mise.toml @@ -0,0 +1,5 @@ +[plugins] +clojure = "https://github.com/asdf-community/asdf-clojure.git" +[tools] +java = "graalvm-22.3.1+java11" +clojure = "1.11" diff --git a/Makefile b/Makefile index 5f9af981..61f436a8 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ SHELL := /bin/bash +env: + env + compile-main-java: clojure -T:build compile-main-java @@ -9,30 +12,50 @@ compile-test-java: compile-main-java clojure -T:build compile-test-java repl: compile-test-java - clojure -M:dev:test:repl + clojure -M:dev:test:app:repl test: compile-test-java - clojure -M:dev:test:runner --focus :unit --reporter kaocha.report/documentation --no-capture-output + clojure -M:dev:test:app:runner --focus :unit --reporter kaocha.report/documentation --no-capture-output test-coverage: compile-test-java - clojure -M:dev:test:runner --focus :coverage --reporter kaocha.report/documentation --no-capture-output + clojure -M:dev:test:app:runner --focus :coverage --reporter kaocha.report/documentation --no-capture-output jq '.coverage["clara/coverage_ruleset.clj"]|join("_")' target/coverage/codecov.json | grep "_1___1____1_0_1__1__" || echo "Unexpected coverage output for clara.coverage-ruleset." exit 1 test-generative: compile-test-java - clojure -M:dev:test:runner --focus :generative --reporter kaocha.report/documentation --no-capture-output + clojure -M:dev:test:app:runner --focus :generative --reporter kaocha.report/documentation --no-capture-output test-config: - clojure -M:dev:test:runner --print-config + clojure -M:dev:test:app:runner --print-config clean: rm -rf target build lint: compile-test-java - clojure -M:dev:test:clj-kondo --copy-configs --dependencies --parallel --lint "$(shell clojure -A:dev:test -Spath)" - clojure -M:dev:test:clj-kondo --lint "src/main:src/test" --fail-level "error" + clojure -M:dev:test:app:clj-kondo --copy-configs --dependencies --parallel --lint "$(shell clojure -A:dev:test -Spath)" + clojure -M:dev:test:app:clj-kondo --lint "src/main:src/test" --fail-level "error" build: compile-main-java - clojure -X:jar :sync-pom true + clojure -X:jar :sync-pom true :jar "build/clara-rules.jar" + +build-native: build + mkdir -p build/graalvm-config + clojure -X:uberjar :sync-pom false :jar "build/clara-test-app.jar" + java -agentlib:native-image-agent=config-output-dir=build/graalvm-config -jar "build/clara-test-app.jar" clara.main + native-image -jar "build/clara-test-app.jar" \ + "-H:+ReportExceptionStackTraces" \ + "-H:+JNI" \ + "-H:EnableURLProtocols=http,https,jar" \ + "-J-Dclojure.spec.skip-macros=true" \ + "-J-Dclojure.compiler.direct-linking=true" \ + "--report-unsupported-elements-at-runtime" \ + "--verbose" \ + "--no-fallback" \ + "--no-server" \ + "--allow-incomplete-classpath" \ + "--trace-object-instantiation=java.lang.Thread" \ + "--features=clj_easy.graal_build_time.InitClojureClasses" \ + "-H:ConfigurationFileDirectories=build/graalvm-config" \ + "build/clara-test-app" deploy: clean build clojure -X:deploy-maven diff --git a/app/clara/main.clj b/app/clara/main.clj new file mode 100644 index 00000000..7b462432 --- /dev/null +++ b/app/clara/main.clj @@ -0,0 +1,51 @@ +(ns clara.main + (:require + [clara.rules :refer [defrule + insert! + insert + defquery + defhierarchy + defsession + query + fire-rules-async] :as r] + [futurama.core :refer [! + (insert! {:fact/type :my/result + :result ?value})) + +(defquery simple-output-query + "simple query that returns an output fact" + [] + [?output <- :my/output]) + +(defhierarchy simple-hierarchy + "simple hierarchy of facts" + :my/thing :my/input + :my/result :my/output + :my/input :my/fact + :my/output :my/fact) + +(defsession my-session + 'clara.main + :fact-type-fn :fact/type) + +(defn -main + "this is a test to compile a bunch of async code into native code, pretty nasty" + [& args] + (println + "async result:" + (! my-session + (insert {:fact/type :my/thing + :value args}) + (fire-rules-async)))] + (query session simple-output-query)))))) diff --git a/deps.edn b/deps.edn index 62d9061f..0a3eaf7d 100644 --- a/deps.edn +++ b/deps.edn @@ -19,6 +19,9 @@ org.clojure/math.combinatorics {:mvn/version "0.3.0"} criterium/criterium {:mvn/version "0.4.6"}}} + :app {:extra-paths ["app"] + :extra-deps {com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}} + :clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.03.05"}} :main-opts ["-m" "clj-kondo.main"]} @@ -47,8 +50,13 @@ :main-opts ["-m" "cljfmt.main" "check" "src" "dev"]} :jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}} - :exec-fn hf.depstar/jar - :exec-args {:jar "build/clara-rules.jar"}} + :exec-fn hf.depstar/jar} + + :uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}} + :exec-fn hf.depstar/uberjar + :exec-args {:aot true + :aliases [:app] + :main-class clara.main}} :install-maven {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.2"}} :exec-fn deps-deploy.deps-deploy/deploy