commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
4k stars 843 forks source link

GHCJS? #337

Closed jkozlowski closed 9 years ago

jkozlowski commented 9 years ago

Are there plans to support GHCJS in the same first class way as GHC (i.e. getting the binaries etc.)?

kgadek commented 9 years ago

Ok, I'll admit that even after this discussion I have no idea what's the status.

As far as I understood, using docker means basically calling cabal there. In other words, this is as good as using cabal on bare metal and not using stack at all?

Also, I'm not sure what is the current issue. If that's the ghcjs not working, I believe @kfigiela has a working setup.

I didn't quite get the actual status of the https://github.com/commercialhaskell/stack/tree/337-ghcjs branch. @mgsloan what is there? What's done, what's to be done, what's "unknown" and to be researched?

mgsloan commented 9 years ago

Ok, I'll admit that even after this discussion I have no idea what's the status.

what is there? What's done, what's to be done, what's "unknown" and to be researched?

This thread is getting long and unwieldy. I've split off a couple of issues to reduce confusion:

1) We need to support building code with ghcjs. The initial code for this is very minimal, and just enables passing in the --ghcjs flag and nothing else https://github.com/commercialhaskell/stack/issues/748

2) We need to support automatically installing GHCJS, in the same way that installing GHC is automated: https://github.com/commercialhaskell/stack/issues/749 . I'd been hoping that this bit can come after adding support for building code with GHCJS. However, given the issues I've had with getting it setup locally, it might actually be best to get this done first.

As far as I understood, using docker means basically calling cabal there. In other words, this is as good as using cabal on bare metal and not using stack at all?

No, stack is still run inside the docker container. Other than the stack solver command, I don't think cabal-install is ever run by stack. The benefit of this is that you can use a docker image that already has ghcjs + libraries installed.

Also, I'm not sure what is the current issue. If that's the ghcjs not working, I believe @kfigiela has a working setup.

That's the current issue for me, yes. I am running into the issue described here while booting: https://github.com/ghcjs/ghcjs/issues/374

@ryantrinkle 's try-reflex setup works perfectly. Pretty nifty! As he mentions, I don't see how to directly use the results with stack.

mgsloan commented 9 years ago

Good news everyone! @kfigiela's instructions for building and booting ghcjs worked, so I spent the last few hours implementing initial stack support.

Things now seem to work decently on the 337-ghcjs branch!

I haven't used this for anything big, so who knows what may be missing. Considering how many people are interested in getting this soon, I figured it's better to push something unpolished for people to play with. If you want to try it out, I've pushed a fork of ghcjs-dom-hello which has a stack.yaml which works with my stack branch.

There are a couple caveats:

mgsloan commented 9 years ago

As I've noted on #748, I've decided to have the resolver specify the GHCJS version. Once that's implemented, there will be no more use-ghcjs field / flag!

kgadek commented 9 years ago

It seems that stack solver doesn't work with GHCJS…?

Other than that, it does seem that this works for us. Great job, @mgsloan ! Now we shall wait for LTS Haskell for GHCJS and it would be… just awesome :)

kfigiela commented 9 years ago

@mgsloan, great job! Indeed it does work.

During setting up everything I found some minor issues:

$ stack solver
This command is not guaranteed to give you a perfect build plan
It's possible that even with the changes generated below, you will still need to do some manual tweaking
Asking cabal to calculate a build plan, please wait
flags:
  text:
    integer-simple: false
extra-deps:
- cairo-0.13.1.0
- gio-0.13.1.0
- glib-0.13.2.1
- gtk3-0.14.0
- mtl-2.2.1
- pango-0.13.1.0
- text-1.2.1.3
- utf8-string-1
- webkitgtk3-0.14.1.0

Here it should not ask for webkitgtk3 as we're going to build with ghcjs. In https://github.com/ghcjs/ghcjs-dom/blob/master/ghcjs-dom.cabal there's condition for dependencies: if !impl(ghcjs) || flag(webkit) which seems to be ignored by stack.

mgsloan commented 9 years ago

@kfigiela Thanks for trying it out! Yes, I haven't added support for ghcjsi. I can try blindly adding that in in my next change, though. That's curious that the GHC_PACKAGE_PATH variable has a non-js DB, I'll need to look into that.

Along with fixing solver and taking a swing at ghcjsi support, next up is removing the use-ghcjs flag and instead have a compiler resolver that looks like ghcjs-0.1.0_ghc-7.10.2. A bit ugly to have both versions, but it's necessary. Is there already a way of formatting the full ghcjs version number that should be used? If there's already a consistent and not too ugly way to do that, I'd prefer to remain consistent with it.

mgsloan commented 9 years ago

I've pushed a new implementation which is based on a resolver setting. The resolver looks like ghcjs-0.1.0_ghc-7.10.2. It now uses ghcjs to build the Setup.hs files, and then runs the resulting javascript in node.

This works for all stack commands except setup, ghc, runghc, and ide. It'd be easy to add support for something like ghc, but should stack ghc run ghcjs? Maybe there should be a new stack ghcjs command for that.

Since I think this is now in pretty good shape, I've opened a PR for it: https://github.com/commercialhaskell/stack/pull/802

snoyberg commented 9 years ago

Since #802 is merged and the only remaining item is being tracked by #749, I'd recommend closing this issue. @mgsloan any objection?

mgsloan commented 9 years ago

Sounds good to me!

xavier83 commented 9 years ago

Is there a howto/wiki to setup and get started on ghcjs using stack?

vertexcite commented 9 years ago

You need to be using a stack built from master, to do that, run:

$ stack upgrade --git

Then, add

resolver: ghcjs-0.1.0.20150924_ghc-7.10.2
compiler-check: match-exact

to ~/.stack/stack.yaml

Then run

$ stack setup

(Second part copied from https://github.com/commercialhaskell/stack/issues/749#issuecomment-143248083 )

fizruk commented 9 years ago

@xavier83 there is no official howto/wiki AFAIK.

For old base GHCJS you can use what @vertexcite suggested. Probably you'd want to add that resolver for a particular GHCJS project, so GHCJS won't be turned on by default.

For GHCJS master (a.k.a. "improved base"), you can place this in your stack.yaml (copied from https://github.com/commercialhaskell/stack/pull/1030#issuecomment-144570922):

resolver: ghcjs-0.2.0.20151001_ghc-7.10.2
compiler-check: match-exact
setup-info:
  ghcjs:
    source:
      ghcjs-0.2.0.20151001_ghc-7.10.2:
        url: "https://github.com/fizruk/ghcjs/releases/download/v0.2.0.20151001/ghcjs-0.2.0.20151001.tar.gz"

NOTE: for the latter to work you'll currently need stack upgrade --git (it has to do with setup-info bug fixed in #1083).

bitemyapp commented 9 years ago

@vertexcite @fizruk thank you both for sharing these, this is very helpful!

GetContented commented 9 years ago

@fizruk could you create a wiki page for it?

fizruk commented 9 years ago

@GetContented I have now created a wike page for Stack & GHCJS.

GetContented commented 9 years ago

@fizruk Thank you :)

xavier83 commented 9 years ago

@fizruk awesome. Thanks :+1:

mgsloan commented 9 years ago

@fizruk Good stuff, thanks! Most of it's spot on, I've updated with some more info and a correction for the versions (stack setup isn't supported by any released version of GHCJS).

dredozubov commented 9 years ago

Looking forward for it in the next release! It'll be extremely useful.

k-bx commented 9 years ago

@fizruk can you take a look please?

$ cat stack.yaml
resolver: ghcjs-0.2.0.20151001_ghc-7.10.2
compiler-check: match-exact
setup-info:
  ghcjs:
    source:
      ghcjs-0.2.0.20151001_ghc-7.10.2:
        url: "https://github.com/fizruk/ghcjs/releases/download/v0.2.0.20151001/ghcjs-0.2.0.20151001.tar.gz"

packages:
- '.'
$ stack setup
Warning: /Users/kb/workspace/ghcjs-stack-play/stack.yaml: Unrecognized field in SetupInfo: ghcjs
Warning: https://raw.githubusercontent.com/fpco/stackage-content/master/stack/stack-setup-2.yaml: Unrecognized field in SetupInfo: ghcjs
No information found for ghcjs-0.2.0.20151001_ghc-7.10.2.
Supported versions for OS key 'macosx': 7.8.4, 7.10.1, 7.10.2
$ stack --version
Version 0.1.5.0 X86_64
kfigiela commented 9 years ago

@k-bx: you need to stack upgrade --git. Make sure that you have Cabal library version 1.22.4 installed (my coleague had 1.22.2 and then ghcjs-boot phase failed, maybe stack could check that?)

fizruk commented 9 years ago

@k-bx you need to upgrade stack to HEAD, see Stack & GHCJS wiki

k-bx commented 9 years ago

Sorry, my bad, mis-read wiki.

tinkyholloway commented 9 years ago

I've been working to the instructions at Stack & GHCJS.

I've found a problem with hsc2hs (whatever that is) when fails on a build of network-2.6.2.1:

hsc2hs-ghcjs-0.2.0.20151001-7.10.2.bin: hsc2hs: rawSystem: runInteractiveProcess: exec: does not exist (No such file or directory)

hsc2hs is present:

✔ ~/.stack/programs/x86_64-osx/ghcjs-0.2.0.20151001_ghc-7.10.2/bin
13:07 $ ~/.stack/programs/x86_64-osx/ghcjs-0.2.0.20151001_ghc-7.10.2/bin/hsc2hs-ghcjs
hsc2hs-ghcjs-0.2.0.20151001-7.10.2.bin: hsc2hs: rawSystem: runInteractiveProcess: exec: does not exist (No such file or directory)
luite commented 9 years ago

Ok this is likely a problem with how hsc2hs is dealt with in GHCJS. It's the only tool that isn't stand-alone, but a wrapper that calls an existing hsc2hs provided by GHC.

Handling of these files is not quite complete yet, but something should probably change. I wonder if GHCJS should even attempt to support them, since it's really for getting information from the C compiler.

tinkyholloway commented 9 years ago

@luite said:

It's ... a wrapper that calls an existing hsc2hs provided by GHC

A ha! Adding ~/.stack/programs/x86_64-osx/ghc-7.10.2/bin/hsc2hs to my path fixed it. Thank you.

erikkaplun commented 9 years ago

will we be seeing any GHCJS related doc on https://www.stackage.org at some point?

bitemyapp commented 9 years ago

@eallik @snoyberg related to Stackage, being able to list available snapshots (LTS, nightly) would be nice. If that is possible, it was impossible to find via the website.

Would a separate set of Stackage snapshots for what's "known good" w/ GHCJS be sensible?

mgsloan commented 9 years ago

@eallik Possibly! I don't think there's much to stackage itself related to GHCJS, though, so I imagine that this will be documented in stack / in tutorials elsewhere.

@bitemyapp If you want to read the nitty-gritty of the decision making process on that, here's the issue related to adding support for using GHCJS with stackage snapshots: https://github.com/commercialhaskell/stack/issues/1190 . So, essentially there is no need for a separate set of stackage snapshots, and ghcjs-only packages will probably get added to stackage.

bitemyapp commented 9 years ago

@mgsloan I had assumed there wouldn't be a separate compiler field, but rather that snapshots and compilers would be bolted together with a separate submission process for GHCJS.

Much as GHCJS has done a great job with compatibility, I'm not sure it makes sense to elide the distinction in the snapshots when that distinction is made for major GHC versions.

mgsloan commented 9 years ago

Yes, once there's a version of GHCJS on hackage, it would be good to get it and its associated libraries into stackage. I suppose when that happens, it'll be desireable to have just plain ghcjs be a valid value for compiler, where the ghc and ghcjs version is provided by the snapshot.

Until then, manually specifying the compiler is the best way I can think of for this to work.

erikkaplun commented 9 years ago

@mgsloan how about your own comment here 3 months ago? there seems to be quite a bit of information in this thread that solely applies to using stack with GHCJS? shouldn't that constitute the GHCJS specific portion of the doc?

mgsloan commented 9 years ago

@eallik I didn't properly understand how GHCJS worked 3 months ago. Another relevant issue is here: https://github.com/fpco/stackage-curator/issues/8 . Which doc do you think this stuff should be added to?

erikkaplun commented 9 years ago

I'm not sure; so one can just use stack/stackage with GHCJS without having to know about how stack works with GHCJS?

mgsloan commented 9 years ago

@eallik It should be pretty straightforward, but the docs certainly deserved more polish. I've done that in the following commits:

Another benefit of using the same stackage snapshots for GHCJS is that you can take existing stack projects intended for GHC and build them with GHCJS via stack build --compiler ghcjs-0.1.0.20150924_ghc-7.10.2. Once ghcjs is in stackage snapshots, it will be possible to just do stack build --compiler ghcjs or perhaps even stack build --ghcjs

erikkaplun commented 9 years ago

Thank you! Exactly what I meant :)

nrolland commented 9 years ago

I updated @fizruk's build as of 2015-10-29

resolver: ghcjs-0.2.0.20151029_ghc-7.10.2
compiler-check: match-exact
setup-info:
  ghcjs:
      source:
            ghcjs-0.2.0.20151029_ghc-7.10.2:
                    url: "https://github.com/nrolland/ghcjs/releases/download/v0.2.0.20151029/ghcjs-0.2.0.20151029.tar.gz"

also had success setuping + building with

resolver: lts-3.0
packages:
- '.'
compiler-check: match-exact
setup-info:
  ghcjs:
      source:
            ghcjs-0.2.0.20151029_ghc-7.10.2:
                    url: "https://github.com/nrolland/ghcjs/releases/download/v0.2.0.20151029/ghcjs-0.2.0.20151029.tar.gz"

and stack setup --compiler ghcjs-0.2.0.20151029_ghc-7.10.2 stack build --compiler ghcjs-0.2.0.20151029_ghc-7.10.2

emmanueltouzery commented 8 years ago

I'm not really sure if this is the right place to ask, but... I have a working setup, there's just one little hitch: stack install works, until the copying bit: then it says Couldn't find executable cigale-web in directory [..]. Indeed in that directory, there is no cigale-web executable, but instead there is a cigale-web.exe subfolder (that ideally stack could copy recursively to my local-bin-path).

I'll probably handle this in a custom Setup.hs, but maybe there is a nicer solution that I'm missing here? Or is this still TODO?

mgsloan commented 8 years ago

@emmanueltouzery Yeah, you should just use stack build for ghcjs. stack install is just an alias for stack build --copy, adding on the extra copy step. Feel free to open an issue about that. While this should work in theory, it's actually kinda nice, I'd rather not have node versions of haskell exes laying around on my PATH.

snoyberg commented 8 years ago

I've actually had use cases where copying the JavaScript files elsewhere would have been convenient

On Mon, Jan 25, 2016, 10:41 PM Michael Sloan notifications@github.com wrote:

@emmanueltouzery https://github.com/emmanueltouzery Yeah, you should just use stack build for ghcjs. stack install is just an alias for stack build --copy, adding on the extra copy step. Feel free to open an issue about that. While this should work in theory, it's actually kinda nice, I'd rather not have node versions of haskell exes laying around on my PATH.

— Reply to this email directly or view it on GitHub https://github.com/commercialhaskell/stack/issues/337#issuecomment-174656040 .

agocorona commented 8 years ago

So finally there is first class install for ghcjs?.

I would like to install it in remote servers with scarce resources. For example in free instances of Cloud9 to enable users to clone and run example code. I can not do an installation from source there.

As a workaround, anyone know how to package and install the binaries manually? cloud9 workspaces are docker instances, so I can compile it in docker locally and translate the binaries.

mgsloan commented 8 years ago

So finally there is first class install for ghcjs?.

Stack has supported setting up GHCJS since v0.1.8, back in November of 2015

I would like to install it in remote servers with scarce resources. For example in free instances of Cloud9 to enable users to clone and run example code. I can not do an installation from source there.

Perhaps use docker? You may need to figure out how to do a binary distribution of GHCJS, afaik no one has figured out how to do a binary distribution, other than mechanisms like docker.

ryantrinkle commented 8 years ago

@mgsloan Maybe we can get stack to use nix's binary package distribution infrastructure somehow?

mgsloan commented 8 years ago

@ryantrinkle Perhaps so! Yes, nix is also a great approach, as demonstrated by your repo https://github.com/reflex-frp/reflex-platform

geraldus commented 8 years ago

Looks like runInteractiveProcess issue is still appears (I got it on my Travis GHCJS build via stack using LTS 7.7 with according compiler snapshot from Marcin).

Sample error message:

hsc2hs: rawSystem: runInteractiveProcess: exec: does not exist (No such file or directory)

To resolve this I added stack --no-terminal --install-ghc install hsc2hs in build section for GHCJS case (see this commit).

haskellstudio commented 6 years ago

hsc2hs: rawSystem: runInteractiveProcess: exec: does not exist (No such file or directory)

i resolve this by :

vim ~/.bash_profile 
export PATH=$PATH:/Users/yourMacUserName/.stack/programs/x86_64-osx/ghc-8.0.1/bin:/Users/hack/.local/bin

because hsc2hs is in /Users/yourMacUserName/.stack/programs/x86_64-osx/ghc-8.0.1/bin