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

AOT compile duct modules and components / explicit :require on all dependencies? #99

Open
danielcompton opened this issue Nov 1, 2019 · 1 comment

Comments

@danielcompton
Copy link

danielcompton commented Nov 1, 2019

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?

@zerg000000
Copy link

zerg000000 commented Feb 27, 2020

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))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants