Skip to content

Commit

Permalink
fix(#4): exceptions in native executable
Browse files Browse the repository at this point in the history
  • Loading branch information
worm2fed committed Jul 17, 2024
1 parent 1613fee commit 8717444
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ jobs:
- macos-latest

steps:
- uses: actions/checkout@v4

- name: Download jar artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -85,7 +87,7 @@ jobs:
- name: Compile to native binary
run: |
mv aidbox-sdk.jar source.jar
native-image -jar ./source.jar --no-fallback --no-server aidbox-sdk-${{ matrix.os }}
native-image -jar ./source.jar -march=native --no-fallback --features=clj_easy.graal_build_time.InitClojureClasses -H:ReflectionConfigurationFiles=./reflect-config.json aidbox-sdk-${{ matrix.os }}
- name: Upload amd64 binary artifact
uses: actions/upload-artifact@v4
Expand Down
20 changes: 11 additions & 9 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
(b/delete {:path "target"}))

(defn uberjar [{:keys [jar-name]
:or {jar-name "aidbox-sdk"}}]

:or {jar-name "aidbox-sdk"}}]
(clean nil)

(b/copy-dir {:src-dirs ["src" "resources"]
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})

(b/compile-clj {:basis basis
(b/compile-clj {:basis basis
:ns-compile '[aidbox-sdk.core]
:class-dir class-dir})
:class-dir class-dir})

(let [jar-path (str "target/" jar-name ".jar")]
(b/uber {:class-dir class-dir
:uber-file jar-path
:basis basis
:main 'aidbox-sdk.core})

(b/uber {:class-dir class-dir
:uber-file (str "target/" jar-name ".jar")
:basis basis
:main 'aidbox-sdk.core}))
(println "Building complete. Uberjar is available at:" jar-path)))
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{:paths ["src"]
:deps {com.github.clj-easy/graal-build-time {:mvn/version "0.1.4"}
:deps {org.clojure/data.json {:mvn/version "2.5.0"}

com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}
org.clojure/clojure {:mvn/version "1.11.3"}
org.clojure/data.json {:mvn/version "2.5.0"}
org.clojure/tools.cli {:mvn/version "1.1.230"}}

:aliases
Expand Down
87 changes: 87 additions & 0 deletions reflect-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[
{
"name": "clojure.lang.APersistentSet",
"methods": [
{
"name": "contains",
"parameterTypes": [
"java.lang.Object"
]
}
]
},
{
"name": "clojure.lang.APersistentVector",
"methods": [
{
"name": "contains",
"parameterTypes": [
"java.lang.Object"
]
}
]
},
{
"name": "clojure.lang.PersistentHashSet",
"queryAllPublicMethods": true
},
{
"name": "clojure.lang.PersistentVector",
"queryAllPublicMethods": true
},
{
"name": "java.io.BufferedReader",
"queryAllPublicMethods": true,
"methods": [
{
"name": "close",
"parameterTypes": []
}
]
},
{
"name": "java.io.File",
"queryAllPublicMethods": true,
"methods": [
{
"name": "getName",
"parameterTypes": []
},
{
"name": "isDirectory",
"parameterTypes": []
},
{
"name": "mkdir",
"parameterTypes": []
}
]
},
{
"name": "java.lang.reflect.Method",
"methods": [
{
"name": "canAccess",
"parameterTypes": [
"java.lang.Object"
]
}
]
},
{
"name": "java.util.concurrent.atomic.AtomicBoolean",
"fields": [
{
"name": "value"
}
]
},
{
"name": "java.util.concurrent.atomic.AtomicReference",
"fields": [
{
"name": "value"
}
]
}
]
2 changes: 2 additions & 0 deletions src/aidbox_sdk/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[clojure.java.io :as io]
[aidbox-sdk.generator :as generator]))

(set! *warn-on-reflection* true)

(defn url
"Safe version of as-url function"
[s]
Expand Down

0 comments on commit 8717444

Please sign in to comment.