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

Graal build v2 #21

Merged
merged 4 commits into from
Mar 11, 2022
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
96 changes: 96 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
on:
push:
branches:
- "main"
jobs:
build-jar:
runs-on: "ubuntu-20.04"
steps:
- uses: "actions/checkout@v2"
- uses: "actions/cache@v2"
with:
path: |
~/.m2/repository
~/.gitlibs
key: "${{ runner.os }}-deps-${{ hashFiles('deps.edn') }}"
- uses: "DeLaGuardo/setup-clojure@4.0"
with:
cli: "1.10.3.1075"
github-token: "${{ secrets.GITHUB_TOKEN }}"
- run: "clojure -A:dev -M --report stderr -m moclojer.build"
env:
CI_COMMIT_SHA: "${{ github.sha }}"
- uses: "actions/upload-artifact@v2"
with:
name: "moclojer-${{ github.run_id }}-jar"
path: |
target/*.jar
target/native
build-native:
needs: "build-jar"
runs-on: "${{ matrix.os }}"
name: "Build native image on ${{ matrix.os }}"
strategy:
matrix:
os: [ "macos-11", "ubuntu-20.04" ]
steps:
- uses: "graalvm/setup-graalvm@v1"
with:
version: "22.0.0.2"
java-version: "17"
components: "native-image"
github-token: "${{ secrets.GITHUB_TOKEN }}"
- uses: "actions/checkout@v2"
- uses: "actions/download-artifact@v2"
with:
name: "moclojer-${{ github.run_id }}-jar"
path: "target"
- name: "Gen reflect.config.json"
working-directory: "target/native"
run: |
echo [] > moclojer.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To address #6, we need to parse a YAML file during this reflect.config process.

Once we parse a YAML on this stage, the YAML library will be added to the reflect config.

java -agentlib:native-image-agent=caller-filter-file=filter.json,config-output-dir=. \
-jar ../moclojer.jar &
PID=$!
## Wait startup
while ! curl -s localhost:8000 -o /dev/null; do echo waiting; sleep 3; done
curl -s localhost:8000 -D -
kill $PID
- working-directory: "target/native"
run: |
native-image @native-image-args \
-H:DashboardDump=report/moclojer \
-jar ../moclojer.jar \
-H:ReflectionConfigurationFiles=reflect-config.json \
-H:ResourceConfigurationFiles=resource-config.json
- uses: "actions/upload-artifact@v2"
with:
name: "moclojer-${{ runner.os }}-${{ github.run_id }}-bin"
path: |
target/native
test-native:
needs: "build-native"
runs-on: "${{ matrix.os }}"
name: "Test native image on ${{ matrix.os }}"
strategy:
matrix:
os: [ "macos-11", "ubuntu-20.04" ]
steps:
- uses: "actions/download-artifact@v2"
with:
name: "moclojer-${{ runner.os }}-${{ github.run_id }}-bin"
- name: "Check http status"
run: |
echo [] > moclojer.yml
chmod +x moclojer
./moclojer &
PID=$!
sleep 5
curl -vvv -s -D - localhost:8000
STATUS=$(curl -s -o /dev/null -w "%{http_code}" localhost:8000)
kill $PID
if [ "x$STATUS" = "x200" ]; then
exit 0
else
exit 1
fi
14 changes: 6 additions & 8 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
:deps {org.clojure/clojure {:mvn/version "1.10.2"}
io.forward/yaml {:mvn/version "1.0.11"}
org.clojure/data.json {:mvn/version "2.4.0"}
io.pedestal/pedestal.service {:mvn/version "0.5.10"
:exclusions [io.pedestal/pedestal.log]}
io.pedestal/pedestal.route {:mvn/version "0.5.10"
:exclusions [io.pedestal/pedestal.log]}
io.pedestal/pedestal.jetty {:mvn/version "0.5.10"
:exclusions [io.pedestal/pedestal.log]}
io.pedestal/pedestal.service {:mvn/version "0.5.10"}
io.pedestal/pedestal.route {:mvn/version "0.5.10"}
io.pedestal/pedestal.jetty {:mvn/version "0.5.10"}
selmer/selmer {:mvn/version "1.12.50"}
slugify/slugify {:mvn/version "0.0.1"}
org.slf4j/slf4j-simple {:mvn/version "1.7.5"}}
Expand All @@ -17,8 +14,9 @@
:exec-fn moclojer.core/-main
:extra-deps {io.pedestal/pedestal.service-tools {:mvn/version "0.5.10"}}}
:dev {:extra-paths ["dev"]
:extra-deps {io.github.clojure/tools.build {:git/url "https://github.com/clojure/tools.build.git"
:sha "e3e353262072e95ccac314a9b935b1bc42412a40"}}}
:extra-deps {io.github.clojure/tools.build {:git/url "https://github.com/clojure/tools.build.git"
:sha "e3e353262072e95ccac314a9b935b1bc42412a40"
:exclusions [org.slf4j/slf4j-nop]}}}
;; Run all tests
;; clj -M:test
:test {:extra-paths ["test" "OpenAPI-Specification/examples"]
Expand Down
48 changes: 24 additions & 24 deletions dev/moclojer/build.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
(ns moclojer.build
(:require [clojure.tools.build.api :as b]
[clojure.java.shell :as sh]
(:require [clojure.data.json :as json]
[clojure.java.io :as io]
[clojure.string :as string]))
[clojure.string :as string]
[clojure.tools.build.api :as b]))

(def lib 'moclojer/moclojer)
(def class-dir "target/classes")
(def uber-file "target/moclojer.jar")
(def java-home (System/getProperty "java.home"))

(set! *warn-on-reflection* true)
(defn -main
[& _]
(let [basis (b/create-basis {:project "deps.edn"})]
Expand All @@ -22,22 +21,23 @@
(b/compile-clj {:basis basis
:src-dirs (:paths basis)
:class-dir class-dir})
;; JAR
#_(b/uber {:class-dir class-dir
:main 'moclojer.core
:uber-file uber-file
:basis basis})
;; native-image
(run! println (vals (sh/sh "./bin/gu" "install" "native-image"
:dir (io/file java-home))))
(run! println (vals (sh/sh (str (io/file java-home "bin" "native-image"))
"-cp" (str (string/join ":" (:classpath-roots (b/create-basis {:project "deps.edn"}))) ":target/classes")
"-H:Name=moclojer"
"-H:+ReportExceptionStackTraces"
"--initialize-at-build-time"
"--verbose"
"--no-fallback"
"--no-server"
"--allow-incomplete-classpath"
"-H:ReflectionConfigurationFiles=reflect-config.json"
"moclojer.core")))))
(b/uber {:class-dir class-dir
:main 'moclojer.core
:uber-file uber-file
:basis basis})
(.mkdirs (io/file "target" "native"))
(spit (io/file "target" "native" "filter.json")
(json/write-str {}))
(spit (io/file "target" "native" "native-image-args")
(string/join "\n" ["-H:Name=moclojer"
"-Dio.pedestal.log.defaultMetricsRecorder=nil"
"-H:+ReportExceptionStackTraces"
"--allow-incomplete-classpath"
"--initialize-at-build-time"
"--verbose"
"-H:+DashboardHeap"
"-H:+DashboardCode"
"-H:+DashboardBgv"
"-H:+DashboardJson"
"--no-fallback"]))))

10 changes: 0 additions & 10 deletions filter.json

This file was deleted.

Loading