Fork me on GitHub
#shadow-cljs
<
2020-10-24
>
nivekuil08:10:30

how is wasm support nowadays? I think I will try to get https://github.com/antelle/argon2-browser working. I installed it from npm and tried requiring it in cljs, but it looks like something can't even read the wasm magic header: {:line 1, :column 0, :message "Character '\0' (U+0000) is not a valid identifier start char"}

thheller08:10:36

@kevin842 bundling wasm is not supported. you can still use wasm, just not bundle it

nivekuil08:10:08

yeah, but I figured I would try to get it working like in https://github.com/thheller/wasm-pack-cljs

nivekuil08:10:12

or is it still too far away to bother?

thheller08:10:04

it all depends on the generated JS that comes with the .wasm file

thheller08:10:30

some works fine out of the box. some will never work.

nivekuil08:10:01

well, reading the generated JS doesn't seem that bad, being only ￱~￱600 lines prettified, but I wish there were better error messages to even see what's going on

thheller08:10:14

as well as the require stuff

thheller08:10:51

the rest looks straightforward

thheller08:10:14

ah nevermind that wasn't the generated file

thheller08:10:07

hmm yeah the generated file looks much worse

nivekuil09:10:46

how so? some of the code in there is for node.js, so maybe that's why.. but I am having trouble even figuring out what to look for, is there a resource?

thheller09:10:41

I didn't write anything beyond the example repo I made

thheller09:10:51

not aware of anyone else doing stuff with wasm

thheller09:10:37

what doesn't work is any kind of JS that expects the bundler to provide the .wasm file

thheller09:10:04

if there is a variant that uses fetch or xhr to load the .wasm file then this variant should be used

thheller09:10:20

and you just copy the .wasm file somewhere and provide the path (assuming thats possible)

thheller09:10:48

unfortunately the emscripten generated code is quite terrible and contains a lot of useless loading code

thheller09:10:09

all this dynamic figuring out which runtime it is in needs to be removed

nivekuil09:10:22

that's unfortunate.. you think the rust wasm toolchain is friendlier than emscripten?

thheller09:10:40

last time I checked it generated better JS yes

thheller09:10:35

its been a while since I looked at it though and it was completely different the time I checked before that

thheller09:10:17

don't think the "standard" for this is any further along too

thheller09:10:33

so no clue. I only follow casually

nivekuil09:10:39

this one seems to work out of the box: https://github.com/Daninet/hash-wasm

nivekuil09:10:03

I wonder what the difference is. anyway thanks for the help :)

wombawomba16:10:01

So I’m trying to upgrade shadow-cljs from 2.8 to 2.11.5, and I’m having some problems. Specifically, my build compiles without errors, but my ‘core’ ns doesn’t get loaded when I open my app in a browser. Instead, I see the following error in the browser:

react_devtools_backend.js:2450 Failed to load foo/core.cljs SyntaxError: Unexpected identifier
    at eval (<anonymous>)
    at Object.goog.globalEval (base.js:577)
    at Object.shadow$cljs$devtools$client$browser$script_eval [as script_eval] (browser.cljs:23)
    at Object.shadow$cljs$devtools$client$browser$do_js_load [as do_js_load] (browser.cljs:35)
    at eval (browser.cljs:56)
    at eval (env.cljs:232)
    at Object.shadow$cljs$devtools$client$env$do_js_reload_STAR_ [as do_js_reload_STAR_] (env.cljs:204)
    at Function.eval [as cljs$core$IFn$_invoke$arity$4] (env.cljs:240)
    at Object.shadow$cljs$devtools$client$browser$do_js_reload [as do_js_reload] (browser.cljs:48)
    at eval (browser.cljs:92)
Any idea what might be causing this, or how I can fix it?

wombawomba16:10:40

Okay I figured it out. I had a function marked as ^:export, and it started working as soon as I removed that keyword. Has ^:export been deprecated, or could there be something else going on?

wombawomba16:10:46

…I assume that ^:export is intended to work, considering that it’s mentioned in the documentation: https://shadow-cljs.github.io/docs/UsersGuide.html#_working_with_optimizations

thheller16:10:41

:export has not been changed. it works just like before.

wombawomba13:10:27

Alright, good to know.

wombawomba13:10:48

Any idea why it would break my code?

afhammad19:10:26

I can't get shadow-cljs to bundle an npm library with a node-script target. I've installed the lib via npm, its in my packages.json, also added a deps.cljs:

{:npm-deps {"xmlhttprequest" "1.8.0"}}
it's required like this:
["xmlhttprequest" :refer [XMLHttpRequest]]
no complaints on compilation but get
Error: Cannot find module 'xmlhttprequest'
at runtime. What am i missing?

thheller20:10:05

@afhammad node builds don't bundle their dependencies by default since node can just load them from node_modules directly. so either just include the node_modules whereever you are running it or post process the file with something like https://github.com/vercel/ncc

afhammad20:10:11

got it, thanks

nivekuil21:10:46

is is possible to target specific node￱_￱modules dependencies to be compiled with :advanced? like:js-provider :closure but for specific modules, not the whole app