diff --git a/.circleci/script/gen_ci.clj b/.circleci/script/gen_ci.clj index 42fb9fed..ae0b9675 100644 --- a/.circleci/script/gen_ci.clj +++ b/.circleci/script/gen_ci.clj @@ -5,7 +5,7 @@ [clojure.string :as str] [flatland.ordered.map :refer [ordered-map]])) -(def graalvm-version "22") +(def graalvm-version "23") (defn run ([cmd-name cmd] @@ -84,7 +84,8 @@ :BABASHKA_PLATFORM "linux" :GRAALVM_VERSION graalvm-version :GRAALVM_HOME graalvm-home - :BABASHKA_TEST_ENV "jvm"} + :BABASHKA_TEST_ENV "jvm" + :BABASHKA_SHA (System/getenv "CIRCLE_SHA1")} :resource_class "large" :steps (gen-steps @@ -128,7 +129,8 @@ java -jar \"$jar\" --config .build/bb.edn --deps-root . release-artifact \"$refl "macos" platform) :BABASHKA_TEST_ENV "native" - :BABASHKA_XMX "-J-Xmx6500m"} + :BABASHKA_XMX "-J-Xmx6500m" + :BABASHKA_SHA (System/getenv "CIRCLE_SHA1")} env (if (= "aarch64" arch) (assoc env :BABASHKA_ARCH arch) env) diff --git a/.cirrus.yml b/.cirrus.yml index 270c6925..3e36b348 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -5,7 +5,7 @@ task: skip: "changesIncludeOnly('logo/*', '**.md')" env: LEIN_ROOT: "true" - GRAALVM_VERSION: "22" + GRAALVM_VERSION: "23" GRAALVM_HOME: ${HOME}/graalvm-${GRAALVM_VERSION}/Contents/Home BABASHKA_PLATFORM: macos # used in release script BABASHKA_ARCH: aarch64 @@ -24,6 +24,8 @@ task: sudo /usr/sbin/softwareupdate --install-rosetta --agree-to-license java -version + export BABASHKA_SHA=$(git rev-parse HEAD) + script/uberjar # curl -sLO 'https://github.com/babashka/pgo-profiles/releases/download/2023.10.11/default.iprof' script/compile # --pgo=default.iprof diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e0944667..a836a934 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,7 @@ jobs: LEIN_ROOT: "true" BABASHKA_PLATFORM: linux # could be used in jar name GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BABASHKA_SHA: ${{ github.sha }} steps: - name: Git checkout uses: actions/checkout@v2 @@ -102,11 +103,12 @@ jobs: runs-on: ${{ matrix.os }} env: LEIN_ROOT: "true" - GRAALVM_VERSION: "22" + GRAALVM_VERSION: "23" BABASHKA_PLATFORM: ${{ matrix.name }} # used in release script BABASHKA_TEST_ENV: native BABASHKA_XMX: "-J-Xmx6500m" GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BABASHKA_SHA: ${{ github.sha }} steps: - name: Git checkout uses: actions/checkout@v2 @@ -126,7 +128,7 @@ jobs: if: "matrix.static == false" uses: graalvm/setup-graalvm@v1 with: - java-version: '22' + java-version: '23' distribution: 'graalvm' components: 'native-image' github-token: ${{ secrets.GITHUB_TOKEN }} @@ -135,7 +137,7 @@ jobs: if: "matrix.static == true" uses: graalvm/setup-graalvm@v1 with: - version: '22' + version: '23' distribution: 'graalvm' components: 'native-image' native-image-musl: true @@ -217,13 +219,13 @@ jobs: run: mkdir -p /tmp/release - name: Download linux binary - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4.1.7 with: name: babashka-${{ steps.babashka-version.outputs.version }}-linux-amd64.zip path: /tmp/release - name: Download static linux binary - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4.1.7 with: name: babashka-${{ steps.babashka-version.outputs.version }}-linux-static-amd64.zip path: /tmp/release-static diff --git a/CHANGELOG.md b/CHANGELOG.md index e94bc972..29cddb95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,44 @@ A preview of the next release can be installed from ## Unreleased -- Clojure 1.12 interop: method thunks, FI coercion, array notation +- [#1752](https://github.com/babashka/babashka/issues/1752): include `java.lang.SecurityException` for `java.net.http.HttpClient` support +- [#1748](https://github.com/babashka/babashka/issues/1748): add `clojure.core/ensure` +- Upgrade to `taoensso/timbre` `v6.6.0` + +## 1.12.194 (2024-10-12) + +- Upgrade to GraalVM 23 +- [#1743](https://github.com/babashka/babashka/issues/1743): fix new fully qualified instance method in call position with GraalVM 23 + +## 1.12.193 (2024-10-11) + +- Clojure 1.12 interop: method thunks, FI coercion, array notation (see below) - Upgrade SCI reflector based on clojure 1.12 and remove specific workaround for `Thread/sleep` interop - Add `tools.reader.edn/read` - Fix [#1741](https://github.com/babashka/babashka/issues/1741): `(taoensso.timbre/spy)` now relies on macros from `taoensso.encore` previously not available in bb +Examples of the new Clojure interop: + +``` clojure +;; Qualified methods in call position: +(String/.length "123") ;;=> 3 +(String/new "123") ;;=> "123" + +;; Qualified methods in value position, as functions: +(map Integer/parseInt ["1" "22" "333"]) ;;=> (1 22 333) +(map String/.length ["1" "22" "333"]) ;;=> (1 2 3) +(map String/new ["1" "22" "333"]) ;;=> ("1" "22" "333") + +;; Typed multi-dimensional array class notation: +long/1 ;;=> 1-dimensional long array class +String/2 ;;=> 2-dimensional String array class + +;; Pass Clojure IFn to Java where `java.util.function.Predicate`, etc. is expected: +(into [] (doto (java.util.ArrayList. [1 2 3]) (.removeIf even?))) ;;=> [1 3] +(.computeIfAbsent (java.util.HashMap.) "abc" #(str % %)) ;;=> "abcabc" +``` + ## 1.4.192 (2024-09-12) - Upgrade Clojure to `1.12.0` diff --git a/Dockerfile b/Dockerfile index 1ec5d193..085b43e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN apt update RUN apt install --no-install-recommends -yy build-essential zlib1g-dev WORKDIR "/opt" -ENV GRAALVM_VERSION="22" +ENV GRAALVM_VERSION="23" ARG TARGETARCH # Do not set those directly, use TARGETARCH instead ENV BABASHKA_ARCH= diff --git a/appveyor.yml b/appveyor.yml index 16dda71d..59c901ce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,8 +7,8 @@ image: Visual Studio 2022 clone_folder: C:\projects\babashka environment: - GRAALVM_HOME: C:\projects\babashka\graalvm\graalvm-jdk-22+36.1 - JAVA_HOME: C:\projects\babashka\graalvm\graalvm-jdk-22+36.1 + GRAALVM_HOME: C:\projects\babashka\graalvm\graalvm-jdk-23+37.1 + JAVA_HOME: C:\projects\babashka\graalvm\graalvm-jdk-23+37.1 BABASHKA_XMX: "-J-Xmx5g" skip_commits: @@ -44,7 +44,7 @@ clone_script: build_script: # TODO: Extract the zip by removing the top level folder to remove the hardcoded path for GRAALVM_HOME - cmd: >- - powershell -Command "if (Test-Path('graalvm')) { return } else { (New-Object Net.WebClient).DownloadFile('https://download.oracle.com/graalvm/22/archive/graalvm-jdk-22_windows-x64_bin.zip', 'graalvm.zip') }" + powershell -Command "if (Test-Path('graalvm')) { return } else { (New-Object Net.WebClient).DownloadFile('https://download.oracle.com/graalvm/23/archive/graalvm-jdk-23_windows-x64_bin.zip', 'graalvm.zip') }" powershell -Command "if (Test-Path('graalvm')) { return } else { Expand-Archive graalvm.zip graalvm }" @@ -61,6 +61,8 @@ build_script: # see https://github.com/quarkusio/quarkus/pull/7663 - cmd: >- + set BABASHKA_SHA=%APPVEYOR_REPO_COMMIT% + call script/uberjar.bat call script/compile.bat diff --git a/deps.edn b/deps.edn index 257ca0e3..7eb7fa66 100644 --- a/deps.edn +++ b/deps.edn @@ -45,7 +45,7 @@ hiccup/hiccup {:mvn/version "2.0.0-RC1"} rewrite-clj/rewrite-clj {:mvn/version "1.1.48"} selmer/selmer {:mvn/version "1.12.59"} - com.taoensso/timbre {:mvn/version "6.5.0"} + com.taoensso/timbre {:mvn/version "6.6.0"} org.clojure/tools.logging {:mvn/version "1.1.0"} org.clojure/data.priority-map {:mvn/version "1.1.0"} insn/insn {:mvn/version "0.5.2"} diff --git a/doc/build.md b/doc/build.md index 6f81d189..71df3425 100644 --- a/doc/build.md +++ b/doc/build.md @@ -3,7 +3,7 @@ ## Prerequisites - Install [lein](https://leiningen.org/) for producing uberjars -- Download [GraalVM](https://www.graalvm.org/downloads/). Currently we use *jdk-22*. +- Download [GraalVM](https://www.graalvm.org/downloads/). Currently we use *Oracle GraalVM 23*. - For Windows, installing Visual Studio 2019 with the "Desktop development with C++" workload is recommended. - Set `$GRAALVM_HOME` to the GraalVM distribution directory. On macOS this can look like: diff --git a/doc/dev.md b/doc/dev.md index a7b27349..b3a22bde 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -22,6 +22,9 @@ agreement, the PR will be merged. Each bug fix, change or new feature should be tested well to prevent future regressions. +If possible, tests should use public APIs. If the bug is in private/internal +code, try to trigger it from a public API. + ### Force-push Please do not use `git push --force` on your PR branch for the following @@ -37,7 +40,7 @@ reasons: ## Requirements -You need [lein](https://leiningen.org/) for running JVM tests and/or producing uberjars. For building binaries you need GraalVM. Currently we use jdk-21.0.0.1 +You need [lein](https://leiningen.org/) for running JVM tests and/or producing uberjars. For building binaries you need GraalVM. Currently we use Oracle GraalVM 23. ## Clone repository diff --git a/feature-logging/babashka/impl/logging.clj b/feature-logging/babashka/impl/logging.clj index 9aa51e83..096a7b1a 100644 --- a/feature-logging/babashka/impl/logging.clj +++ b/feature-logging/babashka/impl/logging.clj @@ -59,7 +59,9 @@ ;; Note pre-resolved expansion `(taoensso.timbre/-log! ~config ~level ~ns ~file ~line ~column ~msg-type ~?err - (delay ~vargs-form) ~?base-data ~callsite-id ~spying?))))) + (delay ~vargs-form) ~?base-data ~callsite-id ~spying? + ~(get opts :instant) + ~(get opts :may-log?)))))) ([level msg-type args & [opts]] (let [{:keys [line column]} (merge (meta &form)) diff --git a/project.clj b/project.clj index d57cf278..8b93769c 100644 --- a/project.clj +++ b/project.clj @@ -73,7 +73,7 @@ :feature/selmer {:source-paths ["feature-selmer"] :dependencies [[selmer/selmer "1.12.59"]]} :feature/logging {:source-paths ["feature-logging"] - :dependencies [[com.taoensso/timbre "6.5.0"] + :dependencies [[com.taoensso/timbre "6.6.0"] [org.clojure/tools.logging "1.1.0"]]} :feature/priority-map {:source-paths ["feature-priority-map"] :dependencies [[org.clojure/data.priority-map "1.1.0"]]} diff --git a/resources/BABASHKA_RELEASED_VERSION b/resources/BABASHKA_RELEASED_VERSION index 2671f6bc..9c319f56 100644 --- a/resources/BABASHKA_RELEASED_VERSION +++ b/resources/BABASHKA_RELEASED_VERSION @@ -1 +1 @@ -1.4.192 \ No newline at end of file +1.12.194 \ No newline at end of file diff --git a/resources/BABASHKA_VERSION b/resources/BABASHKA_VERSION index 0b8ca51e..9ff66859 100644 --- a/resources/BABASHKA_VERSION +++ b/resources/BABASHKA_VERSION @@ -1 +1 @@ -1.4.193-SNAPSHOT \ No newline at end of file +1.12.195-SNAPSHOT \ No newline at end of file diff --git a/resources/META-INF/babashka/deps.edn b/resources/META-INF/babashka/deps.edn index 698182eb..7eb7fa66 100644 --- a/resources/META-INF/babashka/deps.edn +++ b/resources/META-INF/babashka/deps.edn @@ -20,7 +20,7 @@ "impl-java/src"], :deps {org.clojure/clojure {:mvn/version "1.12.0"}, org.babashka/sci {:local/root "sci"} - org.babashka/babashka.impl.java {:mvn/version "0.1.8"} + org.babashka/babashka.impl.java {:mvn/version "0.1.10"} org.babashka/sci.impl.types {:mvn/version "0.0.2"} babashka/babashka.curl {:local/root "babashka.curl"} babashka/fs {:local/root "fs"} @@ -45,7 +45,7 @@ hiccup/hiccup {:mvn/version "2.0.0-RC1"} rewrite-clj/rewrite-clj {:mvn/version "1.1.48"} selmer/selmer {:mvn/version "1.12.59"} - com.taoensso/timbre {:mvn/version "6.5.0"} + com.taoensso/timbre {:mvn/version "6.6.0"} org.clojure/tools.logging {:mvn/version "1.1.0"} org.clojure/data.priority-map {:mvn/version "1.1.0"} insn/insn {:mvn/version "0.5.2"} diff --git a/resources/META-INF/native-image/babashka/babashka/native-image.properties b/resources/META-INF/native-image/babashka/babashka/native-image.properties index ea2ccd7e..f6db946b 100644 --- a/resources/META-INF/native-image/babashka/babashka/native-image.properties +++ b/resources/META-INF/native-image/babashka/babashka/native-image.properties @@ -53,4 +53,5 @@ Args=-H:+ReportExceptionStackTraces \ -EBABASHKA_FEATURE_LANTERNA \ -EBABASHKA_FEATURE_SPEC_ALPHA \ -EBABASHKA_FEATURE_RRB_VECTOR \ - -EBABASHKA_REQUIRE_SCAN + -EBABASHKA_REQUIRE_SCAN \ + -EBABASHKA_SHA diff --git a/sci b/sci index 09589dd3..6d9380f5 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 09589dd37aa762ba1a416582a4d020deb9c612a4 +Subproject commit 6d9380f55b3038769d5856fc67e7d7939ac981ef diff --git a/script/bump_graal_version.clj b/script/bump_graal_version.clj index 415d5896..e9a29fda 100755 --- a/script/bump_graal_version.clj +++ b/script/bump_graal_version.clj @@ -46,7 +46,8 @@ "project.clj" "script/bump_graal_version.clj" ".circleci/script/short_ci.clj" - ".cirrus.yml"]) + ".cirrus.yml" + "script/install-graalvm"]) ;; We might have to keep changing these from ;; time to time whenever the version is bumped @@ -54,8 +55,7 @@ ;; OR ;; ;; We could have them as environment variables -(def current-graal-version "22.3.1") -(def current-java-version "java19") +(def current-graal-version "23") (def cl-options [["-g" "--graal VERSION" "graal version"] @@ -91,19 +91,12 @@ [args] (when (empty? args) (display-help)) - (let [new-graal-version (:graal args) - new-java-version (:java args)] + (let [new-graal-version (:graal args)] (when (not (nil? new-graal-version)) (if (is-valid-bump? new-graal-version nil) (do (println "Performing Graal bump...") (bump-current current-graal-version new-graal-version)) - (show-error new-graal-version))) - (when (not (nil? new-java-version)) - (if (is-valid-bump? new-java-version nil) - (do - (println "Performing Java bump...") - (bump-current current-java-version new-java-version)) - (show-error new-java-version))))) + (show-error new-graal-version))))) (exec-script cl-args) diff --git a/script/compile b/script/compile index 04c3c1f7..3b7097c2 100755 --- a/script/compile +++ b/script/compile @@ -39,7 +39,7 @@ args=("-jar" "$BABASHKA_JAR" # "-H:DashboardDump=reports/dump" # "-H:+DashboardPretty" # "-H:+DashboardJson" - "-H:ReportAnalysisForbiddenType=java.awt.Toolkit:InHeap,Allocated" + # "-H:ReportAnalysisForbiddenType=java.awt.Toolkit:Instantiated" "--verbose" "--no-fallback" "--native-image-info" @@ -54,13 +54,14 @@ BABASHKA_STATIC=${BABASHKA_STATIC:-} BABASHKA_MUSL=${BABASHKA_MUSL:-} if [ "$BABASHKA_STATIC" = "true" ]; then - args+=("--static") if [ "$BABASHKA_MUSL" = "true" ]; then + args+=("--static") args+=("--libc=musl" # see https://github.com/oracle/graal/issues/3398 "-H:CCompilerOption=-Wl,-z,stack-size=2097152") else # see https://github.com/oracle/graal/issues/3737 + args+=("-H:+UnlockExperimentalVMOptions") args+=("-H:+StaticExecutableWithDynamicLibC") fi fi @@ -106,4 +107,14 @@ then export BABASHKA_FEATURE_PRIORITY_MAP="${BABASHKA_FEATURE_PRIORITY_MAP:-false}" fi +if [[ -z "${BABASHKA_SHA:-}" ]] +then + sha=$(git rev-parse HEAD) + if [[ $? -eq 0 ]]; then + export BABASHKA_SHA=$sha + fi +fi + "$GRAALVM_HOME/bin/native-image" "${args[@]}" "$@" + +./"$BABASHKA_BINARY" describe diff --git a/script/compile.bat b/script/compile.bat index 51abbc72..a78af136 100644 --- a/script/compile.bat +++ b/script/compile.bat @@ -23,6 +23,13 @@ Rem -H:EnableURLProtocols=jar,http,https is also not supported. call %GRAALVM_HOME%\bin\gu.cmd install native-image +if "%BABASHKA_SHA%"=="" ( + for /f %%i in ('git rev-parse HEAD') do set sha=%%i + if not errorlevel 1 ( + set BABASHKA_SHA=%sha% + ) +) + call %GRAALVM_HOME%\bin\native-image.cmd ^ "-jar" "target/babashka-%BABASHKA_VERSION%-standalone.jar" ^ "-H:Name=bb" ^ @@ -39,3 +46,4 @@ call %GRAALVM_HOME%\bin\native-image.cmd ^ if %errorlevel% neq 0 exit /b %errorlevel% call bb "(+ 1 2 3)" +call bb describe diff --git a/script/install-graalvm b/script/install-graalvm index dd27675a..13631c63 100755 --- a/script/install-graalvm +++ b/script/install-graalvm @@ -4,7 +4,7 @@ set -euo pipefail INSTALL_DIR="${1:-$HOME}" -GRAALVM_VERSION="${GRAALVM_VERSION:-22}" +GRAALVM_VERSION="${GRAALVM_VERSION:-23}" GRAALVM_PLATFORM=$BABASHKA_PLATFORM @@ -19,7 +19,7 @@ esac GRAALVM_DIR_NAME="graalvm-$GRAALVM_VERSION" GRAALVM_FILENAME="graalvm-jdk-${GRAALVM_VERSION}_${GRAALVM_PLATFORM}-${GRAALVM_ARCH}_bin.tar.gz" -DOWNLOAD_URL="https://download.oracle.com/graalvm/22/archive/${GRAALVM_FILENAME}" +DOWNLOAD_URL="https://download.oracle.com/graalvm/23/archive/${GRAALVM_FILENAME}" pushd "$INSTALL_DIR" >/dev/null diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index 03adfbd1..4c5e5bdc 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -328,6 +328,7 @@ java.lang.ProcessBuilder$Redirect java.lang.Runtime java.lang.RuntimeException + java.lang.SecurityException java.lang.Short java.lang.StackTraceElement java.lang.String @@ -831,6 +832,7 @@ RuntimeException java.lang.RuntimeException Process java.lang.Process ProcessBuilder java.lang.ProcessBuilder + SecurityException java.lang.SecurityException Short java.lang.Short StackTraceElement java.lang.StackTraceElement String java.lang.String diff --git a/src/babashka/impl/clojure/core.clj b/src/babashka/impl/clojure/core.clj index 44a0800e..917b8f01 100644 --- a/src/babashka/impl/clojure/core.clj +++ b/src/babashka/impl/clojure/core.clj @@ -122,7 +122,7 @@ :static true} ([aseq] (try (clojure.lang.RT/seqToTypedArray (seq aseq)) - (catch IllegalArgumentException _ + (catch Throwable _ (clojure.lang.RT/seqToTypedArray Object (seq aseq))))) ([type aseq] (clojure.lang.RT/seqToTypedArray type (seq aseq)))) @@ -179,6 +179,8 @@ 'sync (sci/copy-var sync clojure-core-ns) 'ref (sci/copy-var ref clojure-core-ns) 'ref-set (sci/copy-var ref-set clojure-core-ns) + 'ensure (sci/copy-var ensure clojure-core-ns) + ;; end STM 'update-vals (sci/copy-var update-vals clojure-core-ns) 'update-keys (sci/copy-var update-keys clojure-core-ns) 'parse-boolean (sci/copy-var parse-boolean clojure-core-ns) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index f0dd40a8..2732b5cc 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -110,6 +110,8 @@ (def version common/version) +(def build-commit-sha (or (System/getenv "BABASHKA_SHA") "")) + (defn parse-version [version] (mapv #(Integer/parseInt %) (-> version @@ -261,6 +263,7 @@ Use bb run --help to show this help output. (format (str/trim " {:babashka/version \"%s\" + :git/sha \"%s\" :feature/csv %s :feature/java-nio %s :feature/java-time %s @@ -281,6 +284,7 @@ Use bb run --help to show this help output. :feature/logging %s :feature/priority-map %s}") version + build-commit-sha features/csv? features/java-nio? features/java-time? diff --git a/test/babashka/interop_test.clj b/test/babashka/interop_test.clj index 645dac01..b643a824 100644 --- a/test/babashka/interop_test.clj +++ b/test/babashka/interop_test.clj @@ -75,3 +75,16 @@ (= '(100 100 100 100 100) (->> (Stream/generate (constantly 100)) stream-seq! (take 5)))"))) (is (true? (bb nil "(import [java.util Collection] [java.util.stream Stream] [java.util.function Predicate]) (= '(1 2 3 4 5 6 7 8 9 10) (->> (Stream/iterate 1 inc) stream-seq! (take 10)))")))) + +(deftest regression-test + (is (true? (bb nil "(let [x \"f\"] (String/.startsWith \"foo\" x))")))) + +(deftest clojure-1_12-interop-test + (is (= [1 2 3] (bb nil "(map Integer/parseInt [\"1\" \"2\" \"3\"])"))) + (is (= [1 2 3] (bb nil "(map String/.length [\"1\" \"22\" \"333\"])"))) + (is (= ["1" "22" "333"] (bb nil "(map String/new [\"1\" \"22\" \"333\"])"))) + (is (= 3 (bb nil "(String/.length \"123\")"))) + (is (= "123" (bb nil "(String/new \"123\")")))) + +(deftest clojure-1_12-array-test + (is (true? (bb nil "(instance? Class long/1)"))))