duct
duct copied to clipboard
AOT compile duct modules and components / explicit :require on all dependencies?
I'm trying to build an AOT'd uberjar using the Duct Leiningen template. I can use the template to build an uberjar, but it doesn't look like Duct modules and components are AOT compiled.
$ lein new duct foobar +api +cljs +postgres +site
$ lein uberjar
$ tar xzf target/foobar-0.1.0-SNAPSHOT-standalone.jar -C target/
$ ls target/duct/database/*
target/duct/database/sql.clj
target/duct/database/sql:
hikaricp.clj
If I add an explicit :require
for duct.database.sql.hikaricp
in the foobar.main
ns
form, then the duct.database.sql
and duct.database.sql.hikaricp
namespaces are AOT compiled in the uberjar.
I'm guessing that this is happening because the Clojure compiler isn't able to tell at AOT compile time that those modules are needed.
This also causes issues when compiling with native-image
, as the SubstrateVM compiler can't tell (without extra config) that some namespaces are going to be required at runtime based on info in the config.edn
file.
A workaround is to add explicit requires on all namespaces which are dynamically required by Duct or add them manually in the project.clj
, but this loses some of the benefits of Duct. Is there another way to get all of a Duct application automatically AOT compiled?
don't know if this would help the compilation.
(duct/load-hierarchy)
(def config
(-> (duct/resource "config.edn")
(duct/read-config)
(duct/prep-config [:duct.profile/dev
:duct.profile/local
:duct.profile/prod])))
(defn -main
[& args]
(let [keys (or (duct/parse-keys args) [:duct/daemon])
profiles [:duct.profile/prod]]
(-> config
(duct/exec-config profiles keys))))