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

feat: test building native clojure app using library, test with graalvm #1

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 19 additions & 13 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@ name: Clojure CI

on:
push:
branches: [ "main" ]
branches:
- 'main'
pull_request:
branches: [ "main" ]
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest
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/[email protected]
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 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/hierarchy-test-app this is a test invocation of native app
6 changes: 6 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[plugins]
clojure = "https://github.com/asdf-community/asdf-clojure.git"

[tools]
java = "graalvm-22.3.1+java11"
clojure = "1.11"
33 changes: 27 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
.PHONY: repl test clean deploy install format-check format-fix

SHELL := /bin/bash
env:
env

repl:
clojure -M:dev:test:repl
clojure -M:dev:test:app:repl

test:
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

clean:
rm -rf target build

lint:
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: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:test" --fail-level "error"

build:
clojure -X:jar :sync-pom true
clojure -X:jar :sync-pom true :jar "build/hierarchy.jar"

build-native: build
mkdir -p build/graalvm-config
clojure -X:uberjar :sync-pom false :jar "build/hierarchy-test-app.jar"
java -agentlib:native-image-agent=config-output-dir=build/graalvm-config -jar "build/hierarchy-test-app.jar" hierarchy.main
native-image -jar "build/hierarchy-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/hierarchy-test-app"

deploy: clean build
clojure -X:deploy-maven
Expand Down
23 changes: 23 additions & 0 deletions app/hierarchy/main.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns hierarchy.main
(:require [hierarchy.core :as h])
(:gen-class))

(h/activate!)

(derive [:foo :bar] :foobar)

(defmulti print-a-thing :type)

(defmethod print-a-thing :default
[thing]
(println "thing:" thing))

(defmethod print-a-thing :foobar
[thing]
(println "foobar thing:" thing))

(defn -main
"this is a super simple test app which dispatches to `:foobar`"
[& args]
(print-a-thing {:type [:foo :bar]
:foobar args}))
15 changes: 11 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
:extra-deps {reloaded.repl/reloaded.repl {:mvn/version "0.2.4"}
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 "2023.12.15"}}
:main-opts ["-m" "clj-kondo.main"]}

Expand All @@ -21,7 +24,6 @@
"-m" "kaocha.runner"]
:exec-fn kaocha.runner/exec-fn}


:repl {:extra-deps {nrepl/nrepl {:mvn/version "1.1.0"}
cider/cider-nrepl {:mvn/version "0.44.0"}}
:main-opts ["-e" "(println \"warn-on-reflection =\" (set! *warn-on-reflection* true))"
Expand All @@ -34,9 +36,14 @@
:format-check {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}
:main-opts ["-m" "cljfmt.main" "check" "src" "dev"]}

:jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.0.216"}}
:exec-fn hf.depstar/jar
:exec-args {:jar "build/hierarchy.jar"}}
:jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
: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 hierarchy.main}}

:install-maven {:extra-deps {slipset/deps-deploy {:mvn/version "0.1.5"}}
:exec-fn deps-deploy.deps-deploy/deploy
Expand Down
Loading