Git Product home page Git Product logo

jsaddle-dom's Introduction

Introduction

GHCJS is a Haskell to JavaScript compiler that uses the GHC API.

Quick Start - Developing GHCJS

GHCJS contains a library, ghcjs, which contains the JavaScript code generator and a slightly customized variant of the ghc library, and several executable programs.

The repository has several submodules and some files must be generated before the package can be installed.

prerequisites

GHC

You need the same major version of GHC as the version of the GHCJS branch you're building.

cabal-install

cabal-install 3.0 is supported

emscripten emsdk

GHCJS uses a C toolchain, mostly for build system related tasks like the C preprocessor, Autoconf scripts and tools like hsc2hs. Direct support for using compiled foreign libraries from Haskell code may follow at a later date.

Please follow the installation instructions at https://emscripten.org/docs/getting_started/index.html

GHCJS requires the "upstream" emscripten backend, which is the default now. The earlier "fastcomp" backend will not work.

getting and preparing the source tree

$ git clone https://github.com/ghcjs/ghcjs.git
$ cd ghcjs
$ git submodule update --init --recursive

building the compiler

GHCJS depends on a few "local" packages in the source tree. You can use cabal-install and stack to set up a build environment that contains these packages.

Cabal new-install

After the source tree has been prepared, the package can be installed. You may want ensure that binaries of earlier versions are overwritten:

cabal v2-install --overwrite-policy=always --install-method=copy --installdir=inplace/bin

At the time of writing, cabal-install does not support creating symbolic links on Windows, even though this is the default installation method. A workaround is telling it to copy the executables instead:

cabal v1-install --prefix=inplace

v1 style Cabal sandbox

v1 style cabal sandboxes are also supported

if you want to build with a Cabal sandbox, use the makeSandbox.sh script to add the local packages.

$ cabal v1-sandbox init
$ cabal v1-install

stack

or you can use stack:

$ stack --system-ghc --skip-ghc-check install --local-bin-dir=inplace/bin

Booting GHCJS

The ghcjs-boot program builds the "boot" libraries, like ghc-prim, base and template-haskell with GHCJS. After booting, GHCJS can compile regular Haskell programs and packages.

ghcjs-boot needs to be able to find the emscripten toolchain, a nodejs executable. The easiest way to do this is by running the emsdk_env.sh script. After that, you can run ghcjs-boot by pointing it to the boot libraries (the directory containing the boot.yaml file)

$ source ~/emsdk/emsdk_env.sh
$ ./inplace/bin/ghcjs-boot -s ./lib/boot

GHCJS executables and library paths

After booting, you can add the directory containing the GHCJS binaries to your executable PATH. The ghcjs-boot program prints the location after finishing building the libraries.

You can also create a symbolic link for the ghcjs and ghcjs-pkg programs, or use the --with-compiler and --with-hc-pkg flags when using cabal-install

Generating a source distribution

if you work on boot packages that need some for an upstream library, make sure to update the patches in /lib/patches first

$ ./utils/updatePatches.sh

then regenerate the packages

$ ./utils/makePackages.sh

jsaddle-dom's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsaddle-dom's Issues

How to create Arrays?

I see there are many types of arrays (Float32Array, ArrayBuffer, Int32Array, ...), and many type classes that these array objects belong to (IsFloat32Array, IsGObject, IsJSVal, PToJSVal, ...) but it isn't immediately clear how to construct one of these arrays (perhaps with 1, 2, 3, etc, values) without using FFI - which seems to break the goal of jsaddle. Any tips?

createAnswer returns RTCSessionDescription instead of RTCSessionDescriptionInit

In jsaddle-dom there are two createAnswer functions one is generated and does return a RTCSessionDescriptionInit, the other is custom and does a conversion to RTCSessionDescription. The custom one is exported. This is unfortunate for two reasons:

  1. the return value of createAnswer is used in setLocalDescription which expects a RTCSessionDescriptionInit.
  2. ghcjs-dom only has the generated one, which returns a RTCSessionDescriptionInit. Thus it seems to be incompatible with jsaddle-dom.

I can file a PR for exporting the generated function and maybe even dropping the custom one if this is the way to go. Am I missing something?

Can compile times be improved from around 10-40 minutes?

On my machine jsaddle-dom takes quite a lot of time to compile.

It usually hangs after this step the most:

Configuring jsaddle-dom-0.9.2.0...
Building jsaddle-dom-0.9.2.0...
Preprocessing library jsaddle-dom-0.9.2.0...
[  1 of 599] Compiling JSDOM.Types      ( src/JSDOM/Types.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/JSDOM/Types.o )

Then the RAM consumption just keeps rising, till around a 2-5GB peak before the modules continue building.

  • Any idea what could be the culprit?
  • Could it be the case that GHC is having a hard time processing a package with 599 modules?
  • Or do other packages with similar module counts compile quicker?
  • Is there something relatively fundamental at play here?
  • Or could there be some low hanging fruit to speed this up?
  • Has there been any efforts to reduce or profile build times so far?

