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

Web build support #4

Open
Anut-py opened this issue Nov 13, 2022 · 9 comments
Open

Web build support #4

Anut-py opened this issue Nov 13, 2022 · 9 comments
Assignees
Labels
blocked Cannot make progress right now enhancement New feature or request p:high High priority web Problems with the bindings on the web

Comments

@Anut-py
Copy link
Owner

Anut-py commented Nov 13, 2022

Set up h-raylib to work with emscripten and support building to WebAssembly.

@Anut-py Anut-py self-assigned this Nov 13, 2022
@Anut-py Anut-py added the enhancement New feature or request label Nov 13, 2022
@Anut-py
Copy link
Owner Author

Anut-py commented Nov 27, 2022

This will be possible when the ghc WebAssembly backend adds support for JS FFI. Then the C code can be compiled with emscripten and the Haskell can be compiled to wasm.

@Anut-py Anut-py added the web Problems with the bindings on the web label Dec 18, 2022
@Ashe
Copy link

Ashe commented Sep 10, 2023

Do we know if GHC has made any progress on this? I feel like h-raylib could handle this this could become a really simple and universal method of getting into haskell gamedev. I feel like it'd be a huge challenge to get this working and I wouldn't know where to begin, but if you think it's possible then there's hope maybe? :)

@Anut-py
Copy link
Owner Author

Anut-py commented Sep 13, 2023

Web building with GHC is still a somewhat complex process (this has the instructions. It seems a lot simpler than it was when I created this issue though).

What I had in mind for this was to compile the Raylib C code using emscripten (as described here), which would output JS equivalents to the raylib functions. Then the Haskell code would be compiled using GHC's web build support. The main problem is finding a way to link the two together (i.e. call the JS functions from Haskell). I found this article about it (the article is about Asterius, which has since been merged into GHC), so it should be possible.

@Anut-py
Copy link
Owner Author

Anut-py commented Sep 15, 2023

Update: I was able to make a simple example using haskell to call JS functions. Once it's cleaned up a bit I'll create a repository for it.

@Anut-py
Copy link
Owner Author

Anut-py commented Sep 15, 2023

Here's the proof-of-concept repository: https://github.com/Anut-py/ghc-web-test

As I said, the Haskell-to-WASM compilation process is a bit of a hassle, but it's relatively simple with Nix. Now that this is done I have to figure out how to call the raylib functions through WASM.

@Anut-py
Copy link
Owner Author

Anut-py commented Sep 19, 2023

I integrated raylib into the repository above. I'll add this to h-raylib as soon as possible.

@Anut-py
Copy link
Owner Author

Anut-py commented Jan 25, 2024

I have (in the web branch) added experimental web support and converted the basic-window example into a web-compatible example. Unfortunately, ghc's wasm backend does not yet support Template Haskell, which is required for the changes I made*, so we'll have to wait a bit. TH support for the wasm backend is being worked on, and you can track the progress here.

* The changes to support the web actually don't require TH; I made a TH function to make writing h-raylib/web programs easier, which is why Template Haskell support is necessary. See Raylib.Util.raylibApplication and the basic-window example for more (in the web branch, of course).

@Anut-py Anut-py added p:high High priority blocked Cannot make progress right now labels Jan 30, 2024
@realbogart
Copy link

First of all, you are doing great work here! I'm very excited about the possibility of running a Haskell/raylib game in the browser.

The changes to support the web actually don't require TH; I made a TH function to make writing h-raylib/web programs easier, which is why Template Haskell support is necessary. See Raylib.Util.raylibApplication and the basic-window example for more (in the web branch, of course).

Does this mean that it's possible to skip raylibApplication to get web working without template haskell? I'm eager to get the web support 😄

Thanks!

@Anut-py
Copy link
Owner Author

Anut-py commented Apr 8, 2024

It’s been a while since I made that comment. At the moment, h-raylib uses a lot of template haskell internally, so I don’t think it is possible to get it to work. Afaik we’ll just have to wait for ghc wasm support for template haskell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Cannot make progress right now enhancement New feature or request p:high High priority web Problems with the bindings on the web
Projects
None yet
Development

No branches or pull requests

3 participants