diff --git a/.circleci/config.yml b/.circleci/config.yml index 6ebc49e1..1660268f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,10 +38,10 @@ jobs: curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz tar xzf graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz fi - - run: - name: Install GraalVM SSL libs - command: | - .circleci/script/graalvm_ssl + # - run: + # name: Install GraalVM SSL libs + # command: | + # .circleci/script/graalvm_ssl - run: name: Run JVM tests command: | @@ -96,10 +96,10 @@ jobs: curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz tar xzf graalvm-ce-linux-amd64-19.2.0-dev-b01.tar.gz fi - - run: - name: Install GraalVM SSL libs - command: | - .circleci/script/graalvm_ssl + # - run: + # name: Install GraalVM SSL libs + # command: | + # .circleci/script/graalvm_ssl - run: name: Build binary command: | @@ -159,10 +159,10 @@ jobs: curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.2.0-dev-b01/graalvm-ce-darwin-amd64-19.2.0-dev-b01.tar.gz tar xzf graalvm-ce-darwin-amd64-19.2.0-dev-b01.tar.gz fi - - run: - name: Install GraalVM SSL libs - command: | - .circleci/script/graalvm_ssl + # - run: + # name: Install GraalVM SSL libs + # command: | + # .circleci/script/graalvm_ssl - run: name: Build binary command: | diff --git a/README.md b/README.md index b90e3b92..03804efb 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ through the aliases: From Java the following is available: -- `System`: `exit`, `getProperty`, `getProperties`, `getenv` +- `System`: `exit`, `getProperty`, `setProperty`, `getProperties`, `getenv` Special vars: @@ -185,39 +185,30 @@ Writing file: /tmp/clojure.org.html ## Enabling SSL -If you want to be able to use SSL to e.g. `(slurp "https://www.clojure.org")` -you will need install a runtime dependency called `libsunec.so`. Because I don't -know if I'm allowed to ship this library with babashka, I have chosen to let the -user take care of these and put them in a known location. This also allows you -to include a different `cacerts`. +If you want to be able to use SSL to e.g. run `(slurp +"https://www.clojure.org")` you will need to add the location where +`libsunec.so` or `libsunec.dylib` is located to the `java.library.path` Java +property. This library comes with most JVM installations, so you might already +have it on your machine. It is usually located in `/jre/lib` or +`/jre//lib`. It is also bundled with GraalVM. -To enable SSL, create a `~/.babashka/lib` directory and copy the`libsunec.so` -(Linux) or `libsunec.dylib` (Mac) to it. This library comes with GraalVM and is -located in `/jre/lib/` inside the distribution. Also create a and -`~/.babashka/lib/security` directory and copy `cacerts` to it which comes -bundled with GraalVM and is located in -`/jre/lib/security`. - -As a shell script: +Example: ``` shellsession -mkdir -p ~/.babashka/lib/security +$ cat /tmp/https_get.clj +#!/usr/bin/env bb -f -# Linux: -cp $GRAALVM_HOME/jre/lib/amd64/libsunec.so ~/.babashka/lib +(System/setProperty + "java.library.path" + "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib") -# Mac: -cp $GRAALVM_HOME/jre/lib/libsunec.dylib ~/.babashka/lib - -cp $GRAALVM_HOME/jre/lib/security/cacerts ~/.babashka/lib/security +(slurp (first *command-line-args*)) ``` -You can download a distribution of GraalVM for your platform on -[Github](https://github.com/oracle/graal/releases). - -More information about GraalVM and SSL can be found -[here](https://blog.taylorwood.io/2018/10/04/graalvm-https.html) and -[here](https://quarkus.io/guides/native-and-ssl-guide). +``` shellsession +$ /tmp/https_get.clj https://www.google.com | bb '(subs *in* 0 50)' +"> args" args)) +#_(defn set-ssl [] (let [home (System/getProperty "user.home") bb-lib-dir (io/file home ".babashka" "lib") lib-path (System/getProperty "java.library.path") @@ -135,7 +136,12 @@ ca-certs (.getPath (io/file ca-certs-dir "cacerts"))] (System/setProperty "java.library.path" (str (.getPath bb-lib-dir) ":" lib-path)) (System/setProperty "javax.net.ssl.trustStore" ca-certs) - (System/setProperty "javax.net.ssl.trustAnchors" ca-certs)) + (System/setProperty "javax.net.ssl.tru stAnchors" ca-certs))) + +(defn main + [& args] + #_(binding [*out* *err*] + (prn ">> args" args)) (let [t0 (System/currentTimeMillis) {:keys [:version :raw-in :raw-out :println? :help? :file :command-line-args diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 66c36044..8e0abdbc 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -84,7 +84,13 @@ (bb nil)))) (deftest ssl-test - (is (re-find #"doctype html" (bb nil "(slurp \"https://www.google.com\")")))) + (let [graalvm-home (System/getenv "GRAALVM_HOME") + lib-path (format "%1$s/jre/lib:%1$s/jre/lib/amd64" graalvm-home) + _ (prn "lib-path" lib-path) + resp (bb nil (format "(System/setProperty \"java.library.path\" \"%s\") + (slurp \"https://www.google.com\")" + lib-path))] + (is (re-find #"doctype html" resp)))) (deftest stream-test (is (= "2\n3\n4\n" (test-utils/bb "1 2 3" "--stream" "(inc *in*)")))