GHC 现在可以在浏览器中运行。
GHC now runs in the browser

原始链接: https://discourse.haskell.org/t/ghc-now-runs-in-your-browser/13169

## GHC 现在可以在浏览器中运行 GHC WASM 后端的重大进展使得 GHC 本身能够完全在 Web 浏览器客户端运行,这通过一个新的 Haskell 游乐场得到了演示。虽然细节将在后续公布,但这展示了 Haskell 移植到 WebAssembly 的进展。 用户正在探索各种可能性,例如加载包(可能的解决方案包括使用 `wasm32-wasi-cabal` 预编译)以及在浏览器中运行 Agda(Agda WASM 发行版已经存在)。 初步测试发现并迅速修复了一个关于 GHC 选项持久化的错误。目前,基于浏览器的 GHC 使用字节码解释器,缺乏调用 C 编译器或直接生成 WASM 代码的能力。启动速度可能较慢,因为需要下载约 50MB 的根文件系统。在最近的 WebKit 错误修复之后,正在调查 Safari 的兼容性。 GHC 的核心库与 WASM 编译配合良好,但动态加载和执行仍然是持续开发的关键领域,这得益于最近的 GHC 补丁。默认安装包括 GHC 库及其依赖项。

## GHC 现在可以在浏览器中运行:摘要 Haskell 编译器 GHC 得益于 WebAssembly (WASM) 后端的进步,现在可以直接在 Web 浏览器中运行。这一成就展示了 GHC 的 WASM 支持的成熟度,展示了它在浏览器环境中编译和运行像自身这样复杂系统的能力。 虽然实际应用仍在涌现,但潜在用途包括教育工具、Haskell 的简化演示,以及探索该语言的更低风险环境。这一消息引发了关于 Haskell 自举挑战(从源代码编译编译器)及其对更广泛部署中的信任和安全性的影响的讨论。 该公告还强调了正在进行的工作,以提高 Haskell 的稳定性和可用性,并提到了语言版本和 Pandoc 等工具作为其持续相关性的例子。最终,在浏览器中运行 GHC 是一项技术壮举,它扩展了对 Haskell 的访问并展示了 WASM 的强大功能。
相关文章

原文

ghc itself can now run purely client-side in the browser, here’s a haskell playground demo. terms and conditions apply, and i’ll write up more detailed explanation some time later, but i thought this is a cool thing to show off how far the ghc wasm backend has advanced :slight_smile:

73 Likes

This is very cool! I wonder how easy it would be to load some packages; cabal in the browser when? I’m also wondering how usable Agda in the browser would be.

3 Likes

I think I found a bug: ghc options persist even after I change them. Edit: this has been fixed!

Also -with-rtsopts=-s does not work, sadly. Edit: Ah, that’s because it is interpreted.

3 Likes

This is awesome!
Perfect for building a fully interactive Haskell online course! :star_struck:

Excellent work - the efforts to bring Haskell to WASM are a huge boon to our ecosystem and userbase!

Can’t run it on my tablet (wasm), curious: is this running the type checker or also code gen to wasm?

1 Like

It runs the code, but it seems like it uses the bytecode interpreter.

1 Like

What modifications were to GHC for it to be compiled to WASM?

1 Like

cabal won’t work in the browser due to lack of process support; but it’s possible to use wasm32-wasi-cabal to precompile some third party packages to wasm and make this playground support them as well.

you might be interested to check GitHub - agda-web/agda-wasm-dist: Distributions of Agda executable compiled into WebAssembly.; afaik they even compiled GitHub - agda/agda-language-server: Language Server for Agda to wasm, not sure how usable it is currently

thanks for the report! i pushed an update which should have fixed it.

that’s right; ghc in browser can’t invoke the c compiler and it can only interpret haskell modules via bytecode.

1 Like

thanks for the reports! a few seconds of freeze during start-time is expected, since it needs to download ~50M of a rootfs tarball and extract it, then link the ghc library and all its dependencies. as for safari, it’s strange since i i just landed a workaround for a webkit bug that breaks the wasm dynamic linker a few days ago, i’ll take a closer look later.

the ghc library already mostly works when compiled to wasm, and it can parse/typecheck/desugar stuff. the bottleneck is the linker/loader part, for it to be useful it needs to be able to dynamically load and execute haskell code. i landed a couple of ghc patches recently to push towards that direction, and the last one that gets us towards the haskell playground (not landed yet) is Draft: Support running GHC fully client-side in the browser (!15000) · Merge requests · Glasgow Haskell Compiler / GHC · GitLab

8 Likes

Which packages are installed by default?

2 Likes

now chrome will consume even more memory :stuck_out_tongue:

Awesome work!

2 Likes

the ghc library and its transitive dependencies.

联系我们 contact @ memedata.com