Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHC WebAssembly/JS backend support #724

Open
mikelpr opened this issue Jun 1, 2023 · 9 comments
Open

GHC WebAssembly/JS backend support #724

mikelpr opened this issue Jun 1, 2023 · 9 comments

Comments

@mikelpr
Copy link

mikelpr commented Jun 1, 2023

Is your feature request related to a problem? Please describe.
ghcjs is a bit outdated and stuck at ghc 8.*

Describe the solution you'd like
both tweag's WebAssembly backend and a new JS backend were recently merged into GHC 9 and will probably get the most support going forward wrt haskell on browsers

Additional context
the new JS backend talks about not being complete enough yet (missing Template Haskell) and the WebAssembly backend I don't know if has access to the DOM

anyways, would be exciting!

@noinia
Copy link
Contributor

noinia commented Apr 11, 2024

According to the IOG blog ghcjs-base and friends have been updated to support the ghc js backend, so I think that means this issue has finally become actionable :).

@ysangkok
Copy link

ysangkok commented Apr 17, 2024

Everything seems to compile on ghc 9.10-alpha3 from ghcup and head.hackage with this patch

diff --git a/miso.cabal b/miso.cabal
index dd27739..bf2a39a 100644
--- a/miso.cabal
+++ b/miso.cabal
@@ -137,6 +137,7 @@ library
     hs-source-dirs:
       text-src
   build-depends:
+    ghcjs-base,
     aeson,
     base < 5,
     bytestring,
diff --git a/src/Miso/Html/Types.hs b/src/Miso/Html/Types.hs
index 3310fda..a2b4dfb 100644
--- a/src/Miso/Html/Types.hs
+++ b/src/Miso/Html/Types.hs
@@ -65,7 +65,7 @@ import           Text.HTML.TagSoup          (Tag(..))
 import           Miso.Effect
 import           Miso.Event
 import           Miso.FFI
-import           Miso.String                hiding (reverse)
+import           Miso.String                hiding (elem, reverse)
 
 -- | Core type for constructing a `VTree`, use this instead of `VTree` directly.
 data View action

I use the command

cabal build --with-ghc=javascript-unknown-ghcjs-ghc --with-ghc-pkg=javascript-unknown-ghcjs-ghc-pkg --allow-newer

But I run out of memory during linking of the first demo application in the README. Only have 8G of RAM on this laptop, will try another machine some other day if nobody else in this thread has time...

@hasufell
Copy link

hasufell commented Apr 17, 2024

I ran the test suite (needed a change for aeson-2) and also had to pass --with-hsc2hs=javascript-unknown-ghcjs-hsc2hs to cabal. It succeeded.


edit: apparently have to run the test through the browsers. There I get:

uncaught exception in Haskell main thread: ReferenceError: h$splitmix_init is not defined

@hasufell
Copy link

haskellari/splitmix#75

@amesgen
Copy link
Contributor

amesgen commented Apr 17, 2024

As another resource: We have some examples of how to use Miso with the WASM backend here: https://github.com/tweag/ghc-wasm-miso-examples

@hasufell
Copy link

uncaught exception in Haskell main thread: ReferenceError: h$splitmix_init is not defined

Fixing that with a source-repository-package stanza in cabal.project now leads to:

uncaught exception in Haskell main thread: ReferenceError: $1 is not defined

The offending generated code is:

function h$$72640042() {var a=h$stack[(h$sp-1)];
h$sp-=2;
window.global_test_results = $1;(a);
return h$rs();
};

@hasufell
Copy link

As another resource: We have some examples of how to use Miso with the WASM backend here: https://github.com/tweag/ghc-wasm-miso-examples

Doesn't work here: tweag/ghc-wasm-miso-examples#10

@ysangkok
Copy link

Seems like the JavaScript part of this issue is addressed in:

@mikelpr
Copy link
Author

mikelpr commented Apr 30, 2024

has anyone done a size comparison between WASM and (the new) GHC JS backends? considering @dmjio worries about size on #738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants