Git Product home page Git Product logo

ghcjs-dom-hello'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-dom-hello's People

Contributors

hamishmack avatar kmicklas avatar mgsloan avatar

Stargazers

 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

ghcjs-dom-hello's Issues

ld: symbol(s) not found for architecture x86_64

I'm running into this on OS X, having installed webkit-gtk3 using MacPorts as guided in https://github.com/leksah/leksah#building-on-os-x.

My goal is to compile the ghcjs-dom-hello project with GHC 7.10.2 (as opposed to GHCJS).

I have the binaries from gtk2hs-buildtools in my PATH, and I've confirmed that cabal install webkitgtk3 works (in a sandbox).

~/code/haskell/ghcjs-dom-hello$ sb
mtl-2.2.1: configure
mtl-2.2.1: build
text-1.2.1.3: configure
text-1.2.1.3: build
utf8-string-1.0.1.1: configure
utf8-string-1.0.1.1: build
mtl-2.2.1: copy/register
utf8-string-1.0.1.1: copy/register
text-1.2.1.3: copy/register
glib-0.13.2.1: configure
glib-0.13.2.1: build
cairo-0.13.1.0: configure
cairo-0.13.1.0: build
glib-0.13.2.1: copy/register
gio-0.13.1.0: configure
gio-0.13.1.0: build
cairo-0.13.1.0: copy/register
pango-0.13.1.0: configure
pango-0.13.1.0: build
pango-0.13.1.0: copy/register
gio-0.13.1.0: copy/register
gtk3-0.14.1: configure
gtk3-0.14.1: build
gtk3-0.14.1: copy/register
webkitgtk3-0.14.1.0: configure
webkitgtk3-0.14.1.0: build
webkitgtk3-0.14.1.0: copy/register
ghcjs-dom-0.2.3.0: configure
ghcjs-dom-0.2.3.0: build
ghcjs-dom-0.2.3.0: copy/register
ghcjs-dom-hello-2.0.0.0: configure
Configuring ghcjs-dom-hello-2.0.0.0...
ghcjs-dom-hello-2.0.0.0: build
Preprocessing executable 'ghcjs-dom-hello' for ghcjs-dom-hello-2.0.0.0...
[1 of 1] Compiling Main             ( src/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/ghcjs-dom-hello/ghcjs-dom-hello-tmp/Main.o )
Linking .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/ghcjs-dom-hello/ghcjs-dom-hello ...
Undefined symbols for architecture x86_64:
  "_iconv", referenced from:
      _hs_iconv in libHSbase-4.8.1.0-GDytRqRVSUX7zckgKqJjgw.a(iconv.o)
     (maybe you meant: _base_GHCziIOziEncodingziIconv_iconvEncodingzuloc_info, _base_GHCziIOziEncodingziIconv_iconvEncodingzuloc1_info , _base_GHCziIOziEncodingziIconv_iconvEncoding9_info , _base_GHCziIOziEncodingziIconv_iconvEncoding10_closure , _hs_iconv_open , _base_GHCziIOziEncodingziIconv_iconvEncoding7_info , _base_GHCziIOziEncodingziIconv_iconvEncoding11_info , _base_GHCziIOziEncodingziIconv_iconvEncoding8_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding7_closure , _base_GHCziIOziEncodingziIconv_iconvEncodingzuloc_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding2_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding2_info , _base_GHCziIOziEncodingziIconv_iconvEncoding4_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding4_info , _hs_iconv , _base_GHCziIOziEncodingziIconv_iconvEncodingzuloc1_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding10_info , _hs_iconv_close , _base_GHCziIOziEncodingziIconv_iconvEncoding11_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding9_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding3_closure , _base_GHCziIOziEncodingziIconv_iconvEncoding8_info , _base_GHCziIOziEncodingziIconv_iconvEncoding5_closure )
  "_iconv_close", referenced from:
      _hs_iconv_close in libHSbase-4.8.1.0-GDytRqRVSUX7zckgKqJjgw.a(iconv.o)
     (maybe you meant: _hs_iconv_close)
  "_iconv_open", referenced from:
      _hs_iconv_open in libHSbase-4.8.1.0-GDytRqRVSUX7zckgKqJjgw.a(iconv.o)
     (maybe you meant: _hs_iconv_open)
  "_locale_charset", referenced from:
      _localeEncoding in libHSbase-4.8.1.0-GDytRqRVSUX7zckgKqJjgw.a(PrelIOUtils.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Completed all 11 actions.

--  While building package ghcjs-dom-hello-2.0.0.0 using:
      /Users/erik/.stack/setup-exe-cache/setup-Simple-Cabal-1.22.4.0-x86_64-osx-ghc-7.10.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.4.0 build exe:ghcjs-dom-hello --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

Please add install instructions.

I've tried installing it on OSX El Captain. I used stack init --solver; stack build and got:

Please install `gtk2hs-buildtools` first and check that the install directory is in your PATH (e.g. HOME/.cabal/bin)."

I installed it through stack and got:

The program 'pkg-config' version >=0.9.0 is required but it could not be found.

I installed it through homebrew and got:

The pkg-config package 'cairo' version >=1.2.0 is required but it could not be found.

I don't know how I'm supposed to proceed. Seems like I am missing something here. Please add install instructions.

Compiling with GHC fails with error: No instance for ToJSString (Maybe [Char])

I tried to compile ghcjs-dom-hello under GHC / WebkitGtk2 with the following stack.yaml file:

resolver: lts-8.17
packages:
- location: '.'
#- location:
#    git: https://github.com/GHCJS/jsaddle
#    commit: a51df99cbcca19d11df079f1a99771043153d1a7 
#  subdirs:
#  - jsaddle
# extra-dep: true
  
extra-deps:
- jsaddle-0.9.0.0
- jsaddle-dom-0.9.0.0
- ghcjs-dom-0.9.0.0
- jsaddle-warp-0.9.0.0
- jsaddle-webkit2gtk-0.9.0.0
- ref-tf-0.4.0.1
- ghcjs-dom-jsaddle-0.9.0.0
- gi-webkit2-4.0.12
- webkit2gtk3-javascriptcore-0.14.2.1
- gi-javascriptcore-4.0.12
flags: {}

extra-package-dbs: []

And got the error:

/home/roland/Projekte/ghcjs-dom-hello/src/HelloMain.hs:22:5-52: error:
    • No instance for (Language.Javascript.JSaddle.Marshal.String.ToJSString
                         (Maybe [Char]))
        arising from a use of ‘setInnerHTML’

Note: To be able to build under Linux I had to remove the section executable ghcjs-dom-hello-wkwebview and the if os(osx) || os(ios) from the cabal file.

I don't really understand why we have this error. We have in module Language.Javascript.JSaddle.Marshal.String :

-- | Anything that can be used to make a JavaScript string
class ToJSVal a => ToJSString a where
    toJSString :: a -> JSString

and in module Language.Javascript.JSaddle.Value :

instance ToJSVal a => ToJSVal (Maybe a) where
    toJSVal Nothing = return jsNull
    toJSVal (Just a) = toJSVal a

Here is the full building log with the complete error message:

roland@goms:~/Projekte/ghcjs-dom-hello$ stack setup
stack will use a sandboxed GHC it installed
For more information on paths, see 'stack path' and 'stack exec env'
To use this GHC and packages outside of a project, consider using:
stack ghc, stack ghci, stack runghc, or stack exec
roland@goms:~/Projekte/ghcjs-dom-hello$ stack setup
stack will use a sandboxed GHC it installed
For more information on paths, see 'stack path' and 'stack exec env'
To use this GHC and packages outside of a project, consider using:
stack ghc, stack ghci, stack runghc, or stack exec
roland@goms:~/Projekte/ghcjs-dom-hello$ stack build
webkit2gtk3-javascriptcore-0.14.2.1: configure
webkit2gtk3-javascriptcore-0.14.2.1: build
gi-javascriptcore-4.0.12: configure
webkit2gtk3-javascriptcore-0.14.2.1: copy/register
gi-javascriptcore-4.0.12: build
ref-tf-0.4.0.1: configure
ref-tf-0.4.0.1: build
gi-javascriptcore-4.0.12: copy/register
ref-tf-0.4.0.1: copy/register
gi-webkit2-4.0.12: configure
gi-webkit2-4.0.12: build
jsaddle-0.9.0.0: configure
jsaddle-0.9.0.0: build
gi-webkit2-4.0.12: copy/register
jsaddle-0.9.0.0: copy/register
jsaddle-warp-0.9.0.0: configure
jsaddle-warp-0.9.0.0: build
jsaddle-webkit2gtk-0.9.0.0: configure
jsaddle-webkit2gtk-0.9.0.0: build
jsaddle-dom-0.9.0.0: configure
jsaddle-dom-0.9.0.0: build
jsaddle-warp-0.9.0.0: copy/register
jsaddle-webkit2gtk-0.9.0.0: copy/register
jsaddle-dom-0.9.0.0: copy/register
ghcjs-dom-jsaddle-0.9.0.0: configure
ghcjs-dom-jsaddle-0.9.0.0: build
ghcjs-dom-jsaddle-0.9.0.0: copy/register
ghcjs-dom-0.9.0.0: configure
ghcjs-dom-0.9.0.0: build
ghcjs-dom-0.9.0.0: copy/register
ghcjs-dom-hello-5.0.0.0: configure (lib + exe)
Configuring ghcjs-dom-hello-5.0.0.0...
ghcjs-dom-hello-5.0.0.0: build (lib + exe)
Preprocessing library ghcjs-dom-hello-5.0.0.0...
[1 of 1] Compiling HelloMain        ( src/HelloMain.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/HelloMain.o )
               
/home/roland/Projekte/ghcjs-dom-hello/src/HelloMain.hs:22:5-52: error:
    • No instance for (Language.Javascript.JSaddle.Marshal.String.ToJSString
                         (Maybe [Char]))
        arising from a use of ‘setInnerHTML’
    • In a stmt of a 'do' block:
        setInnerHTML body (Just "<h1>Kia ora (Hi)</h1>")
      In the expression:
        do { doc <- currentDocumentUnchecked;
             body <- getBodyUnsafe doc;
             setInnerHTML body (Just "<h1>Kia ora (Hi)</h1>");
             _ <- on doc click
                  $ do { (x, y) <- mouseClientXY;
                         newParagraph <- uncheckedCastTo HTMLParagraphElement
                                         <$> createElement doc "p";
                         .... };
             .... }
      In an equation for ‘helloMain’:
          helloMain
            = do { doc <- currentDocumentUnchecked;
                   body <- getBodyUnsafe doc;
                   setInnerHTML body (Just "<h1>Kia ora (Hi)</h1>");
                   .... }
Completed 11 action(s).

--  While building package ghcjs-dom-hello-5.0.0.0 using:
      /home/roland/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0 build lib:ghcjs-dom-hello exe:ghcjs-dom-hello exe:ghcjs-dom-hello-warp exe:ghcjs-dom-hello-webkitgtk --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
roland@goms:~/Projekte/ghcjs-dom-hello$ 

Inserted <p> is empty

Hi,

this is my first try to get my hands on ghcjs. So I compiled ghcjs from github with the following configuration (using improved-base branch like the ghcjs wiki suggests):

  • Cabal (1.22.4.0)
  • cabal-install (1.22.6.0)
  • ghc (7.10.2)

Compiling and building ghc-dom-hello works flawlessly. The only problem is that all the inserted <p> elements are empty. It seems like setInnerText is not working.

Are there some changes necessary to make it work with the recent version of ghcjs, ghc-js or the runtime?

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.