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

Make examples runnable with jsaddle-warp #23

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

georgefst
Copy link

@georgefst georgefst commented Oct 17, 2024

Allows running examples locally without targeting WASM, e.g. with cabal run ghc-wasm-miso-examples -- snake. Note that it doesn't work on Firefox: ghcjs/jsaddle#64.

Code is largely adapted from Miso's own example. I don't know whether there's any particular reason this hadn't already been done in this repository. Maybe just that GHC's WASM backend is nowhere near as slow as GHCJS, so it's a bit less important? Anyway, I thought I may as well see whether you'd be interested in upstreaming this before going any further.

There are still quite a few things that could be improved:

  • The two CPP branches in Main.hs are completely separate, so perhaps we're better off using two separate modules and Cabal conditionals instead.
  • The CPP in App.hs is a bit awkward, and potentially overly complicated, since Data.JSString.Internal.Type.JSString is not the same as GHC.Internal.Wasm.Prim.Types.JSString. This is also the reason for the extra annotations in this file and XHR.hs: monomorphising the former gives us some compatiblity. It's possible that jsaddle could be improved to abstract over this difference.
  • After a non-WASM build, building for WASM with ./build.sh requires a cabal clean. Presumably more could be done to keep build folders separate.
  • I've ditched the GHCI stuff (i.e. debug) from the Miso examples for now. This is simpler and easier to understand, since jsaddle-warp has a pretty bad and under-documented API, but it does limit some of the main benefits.
    • It works perfectly well with GHCI (EDIT: except that writing to stdout no longer works...), but when compiled the program immediately just exits.
    • I'm not sure what the purpose of Miso's debugOr 8080 (f >> syncPoint) jsaddleApp is. I've found that just using debug 8000 f works fine.
  • CSS isn't picked up. We can host the CSS files using wai-app-static, replacing jsaddleApp with (jsaddleAppWithJsOr (jsaddleJs False) $ staticApp $ defaultWebAppSettings "frontend"), but I don't know how we can specify stylesheets like in our static HTML since we can't seem to get at the document's head.
  • For some reason, fail "unknown example" isn't called when passing an invalid CLI argument.
  • The XHR example is not yet implemented since it was not trivial to adapt.

Copy link
Member

@amesgen amesgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is largely adapted from Miso's own examples. I don't know whether there's any particular reason this hadn't already been done in this repository. Maybe just that GHC's WASM backend is nowhere near as slow as GHCJS, so it's a bit less important? Anyway, I thought I may as well see whether you'd be interested in upstreaming this before going any further.

Definitely interested, we even had jsaddle-warp support in this repo in the past, but removed it because it caused churn (see #6 (review)). Also, the fact that the WASM backend is much faster than GHCJS definitely is a part of the somewhat reduced benefit.

However, recent social media posts like https://redd.it/1g2lanx show that not everyone not aware of this possibility (which in particular gives HLS support), so I think it would be quite nice to demo this in this repo, thanks for (re)starting that effort! Will take a look soon.

All previous versions are broken, especially without Hackage revisions to add bounds: dmjio/miso#752.
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

Successfully merging this pull request may close these issues.

2 participants