hi, I made a demo project that compiles ClojureScript to WebAssembly using cherry https://github.com/ieugen/cherry-wasm-demo . And it runs 🙂
share if you are on mastodon https://mas.to/@ieugen/111804996102832877
How are you using cherry in the wasm runtime?
I see you are embedding cherry, but I don't see how you are using it at runtime
I followed the embedding tutorial because I needed a single file for javy to work
What I mean is when you change the source to:
(ns my.cherry
#_(:require [cherry.embed :as cherry]))
#_(cherry/preserve-ns 'cljs.core)
#_(cherry/preserve-ns 'clojure.string)
(defn add [a b]
(+ a b))
(defn init []
(println "Hello from init!" (add 1 3)))
(println "Hello world!" (add 1 4))
your README still works as it stands and the wasm output is around 2mb.
It gets more exciting when you evaluate some CLJS dynamically using cherry.e.g. like this:
(ns my.cherry
(:require [cherry.embed :as cherry]))
(cherry/preserve-ns 'cljs.core)
(cherry/preserve-ns 'clojure.string)
(defn add [a b]
(+ a b))
(defn init []
(let [[_ expr] (.slice js/process.argv 2)]
(cherry/eval-string expr)))you need to find out how to get command line arguments in your wasm runtime though
yeah, I was looking for a LOONG time to have clojure -> wasm . I just got this working (thank you again). I'll play around with it the coming days/weeks and share
cli should be possible
I created an issue and with a little rust knowledge, we might get env and cli args https://github.com/bytecodealliance/javy/issues/592 . I started looking into rust a bit to see if I can make a PR - but it will take some time