dhall-rust icon indicating copy to clipboard operation
dhall-rust copied to clipboard

wasm-unknown-unknown support?

Open tocklime opened this issue 5 years ago • 13 comments

I tried using serde_dhall in my seed project (compiling to wasm-unknown-unknown). This doesn't compile becuase it relies on the blocking feature of reqwest, which doesn't appear to be implemented in reqwest wasm mode.

tocklime avatar May 29 '20 16:05 tocklime

I see. From what I read, reqwest::get and reqwest::Client are accessible in wasm, but only as async functions. So I'd need to make import resolution async. I've been wanting to do that anyways, to speed up import resolution, but that would be a lot of work. As an easier workaround I guess I could just use https://docs.rs/async-std/1.6.0/async_std/task/fn.block_on.html

Nadrieril avatar May 29 '20 20:05 Nadrieril

Could you try running your code with https://github.com/Nadrieril/dhall-rust/pull/167 ? I removed the use of reqwest's blocking feature, but there might be other issues that prevent building on wasm

Nadrieril avatar May 29 '20 21:05 Nadrieril

I've tried with

serde_dhall = { git = "https://github.com/Nadrieril/dhall-rust", branch = "wasm" }

in dependencies, and when I run

wasm-pack build --target web --out-name package --dev 2>&1 > err.log

I get the attached error log. err.log

tocklime avatar May 30 '20 08:05 tocklime

Ugh ok, turns out hyper and tokio don't support wasm. The wasm branch builds with wasm-pack now. Can you try it? You seem to have another error related to parsing dhall.abnf. Make sure to fetch the dhall-lang submodule, using git submodule update.

Nadrieril avatar May 30 '20 10:05 Nadrieril

I've checked out the wasm branch locally. Running cargo make in that directory ends up with the same dhall.abnf errors. I'm building on windows here. Is that supported? is there some build tool I need to be installed?

I've run git submodule {init,update}

tocklime avatar May 30 '20 11:05 tocklime

Ah, I never tried compiling on windows. I think I remember that windows doesn't support symlinks; what do you see in dhall/src/syntax/text/dhall.abnf? Does it work if you manually remove dhall/src/syntax/text/dhall.abnf and replacing it with a copy of dhall-lang/standard/dhall.abnf?

Nadrieril avatar May 30 '20 12:05 Nadrieril

Another potential issue is line endings: git tries to be clever with line endings on different platforms and that might break the abnf parser. But as far as I can see it works with dos line endings too.

Nadrieril avatar May 30 '20 12:05 Nadrieril

Aha. What was supposed to be the symlink was a text file containing the path to the target. Replaced it with the correct dhall.abnf, and it compiles. Also my project with a reference to the local serde_dhall also compiles now.

tocklime avatar May 30 '20 12:05 tocklime

Yay! I'm fixing windows support here: https://github.com/Nadrieril/dhall-rust/pull/168. Once both this and https://github.com/Nadrieril/dhall-rust/pull/167 get merged, it should work out of the box for you.

Nadrieril avatar May 30 '20 13:05 Nadrieril

I released version 0.5.3 that should support wasm and windows

Nadrieril avatar May 30 '20 14:05 Nadrieril

Thanks, that does indeed compile and work... until I actually try to use dhall's import mechanism. For example:

let map = https://prelude.dhall-lang.org/List/map

Then I get:

panicked at 'can't block with web assembly', src/libstd/sys/wasm/condvar.rs:21:9

tocklime avatar May 31 '20 11:05 tocklime

Ah >< I was afraid something like that might be the reason why reqwest didn't support blocking on wasm. Well then the only option is to make a big chunk of dhall-rust async. I'm sorry to say that this would involve considerable work, and I don't currently have the resources to invest a lot of time into dhall. We'll see how that evolves in the following months but I'm not hopeful.

Nadrieril avatar May 31 '20 12:05 Nadrieril

Thanks for your help on this anyway - it's now at a place where I've got something working. And my project is only a MVP / learn how a bunch of technologies work at the moment.

tocklime avatar May 31 '20 14:05 tocklime