Fork me on GitHub
#babashka
<
2020-02-11
>
jeroenvandijk11:02:13

I've also used https://github.com/owainlewis/yaml Works fine for simple use cases. More complicated yaml files (e.g. with custom tags) are more troublesome if i remember correctly. I've never been able to convert cloudformation yaml to json and edn. I still use online converters for this 🙈 https://github.com/owainlewis/yaml/issues/27#issuecomment-507616380

jeroenvandijk11:02:31

copied it in the issue

jeroenvandijk11:02:27

@borkdude What do you think about adding a missing symbol resolver to Sci? I have a specific use case for this. Now I have a hack:

(let [external-definitions '{a 1 b/x 2 c 5 d 9}
      resolver (fn [sym]
                 (get external-definitions sym))
      code "(+ a b/x c d)"
      ]
  (loop [assignments {}]        
    (let [[state result] (try
                           [:ok (sci/eval-string code {:bindings assignments})]

                           (catch clojure.lang.ExceptionInfo e
                             (if-let [sym (second (re-find  #"Could not resolve symbol: (.*) \[" (ex-message e) ))]
                               (let [missing (symbol sym)]
                                 (if-let [assignment (resolver missing)]
                                   [:retry (assoc assignments missing assignment)]
                                   (throw e)))
                               (throw e))))]
      (case state
        :ok result
        :retry (recur result)))))

borkdude11:02:24

why exactly do you need this?

borkdude11:02:16

why don't you pass the external-definitions in as bindings?

jeroenvandijk11:02:39

I would like Sci to tell me what I need, but i'll explain

jeroenvandijk11:02:44

Ok it is a long story, but here it goes. I'm writing a aws lambda function in clojure. I'm testing it locally in my repl. However it needs to run in sci. Sci needs the definition of the code. In my case it is 5 functions I need to paste or somehow get as a string in Sci. If there would be a resolver I could do this a bit less manually (i'm not actually doing it manually, but it's uggly code like above)

jeroenvandijk11:02:08

Does it make sense?

jeroenvandijk11:02:24

Otherwise i'll just stick with my hack and show my use case when it is done

borkdude11:02:03

I don't get it since your resolver does the same as sci would do when you would pass those as bindings

borkdude11:02:26

you might have a good use case, but I'm not getting it yet

borkdude11:02:13

note that the resolve function might not work well with DCE of graalvm and CLJS advanced, so it's bit of a risk to let users do it in arbitrary ways

jeroenvandijk12:02:23

I'll show my use case later. I can work around it

Jakub HolĂ˝ (HolyJak)13:02:17

Hi! Trying to include Cognitect's aws-api as built-in in bb fails with > AnalysisGraphBuilderPhase: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.ClassLoader.defineClass(String, byte[], int, int) is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class > at parsing clojure.lang.DynamicClassLoader.defineClass(DynamicClassLoader.java:46) > at org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2470) > at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:92) > at org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3272) Is there any way to fix that? Thank you!

borkdude13:02:15

can you track it down to a specific part in aws-api which causes this?

borkdude13:02:51

one other problematic part might be https://github.com/cognitect-labs/aws-api/blob/2f966de5e4308b4f9039f13af8a388d63f5c437a/src/cognitect/aws/dynaload.clj#L6 due to locking, so you would have to patch that as well

borkdude13:02:35

I think it would make sense to fork this lib and simplify parts around resolve and locking, until it works with graalvm

Jakub HolĂ˝ (HolyJak)16:02:12

Thanks a lot for looking into it! So far, GraalVM is dark magic to me so I will likely take the cljs route for now.

borkdude16:02:32

it is pretty dark magic

mbjarland11:02:30

Graal compiles make you realize the luxury of living on the "no you don't need to care what version of glibc / zlib / esoteric-thing happens to be installed on your build machine" JVM

jeroenvandijk14:02:03

@holyjak I've ported cognitect.aws.util and cognitect.aws.signers to cljs. I think those namespaces by itself would also compile to GraalVM. This gives you the signing parts of AWS requests. To do a proper request you still need to do some manual work. So if you have other options I would advice against trying to this via GraalVM

👍 4
jeroenvandijk14:02:15

If you want to try anyway, i would remove all the http client stuff and see if it compiles. If it does than you just need to use a different http client. E.g. ring-curl works with GraalVM

borkdude14:02:50

clj-http-lite also works with graalvm and bb

borkdude14:02:09

but that might not have the things you need security wise? don't know

jeroenvandijk14:02:31

the ring-curl was chosen because of the SSL issue when you compile it on github actions

jeroenvandijk14:02:46

I think if you compile it locally clj-http-lite etc would be fine