Async versus sync callbacks

I just ran into an issue where readystatechange being async caused some trouble. Specifically:

  1. The XHR changed to readystate 2, then 3, then 4.
  2. As a result, 3 callbacks got enqueued
  3. Then, all 3 callbacks got processed
  4. Since the readystate had already changed to 4, all 3 callbacks saw readystate 4, and all 4 reported that the XHR had just finished.

This behavior doesn't seem right, but I'm not clear on how the decision ought to be made between sync and async for this sort of thing.

jsaddle-dom-0.9.3.1 breaks build with GHC-8.2

Sorry for complaining about old compiler versions… but I get

[  2 of 599] Compiling JSDOM.Types      ( src/JSDOM/Types.hs, dist/build/JSDOM/Types.js_o )

src/JSDOM/Types.hs:1037:9: error:
    • Variable not in scope: (<>) :: t0 -> String -> t1
    • Perhaps you meant one of these:
        ‘<$>’ (imported from Prelude.Compat),
        ‘*>’ (imported from Prelude.Compat),
        ‘<$’ (imported from Prelude.Compat)
     |
1037 |         <> T.unpack destType <> " requested."
     |         ^^

src/JSDOM/Types.hs:1037:30: error:
    • Variable not in scope: (<>) :: t1 -> [Char] -> IO obj'
    • Perhaps you meant one of these:
        ‘<$>’ (imported from Prelude.Compat),
        ‘*>’ (imported from Prelude.Compat),
        ‘<$’ (imported from Prelude.Compat)
     |
1037 |         <> T.unpack destType <> " requested."
     |                              ^^
cabal: Failed to build jsaddle-dom-0.9.3.1 (which is required by
exe:kaleidogen from kaleidogen-0.1). See the build log above for details.

with ghcjs-8.2.

This was broken with #11, which made it work with GHC-8.4, but not GHC-8.2. Maybe you don’t care about GHC-8.2 (fair enough), in that case you could edit the metadata on hackage to tighten the bounds.

jsaddle-dom-0.9.3.0 incompatible with GHC-8.4

A build of my project fails now, it seems that jsaddle-dom either needs tighter bounds or (preferably) hide (<>) from Data.Monoid:

src/JSDOM/Types.hs:1038:9: error:
    Ambiguous occurrence ‘<>’
    It could refer to either ‘Prelude.Compat.<>’,
                             imported from ‘Prelude.Compat’ at src/JSDOM/Types.hs:956:1-34
                             (and originally defined in ‘Data.Semigroup’)
                          or ‘Data.Monoid.<>’,
                             imported from ‘Data.Monoid’ at src/JSDOM/Types.hs:961:21-24
     |
1038 |         <> T.unpack destType <> " requested."
     |         ^^

https://travis-ci.org/nomeata/kaleidogen/builds/489287621

PToJSVal / ToJSVal Discrepancies with ghcjs-dom-jsffi

There a many examples (most Callbacks and other things) of the following differences between:

jsaddle-dom version:

instance ToJSVal VoidCallback where toJSVal (VoidCallback (Callback r)) = toJSVal r

ghcjs-dom-jsffi version:

instance PToJSVal VoidCallback where pToJSVal (VoidCallback (Callback r)) = r

together with the missing in ghcjs-base

instance ToJsVal PToJSval where toJsVal = return . pToJsVal

this breaks code compatibility between GHC and GHCJS.

I am not sure which parts of the ecosystem should be fixed.

  1. Should the above instance added to ghcjs-base?

  2. Should one of ghcjs-dom-jsffi and jsaddle-dom be changed to make VoidCallback have the same instances in both?

Break up JSDOM.Types

When I build jsaddle-dom I get the following error:

[  1 of 600] Compiling JSDOM.Types      ( src/JSDOM/Types.hs, dist/build/JSDOM/Types.p_o )
clang-3.7: error: unable to execute command: Killed: 9
clang-3.7: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.7.1 (tags/RELEASE_371/final)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
clang-3.7: note: diagnostic msg: PLEASE submit a bug report to  and include the crash backtrace, preprocessed source, and associated run script.
clang-3.7: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3.7: note: diagnostic msg: /private/var/folders/yw/4lyc2l_n51z601wqjnyc9vvr0000gn/T/nix-build-jsaddle-dom-0.9.1.0.drv-0/ghc_14-d6f02a.c
clang-3.7: note: diagnostic msg: /private/var/folders/yw/4lyc2l_n51z601wqjnyc9vvr0000gn/T/nix-build-jsaddle-dom-0.9.1.0.drv-0/ghc_14-d6f02a.sh
clang-3.7: note: diagnostic msg:

********************

<no location info>: error:
    `cc' failed in phase `C Compiler'. (Exit code: 254)

It sits on the JSDOM.Types module for tens of minutes, possibly more than an hour before failing. I'm running macOS on a machine with 16 gigs of RAM. The fact that I can't build jsaddle-dom on a machine this big seems like a problem. Is it possible to break this module up to make it buildable on normal size systems?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.