diff --git a/.circleci/config.yml b/.circleci/config.yml index d41b04e5..92f782a5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -52,7 +52,7 @@ jobs: name: Create uberjar command: | mkdir -p /tmp/release - lein do clean, uberjar + script/uberjar VERSION=$(cat resources/BABASHKA_VERSION) cp target/babashka-$VERSION-standalone.jar /tmp/release/babashka-$VERSION-standalone.jar - store_artifacts: @@ -109,6 +109,7 @@ jobs: - run: name: Build binary command: | + script/uberjar script/compile no_output_timeout: 30m - run: @@ -180,6 +181,7 @@ jobs: - run: name: Build binary command: | + script/uberjar script/compile no_output_timeout: 30m - run: @@ -242,6 +244,7 @@ jobs: - run: name: Build binary command: | + script/uberjar script/compile no_output_timeout: 30m - run: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ae444cf3..f2d10408 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,8 +54,7 @@ jobs: - name: Build uberjar run: | - lein with-profiles +reflection do run - lein do clean, uberjar + script/uberjar - name: Babashka version id: babashka-version diff --git a/deps.edn b/deps.edn index 747b2866..ab8961d1 100644 --- a/deps.edn +++ b/deps.edn @@ -1,4 +1,4 @@ -{:paths ["src" "sci/src" "babashka.curl/src" "resources" "sci/resources"], +{:paths ["src" "src-xml" "sci/src" "babashka.curl/src" "resources" "sci/resources"], :deps {org.clojure/clojure {:mvn/version "1.10.2-alpha1"}, org.clojure/tools.reader {:mvn/version "1.3.2"}, borkdude/edamame {:mvn/version "0.0.11-alpha.9"}, diff --git a/doc/build.md b/doc/build.md index 6543cf38..50ac9638 100644 --- a/doc/build.md +++ b/doc/build.md @@ -38,16 +38,12 @@ $ git submodule update --recursive ## Build -Run the `compile` script: - -``` shell -$ script/compile -``` +First run `script/uberjar` to create the `.jar` file. Then run `script/compile`. To configure maximum heap size you can use: ``` -$ BABASHKA_XMX="-J-Xmx4g" script/compile +$ BABASHKA_XMX="-J-Xmx4800m" script/compile ``` ## Windows diff --git a/project.clj b/project.clj index 477d1aa9..f306d314 100644 --- a/project.clj +++ b/project.clj @@ -19,23 +19,26 @@ [org.clojure/core.async "1.1.587"] [org.clojure/tools.cli "1.0.194"] [org.clojure/data.csv "1.0.0"] - [org.clojure/data.xml "0.2.0-alpha6"] [cheshire "5.10.0"] [fipp "0.6.22"] [clj-commons/clj-yaml "0.7.1"] [com.cognitect/transit-clj "1.0.324"] [seancorfield/next.jdbc "1.0.424"] [org.postgresql/postgresql "42.2.12"]] - :profiles {:feature/hsqldb {:dependencies [[org.hsqldb/hsqldb "2.4.0"]]} - :test {:dependencies [[clj-commons/conch "0.9.2"] - [com.clojure-goes-fast/clj-async-profiler "0.4.1"]]} + :profiles {:feature/xml {:source-paths ["src-xml"] + :dependencies [[org.clojure/data.xml "0.2.0-alpha6"]]} + :feature/hsqldb {:dependencies [[org.hsqldb/hsqldb "2.4.0"]]} + :test [:feature/xml + :feature/hsqldb + {:dependencies [[clj-commons/conch "0.9.2"] + [com.clojure-goes-fast/clj-async-profiler "0.4.1"]]}] :uberjar {:global-vars {*assert* false} :jvm-opts ["-Dclojure.compiler.direct-linking=true" "-Dclojure.spec.skip-macros=true"] :main babashka.main :aot :all} :reflection {:main babashka.impl.classes/generate-reflection-file}} - :aliases {"bb" ["run" "-m" "babashka.main"]} + :aliases {"bb" ["with-profiles" "+feature/xml,+feature/hsqldb" "run" "-m" "babashka.main"]} :deploy-repositories [["clojars" {:url "https://clojars.org/repo" :username :env/clojars_user :password :env/clojars_pass diff --git a/script/compile b/script/compile index 153874b5..3286b111 100755 --- a/script/compile +++ b/script/compile @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail +set -eou pipefail if [ -z "$BABASHKA_XMX" ]; then export BABASHKA_XMX="-J-Xmx4500m" @@ -11,9 +11,18 @@ if [ -z "$GRAALVM_HOME" ]; then exit 1 fi +BABASHKA_VERSION=$(cat resources/BABASHKA_VERSION) + +BABASHKA_JAR=${BABASHKA_JAR:-"target/babashka-$BABASHKA_VERSION-standalone.jar"} + +if [[ ! -f "$BABASHKA_JAR" ]] +then + echo "Please run script/uberjar first." + exit 1 +fi + $GRAALVM_HOME/bin/gu install native-image -BABASHKA_VERSION=$(cat resources/BABASHKA_VERSION) export JAVA_HOME=$GRAALVM_HOME @@ -23,15 +32,22 @@ $GRAALVM_HOME/bin/javac -cp "$SVM_JAR" resources/CutOffCoreServicesDependencies. BABASHKA_LEIN_PROFILES="" +BABASHKA_FEATURE_HSQLDB=${BABASHKA_FEATURE_HSQLDB:-} + if [ "$BABASHKA_FEATURE_HSQLDB" = "true" ] then - BABASHKA_LEIN_PROFILES="+feature/hsqldb" + BABASHKA_LEIN_PROFILES+="+feature/hsqldb" +else + BABASHKA_LEIN_PROFILES+="-feature/hsqldb" fi -if [ -z "$BABASHKA_JAR" ]; then - lein with-profiles "+reflection,$BABASHKA_LEIN_PROFILES" do run - lein with-profiles "+uberjar,$BABASHKA_LEIN_PROFILES" do clean, uberjar - BABASHKA_JAR=${BABASHKA_JAR:-"target/babashka-$BABASHKA_VERSION-standalone.jar"} +BABASHKA_FEATURE_XML=${BABASHKA_FEATURE_XML:-} + +if [ "$BABASHKA_FEATURE_XML" != "false" ] +then + BABASHKA_LEIN_PROFILES+=",+feature/xml" +else + BABASHKA_LEIN_PROFILES+=",-feature/xml" fi BABASHKA_BINARY=${BABASHKA_BINARY:-"bb"} @@ -57,6 +73,8 @@ args=( -jar $BABASHKA_JAR \ "--initialize-at-run-time=org.postgresql.sspi.SSPIClient" \ "$BABASHKA_XMX" ) +BABASHKA_STATIC=${BABASHKA_STATIC:-} + if [ "$BABASHKA_STATIC" = "true" ]; then args+=("--static") fi diff --git a/script/uberjar b/script/uberjar new file mode 100755 index 00000000..3e28e684 --- /dev/null +++ b/script/uberjar @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -eo pipefail + +BABASHKA_LEIN_PROFILES="" + +if [ "$BABASHKA_FEATURE_HSQLDB" = "true" ] +then + BABASHKA_LEIN_PROFILES+="+feature/hsqldb" +else + BABASHKA_LEIN_PROFILES+="-feature/hsqldb" +fi + +if [ "$BABASHKA_FEATURE_XML" != "false" ] +then + BABASHKA_LEIN_PROFILES+=",+feature/xml" +else + BABASHKA_LEIN_PROFILES+=",-feature/xml" +fi + +if [ -z "$BABASHKA_JAR" ]; then + lein with-profiles "+reflection,$BABASHKA_LEIN_PROFILES" do run + lein with-profiles "+uberjar,$BABASHKA_LEIN_PROFILES" do clean, uberjar +fi diff --git a/src/babashka/impl/xml.clj b/src-xml/babashka/impl/xml.clj similarity index 100% rename from src/babashka/impl/xml.clj rename to src-xml/babashka/impl/xml.clj diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index 281f2e04..8fc07797 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -69,11 +69,11 @@ ;; not supported: {:name "setURLStreamHandlerFactory"} {:name "toExternalForm"} {:name "toString"} - {:name "toURI"}]} - com.sun.xml.internal.stream.XMLInputFactoryImpl - {:methods [{:name "" :parameterTypes []}]} - com.sun.xml.internal.stream.XMLOutputFactoryImpl - {:methods [{:name "" :parameterTypes []}]}} + {:name "toURI"}]}} + features/xml? (assoc `com.sun.xml.internal.stream.XMLInputFactoryImpl + {:methods [{:name "" :parameterTypes []}]} + `com.sun.xml.internal.stream.XMLOutputFactoryImpl + {:methods [{:name "" :parameterTypes []}]}) features/hsqldb? (assoc `org.hsqldb.dbinfo.DatabaseInformationFull {:methods [{:name "" :parameterTypes ["org.hsqldb.Database"]}]} diff --git a/src/babashka/impl/features.clj b/src/babashka/impl/features.clj index 05a3e497..a4e1ad2d 100644 --- a/src/babashka/impl/features.clj +++ b/src/babashka/impl/features.clj @@ -1,4 +1,5 @@ (ns babashka.impl.features {:no-doc true}) -(def hsqldb? (= "true" (System/getenv "BABASHKA_FEATURE_HSQLDB"))) +(def xml? (not= "false" (System/getenv "BABASHKA_FEATURE_XML"))) ;; included by default +(def hsqldb? (= "true" (System/getenv "BABASHKA_FEATURE_HSQLDB"))) ;; excluded by default diff --git a/src/babashka/main.clj b/src/babashka/main.clj index c26d47cf..2e156950 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -15,6 +15,7 @@ [babashka.impl.common :as common] [babashka.impl.csv :as csv] [babashka.impl.curl :refer [curl-namespace]] + [babashka.impl.features :as features] [babashka.impl.jdbc :as jdbc] [babashka.impl.nrepl-server :as nrepl-server] [babashka.impl.pipe-signal-handler :refer [handle-pipe! pipe-signal-received?]] @@ -24,7 +25,6 @@ [babashka.impl.test :as t] [babashka.impl.tools.cli :refer [tools-cli-namespace]] [babashka.impl.transit :refer [transit-namespace]] - [babashka.impl.xml :as xml] [babashka.impl.yaml :refer [yaml-namespace]] [babashka.wait :as wait] [clojure.edn :as edn] @@ -39,6 +39,9 @@ [sci.impl.vars :as vars]) (:gen-class)) +(when features/xml? + (require '[babashka.impl.xml])) + (binding [*unrestricted* true] (sci/alter-var-root sci/in (constantly *in*)) (sci/alter-var-root sci/out (constantly *out*)) @@ -245,21 +248,22 @@ Everything after that is bound to *command-line-args*.")) (throw (ex-info "" {:bb/exit-code n}))) (def aliases - '{tools.cli clojure.tools.cli - edn clojure.edn - wait babashka.wait - signal babashka.signal - shell clojure.java.shell - io clojure.java.io - async clojure.core.async - csv clojure.data.csv - json cheshire.core - xml clojure.data.xml - yaml clj-yaml.core - curl babashka.curl - transit cognitect.transit - bencode bencode.core - jdbc next.jdbc}) + (cond-> + '{tools.cli clojure.tools.cli + edn clojure.edn + wait babashka.wait + signal babashka.signal + shell clojure.java.shell + io clojure.java.io + async clojure.core.async + csv clojure.data.csv + json cheshire.core + yaml clj-yaml.core + curl babashka.curl + transit cognitect.transit + bencode bencode.core + jdbc next.jdbc} + features/xml? (assoc 'xml 'clojure.data.xml))) (def cp-state (atom nil)) @@ -274,29 +278,30 @@ Everything after that is bound to *command-line-args*.")) nil) (def namespaces - {'clojure.tools.cli tools-cli-namespace - 'clojure.java.shell shell-namespace - 'babashka.wait {'wait-for-port wait/wait-for-port - 'wait-for-path wait/wait-for-path} - 'babashka.signal {'pipe-signal-received? pipe-signal-received?} - 'clojure.java.io io-namespace - 'clojure.core.async async-namespace - 'clojure.core.async.impl.protocols async-protocols-namespace - 'clojure.data.csv csv/csv-namespace - 'cheshire.core cheshire-core-namespace - 'clojure.stacktrace stacktrace-namespace - 'clojure.main {'demunge demunge - 'repl-requires clojure-main/repl-requires} - 'clojure.test t/clojure-test-namespace - 'babashka.classpath {'add-classpath add-classpath*} - 'clojure.data.xml xml/xml-namespace - 'clj-yaml.core yaml-namespace - 'clojure.pprint pprint-namespace - 'babashka.curl curl-namespace - 'cognitect.transit transit-namespace - 'bencode.core bencode-namespace - 'next.jdbc jdbc/njdbc-namespace - 'next.jdbc.sql jdbc/next-sql-namespace}) + (cond-> + {'clojure.tools.cli tools-cli-namespace + 'clojure.java.shell shell-namespace + 'babashka.wait {'wait-for-port wait/wait-for-port + 'wait-for-path wait/wait-for-path} + 'babashka.signal {'pipe-signal-received? pipe-signal-received?} + 'clojure.java.io io-namespace + 'clojure.core.async async-namespace + 'clojure.core.async.impl.protocols async-protocols-namespace + 'clojure.data.csv csv/csv-namespace + 'cheshire.core cheshire-core-namespace + 'clojure.stacktrace stacktrace-namespace + 'clojure.main {'demunge demunge + 'repl-requires clojure-main/repl-requires} + 'clojure.test t/clojure-test-namespace + 'babashka.classpath {'add-classpath add-classpath*} + 'clj-yaml.core yaml-namespace + 'clojure.pprint pprint-namespace + 'babashka.curl curl-namespace + 'cognitect.transit transit-namespace + 'bencode.core bencode-namespace + 'next.jdbc jdbc/njdbc-namespace + 'next.jdbc.sql jdbc/next-sql-namespace} + features/xml? (assoc 'clojure.data.xml @(resolve 'babashka.impl.xml/xml-namespace)))) (def bindings {'java.lang.System/exit exit ;; override exit, so we have more control