Git Product home page Git Product logo

ghcjs-examples'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

ghcjs-examples's People

Contributors

ajnsit avatar hamishmack avatar luite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar

ghcjs-examples's Issues

Promise example

A lot (if not all) APIs these days are promise-based. Is there a nice way to interface with these? An example would be great.

Does ghcjs-hello have to be so complicated?

I was hoping for a simple Hello World that runs inside Webkit when natively compiled, or compiles to a simple JS application. But it seems to rely on stuff like Sodium even.

webkit-sodium build fail

Trying to test ghcjs-hello package, when installing webkit-sodium:

Note: installing in sandbox.

src/Language/Javascript/JSaddle/Value.hs:116:29:
    Overlapping instances for Eq JSObjectRef
      arising from the first field of ‘ValObject’ (type ‘JSObjectRef’)
    Matching instances:
      instance Eq (JSRef a) -- Defined in ‘ghcjs-prim-0.1.0.0:GHCJS.Prim’
      instance Eq (JSRef Language.Javascript.JSaddle.Types.ValueOrObject)
        -- Defined at src/Language/Javascript/JSaddle/Types.hs:50:10
    When deriving the instance for (Eq JSValue)
Failed to install jsaddle-0.2.0.5
cabal: Error: some packages failed to install:
jsaddle-0.2.0.5 failed during the building phase. The exception was:
ExitFailure 1
webkit-sodium-0.0.1 depends on jsaddle-0.2.0.5 which failed to install.

Environment:
GHCJS 0.1.0 (GHC 7.8.3)
cabal-install version 1.22.4.0
using version 1.22.3.0 of the Cabal library
System: 4.0.6-200.fc21.x86_64

Heap visualization example?

In the New York talk about ghcjs Luite shows an example if a program showing the heap as it executes (or at least, I think it does -- the slides are very hard to see). Is that available anywhere? I'd love to play with that, would be awesome for writing explanatory Haskell blog posts!

"goog is not defined" error

Steps to reproduce:

cd ./ghcjs-examples/weblog/race
ghcjs -o race race.js
cp race.html ./race.jsexe
cd race.jsexe
open race.html

The example works fine (as expected), however my firefox's console shows ReferenceError: goog is not defined error for this line in lib.js: https://i.imgur.com/AslTLFK.png

Is this repo abandoned?

Guys, is it?

At the moment it does not build on travis.

As a newbie I cannot fix it myself, and indeed it was (for a newbie) an interesting challenge to get it working "somehow" - but it took half a day.

So the question is - could someone please fix travis builds so that it was a reproducible way to build all the demos?

Thanks.

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.