Skip to content

Commit

Permalink
[babashka#332] support GraalVM java11
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored and bbss committed Aug 18, 2020
1 parent 4afed64 commit 116b185
Show file tree
Hide file tree
Showing 11 changed files with 720 additions and 19 deletions.
28 changes: 15 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
jvm:
docker:
# specify the version you desire here
- image: circleci/clojure:lein-2.8.1
- image: circleci/clojure:openjdk-11-lein-2.8.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
node:
docker:
# specify the version you desire here
- image: circleci/clojure:lein-2.8.1-node
- image: circleci/clojure:openjdk-11-lein-2.8.1-node
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
Expand All @@ -62,11 +62,11 @@ jobs:
key: v1-dependencies-{{ checksum "project.clj" }}
linux:
docker:
- image: circleci/clojure:lein-2.8.1
- image: circleci/clojure:openjdk-11-lein-2.8.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
GRAALVM_HOME: /home/circleci/graalvm-ce-19.1.1
GRAALVM_HOME: /home/circleci/graalvm-ce-java11-20.1.0
# SCI_TEST_ENV: native
steps:
- checkout
Expand All @@ -82,9 +82,9 @@ jobs:
name: Download GraalVM
command: |
cd ~
if ! [ -d graalvm-ce-19.1.1 ]; then
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.1.1/graalvm-ce-linux-amd64-19.1.1.tar.gz
tar xzf graalvm-ce-linux-amd64-19.1.1.tar.gz
if ! [ -d graalvm-ce-java11-20.1.0 ]; then
curl -O -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz
tar xzf graalvm-ce-java11-linux-amd64-20.1.0.tar.gz
fi
- run:
name: Build binary
Expand All @@ -98,7 +98,7 @@ jobs:
- save_cache:
paths:
- ~/.m2
- ~/graalvm-ce-19.1.1
- ~/graalvm-ce-java11-20.1.0
key: linux-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }}
- store_artifacts:
path: /tmp/release
Expand All @@ -107,7 +107,8 @@ jobs:
macos:
xcode: "9.0"
environment:
GRAALVM_HOME: /Users/distiller/graalvm-ce-19.1.1/Contents/Home
GRAALVM_HOME: /Users/distiller/graalvm-ce-java11-20.1.0/Contents/Home
JAVA_HOME: /Users/distiller/graalvm-ce-java11-20.1.0/Contents/Home
SCI_TEST_ENV: native
steps:
- checkout
Expand All @@ -127,9 +128,9 @@ jobs:
command: |
cd ~
ls -la
if ! [ -d graalvm-ce-19.1.1 ]; then
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.1.1/graalvm-ce-darwin-amd64-19.1.1.tar.gz
tar xzf graalvm-ce-darwin-amd64-19.1.1.tar.gz
if ! [ -d graalvm-ce-java11-20.1.0 ]; then
curl -O -sL curl -O -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-darwin-amd64-20.1.0.tar.gz
tar xzf graalvm-ce-java11-darwin-amd64-20.1.0.tar.gz
fi
- run:
name: Build binary
Expand All @@ -139,11 +140,12 @@ jobs:
- run:
name: Run tests
command: |
export PATH=$GRAALVM_HOME/bin:$PATH
script/test/native
- save_cache:
paths:
- ~/.m2
- ~/graalvm-ce-19.1.1
- ~/graalvm-ce-java11-20.1.0
key: mac-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }}
- store_artifacts:
path: /tmp/release
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,29 @@ More examples of what is currently possible can be found at

If you miss something, feel free to post an issue.

## Caveats
## GraalVM

### Random numbers

To make the `rand-*` functions behave well when compiling to a GraalVM native binary, use this setting:

``` clojure
--initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder
```

### Java 11

To use sci with GraalVM java11 override the dependency
`[borkdude/sci.impl.reflector "0.0.1"]` to `[borkdude/sci.impl.reflector
"0.0.1-java11]` in your `project.clj` or `deps.edn`.

Also you'll likely need a fix for `clojure.lang.Reflector`:

See
[clj-graal-docs](https://github.com/lread/clj-graal-docs#jdk11-and-clojurelangreflector)
and
[clj-reflector-graal-java11-fix](https://github.com/borkdude/clj-reflector-graal-java11-fix).

## Use from JavaScript

Sci is available on NPM:
Expand Down
4 changes: 3 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
:url "http://opensource.org/licenses/eclipse-1.0.php"}
:source-paths ["src"]
:dependencies [[org.clojure/clojure "1.9.0"]
[borkdude/sci.impl.reflector "0.0.1"] ;; use 0.0.1-jdk11 with JDK 11
[borkdude/edamame "0.0.11-alpha.12"]
[borkdude/sci.impl.reflector "0.0.1"]
[org.clojure/tools.reader "1.3.2"]]
:plugins [[lein-codox "0.10.7"]]
:profiles {:clojure-1.9.0 {:dependencies [[org.clojure/clojure "1.9.0"]]}
Expand All @@ -26,6 +26,8 @@
"-Dclojure.spec.skip-macros=true"]
:aot :all
:main sci.impl.main}
:native-image {:dependencies [[borkdude/sci.impl.reflector "0.0.1-jdk11"]
[borkdude/clj-reflector-graal-java11-fix "0.0.1-graalvm-20.1.0"]]}
:libsci {:dependencies [[cheshire "5.10.0"]]
:source-paths ["src" "libsci/src"]}}
;; for testing only
Expand Down
1 change: 1 addition & 0 deletions reflector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.clj
4 changes: 2 additions & 2 deletions reflector/project.clj → reflector/project.clj.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defproject borkdude/sci.impl.reflector "0.0.1"
(defproject borkdude/sci.impl.reflector "{{version}}"
:dependencies [[org.clojure/clojure "1.9.0"]]
:java-source-paths ["src-java"]
:java-source-paths ["{{java-source-path}}"]
:deploy-repositories [["clojars" {:url "https://clojars.org/repo"
:username :env/clojars_user
:password :env/clojars_pass
Expand Down
5 changes: 5 additions & 0 deletions reflector/script/deploy_java11
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

export SCI_REFLECTOR_JAVA11=true
script/update-project.clj
lein deploy clojars
5 changes: 5 additions & 0 deletions reflector/script/deploy_java8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

export SCI_REFLECTOR_JAVA11=false
script/update-project.clj
lein deploy clojars
26 changes: 26 additions & 0 deletions reflector/script/update-project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env clojure -Sdeps {:deps,{selmer,{:mvn/version,"1.12.17"}}}

(require '[selmer.parser :as p])
(require '[clojure.java.io :as io])

(def version (str "0.0.1"
(if (= "true" (System/getenv "SCI_REFLECTOR_JAVA11"))
"-java11"
"")))

(def java-source-path (str "src-java"
(if (= "true" (System/getenv "SCI_REFLECTOR_JAVA11"))
"11"
"8")))

(spit "project.clj" (str ";; GENERATED by script/update-project.clj, DO NOT EDIT\n"
"\n"
(p/render (slurp (io/file "project.clj.template"))
{:version version
:java-source-path java-source-path})))


;; [[org.clojure/clojurescript "1.10.520"] ;; for extraction tests
;; [clj-commons/conch "0.9.2"]
;; [jonase/eastwood "0.3.6"]
;; [borkdude/missing.test.assertions "0.0.1"]]
Loading

0 comments on commit 116b185

Please sign in to comment.