MyNixOS website logo
Description

Allow GHCJS projects to compile under GHC and develop using intero.

Allow GHCJS projects to compile under GHC and develop using intero. Please refer to README.md.

Hackage Build Status

Motivation

Javascript projects using GHCJS must use ghcjs-base, which cannot be compiled by GHC as it requires JavaScriptFFI. This package is is drop-in-replacement (same type signature, module namespace) for ghcjs-base that can be compiled in GHC.

When using GHCJS to compile, the original modules from ghjs-base is exported.

When using GHC to compile, fake stubs are emitted for all the ghcjs-base javascript functions, so this is not meant for production use with GHC.

However, this will allow tooling (such as intero, generating haddocks) to use the much faster GHC to compile GHCJS projects.

Prod GHC use case

For project that need to compile to both GHC and GHCJS for production, consider using jsaddle, which compiles to ghcjs-dom under GHC. However, the type signatures will change as the the IO monad becomes the JSM monad.

Usage

In your project cabal file, instead of using ghcjs-base, use ghcjs-base-stub

build-depends: ghcjs-base-stub

Version 0.1.x.x of ghjc-base-stub did not re-export the original ghcjs-base when compiling under GHCJS. Version 0.2.x.x re-exports ghjs-base so that cabal.project does not need preprocesisng to select which ghcjs base library to use.

Pull requests

This package is actually missing a few ghcjs-base modules that I have not got around to stubbing. Pull requests are welcome if you need those extra stubs. When making a stub, please do not create partial functions, just emit safe stubbed values. Eg. Bad

foo :: IO JSVal
foo = undefined

Better

foo :: IO JSVal
foo = pure nullRef

How to build manually

git clone https://github.com/louispan/ghcjs-base-stub
cd ghcjs-base
git submodule update --init --recursive
Metadata

Version

0.3.0.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows