Compare commits
13 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e49a4c0707 | ||
|
|
2e2ce50f60 | ||
|
|
98779b1f7a | ||
|
|
218dc24292 | ||
|
|
a089394221 | ||
|
|
cf20734557 | ||
|
|
ea50cbfd97 | ||
|
|
2bc0967e2c | ||
|
|
f3ed0c4ab3 | ||
|
|
d2c1d93240 | ||
|
|
63c37c838d | ||
|
|
5453a32685 | ||
|
|
c802c1c852 |
6 changed files with 103 additions and 5 deletions
13
project.clj
13
project.clj
|
|
@ -12,7 +12,6 @@
|
|||
"deps.clj/src" "deps.clj/resources"]
|
||||
;; for debugging Reflector.java code:
|
||||
;; :java-source-paths ["sci/reflector/src-java"]
|
||||
:java-source-paths ["src-java"]
|
||||
:resource-paths ["resources" "sci/resources"]
|
||||
:test-selectors {:windows :windows}
|
||||
:dependencies [[org.clojure/clojure "1.11.0-alpha1"]
|
||||
|
|
@ -22,7 +21,10 @@
|
|||
[cheshire "5.10.0"]
|
||||
[nrepl/bencode "1.1.0"]
|
||||
[borkdude/sci.impl.reflector "0.0.1"]
|
||||
[org.clojure/test.check "1.1.0"]]
|
||||
[org.clojure/test.check "1.1.0"]
|
||||
;; core async was moved from the core async feature to here,
|
||||
;; because it is used in tasks
|
||||
[org.clojure/core.async "1.3.610"]]
|
||||
:profiles {:feature/xml {:source-paths ["feature-xml"]
|
||||
:dependencies [[org.clojure/data.xml "0.2.0-alpha6"]]}
|
||||
:feature/yaml {:source-paths ["feature-yaml"]
|
||||
|
|
@ -33,8 +35,7 @@
|
|||
;:feature/oracledb [:feature/jdbc {:dependencies [[com.oracle.database.jdbc/ojdbc8 "19.8.0.0"]]}]
|
||||
:feature/oracledb [:feature/jdbc {:dependencies [[io.helidon.integrations.db/ojdbc "2.1.0"]]}] ; ojdbc10 + GraalVM config, by Oracle
|
||||
:feature/hsqldb [:feature/jdbc {:dependencies [[org.hsqldb/hsqldb "2.5.1"]]}]
|
||||
:feature/core-async {:source-paths ["feature-core-async"]
|
||||
:dependencies [[org.clojure/core.async "1.3.610"]]}
|
||||
:feature/core-async {:source-paths ["feature-core-async"]}
|
||||
:feature/csv {:source-paths ["feature-csv"]
|
||||
:dependencies [[org.clojure/data.csv "1.0.0"]]}
|
||||
:feature/transit {:source-paths ["feature-transit"]
|
||||
|
|
@ -76,7 +77,9 @@
|
|||
:feature/selmer
|
||||
{:dependencies [[com.clojure-goes-fast/clj-async-profiler "0.4.1"]
|
||||
[com.opentable.components/otj-pg-embedded "0.13.3"]]}]
|
||||
:uberjar {:global-vars {*assert* false}
|
||||
:uberjar {:java-source-paths ["src-java"]
|
||||
:dependencies [[org.graalvm.nativeimage/svm "21.1.0"]]
|
||||
:global-vars {*assert* false}
|
||||
:jvm-opts ["-Dclojure.compiler.direct-linking=true"
|
||||
"-Dclojure.spec.skip-macros=true"
|
||||
"-Dborkdude.dynaload.aot=true"]
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ call %GRAALVM_HOME%\bin\native-image.cmd ^
|
|||
"-H:Log=registerResource:" ^
|
||||
"--no-fallback" ^
|
||||
"--verbose" ^
|
||||
"-H:NativeLinkerOption=prefs.lib" ^
|
||||
"-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileReader" ^
|
||||
"-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileReader" ^
|
||||
"-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.MixerProvider" ^
|
||||
|
|
|
|||
60
src-java/babashka/impl/Graal.java
Normal file
60
src-java/babashka/impl/Graal.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package babashka.impl;
|
||||
|
||||
import org.graalvm.nativeimage.c.function.CFunction;
|
||||
import org.graalvm.nativeimage.c.function.CFunction.Transition;
|
||||
import org.graalvm.nativeimage.c.function.CLibrary;
|
||||
import org.graalvm.nativeimage.c.CContext;
|
||||
import org.graalvm.nativeimage.c.type.CCharPointer;
|
||||
import com.oracle.svm.core.c.ProjectHeaderFile;
|
||||
import org.graalvm.nativeimage.c.type.CTypeConversion;
|
||||
import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
@CContext(Graal.MyDirectives.class)
|
||||
public class Graal {
|
||||
|
||||
static class MyDirectives implements CContext.Directives {
|
||||
|
||||
@Override
|
||||
public List<String> getHeaderFiles() {
|
||||
return Collections.singletonList("<stdlib.h>");
|
||||
}
|
||||
}
|
||||
|
||||
@CFunction
|
||||
private static native int setenv(CCharPointer name, CCharPointer value, int overwrite);
|
||||
|
||||
@CFunction
|
||||
private static native CCharPointer getenv(CCharPointer name);
|
||||
|
||||
// Public API
|
||||
|
||||
public static boolean setEnv(String name, String value) {
|
||||
return setEnv(name, value, true);
|
||||
}
|
||||
|
||||
public static boolean setEnv(String name, String value, boolean overwrite) {
|
||||
boolean ret = false;
|
||||
try (CCharPointerHolder nameHolder = CTypeConversion.toCString(name)) {
|
||||
CCharPointerHolder valueHolder = CTypeConversion.toCString(value);
|
||||
int w = (overwrite ? 1 : 0);
|
||||
int cRet = setenv(nameHolder.get(), valueHolder.get(), w);
|
||||
ret = (cRet == 0 ? true : false);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getEnv(String name) {
|
||||
try (CCharPointerHolder nameHolder = CTypeConversion.toCString(name);) {
|
||||
CCharPointer p = getenv(nameHolder.get());
|
||||
String ret = CTypeConversion.toJavaString(p);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(setEnv(args[0], args[1]));
|
||||
System.out.println(getEnv(args[0]));
|
||||
}
|
||||
}
|
||||
14
src/babashka/impl/os.clj
Normal file
14
src/babashka/impl/os.clj
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(ns babashka.impl.os
|
||||
{:no-doc true}
|
||||
(:require [babashka.os :as os]
|
||||
[sci.core :as sci]))
|
||||
|
||||
(def ons (sci/create-ns 'babashka.os nil))
|
||||
|
||||
(def os-namespace
|
||||
{'set-env (sci/copy-var os/set-env ons)
|
||||
'get-env (sci/copy-var os/get-env ons)})
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
[babashka.impl.error-handler :refer [error-handler]]
|
||||
[babashka.impl.features :as features]
|
||||
[babashka.impl.fs :refer [fs-namespace]]
|
||||
[babashka.impl.os :refer [os-namespace]]
|
||||
[babashka.impl.pods :as pods]
|
||||
[babashka.impl.pprint :refer [pprint-namespace]]
|
||||
[babashka.impl.process :refer [process-namespace]]
|
||||
|
|
@ -321,6 +322,7 @@ Use bb run --help to show this help output.
|
|||
'clojure.java.shell shell-namespace
|
||||
'babashka.wait {'wait-for-port wait/wait-for-port
|
||||
'wait-for-path wait/wait-for-path}
|
||||
'babashka.os os-namespace
|
||||
'babashka.signal {'pipe-signal-received? pipe-signal-received?}
|
||||
'clojure.java.io io-namespace
|
||||
'cheshire.core cheshire-core-namespace
|
||||
|
|
|
|||
18
src/babashka/os.clj
Normal file
18
src/babashka/os.clj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(ns babashka.os)
|
||||
|
||||
(defmacro if-graal [then else]
|
||||
(if (resolve 'babashka.impl.Graal)
|
||||
then
|
||||
else))
|
||||
|
||||
(defn set-env
|
||||
([name value] (set-env name value true))
|
||||
([name value overwrite?]
|
||||
(if-graal
|
||||
(babashka.impl.Graal/setEnv name value overwrite?)
|
||||
(throw (UnsupportedOperationException. "set-env is only available in the native image.")))))
|
||||
|
||||
(defn get-env [name]
|
||||
(if-graal
|
||||
(babashka.impl.Graal/getEnv name)
|
||||
(throw (UnsupportedOperationException. "set-env is only available in the native image."))))
|
||||
Loading…
Reference in a new issue