ghcjs / ghcjs

Haskell to JavaScript compiler, based on GHC
MIT License
2.61k stars 188 forks source link

ghcjs packages and sandbox #353

Open emmanueltouzery opened 9 years ago

emmanueltouzery commented 9 years ago

I have ghcjs working in a sandbox. Now I want to install ghcjs-jquery. I cloned it from github in a directory under the one where I have the ghcjs cabal sandbox. And there I ran:

cabal install --ghcjs ./ghcjs-jquery

And it succeeded, and installed some files:

$ find .cabal-sandbox/ | grep jquery
.cabal-sandbox/logs/ghcjs-jquery-0.1.0.0.log
.cabal-sandbox/share/doc/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0
.cabal-sandbox/share/doc/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0/LICENSE
.cabal-sandbox/lib/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0
.cabal-sandbox/lib/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0/libHSghcjs-jquery-0.1.0.0.js_a
.cabal-sandbox/lib/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0/JavaScript
.cabal-sandbox/lib/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0/JavaScript/JQuery
.cabal-sandbox/lib/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0/JavaScript/JQuery/Internal.js_hi
.cabal-sandbox/lib/x86_64-linux-ghcjs-0.1.0-ghc7_8_3/ghcjs-jquery-0.1.0.0/JavaScript/JQuery.js_hi
.cabal-sandbox/x86_64-linux-ghcjs-0.1.0-ghc7_8_3-packages.conf.d/ghcjs-jquery-0.1.0.0-540b26463c89be589cd72977c9442845.conf

However, ghcjs-pkg list | grep quer shows that ghcjs is not aware of the ghcjs-jquery package, and also compilation of a file containing import JavaScript.JQuery says the module can not be found.

So, can I install ghcjs packages in cabal sandboxes and if yes, how? Thank you!

imalsogreg commented 9 years ago

There is the cabal exec feature. Have you tried (from in the project's toplevel directory) :

cabal exec ghcjs-pkg list
cabal exec ghcjs Main.hs
luite commented 9 years ago

i think you may need a line compiler: ghcjs in your cabal sandbox config to make cabal exec set up the package paths for ghcjs, rather than the default ghc

emmanueltouzery commented 9 years ago

No, none of these changes help.

$ cat cabal.config 
compiler: ghcjs

and still cabal exec ghcjs-pkg list | grep query returns nothing, and cabal exec ghcjs test/Hello.hs complains that it cannot find the JavaScript.JQuery module.

Interestingly though:

$ cabal install --ghcjs ./ghcjs-jquery
Resolving dependencies...
In order, the following will be installed:
ghcjs-jquery-0.1.0.0 (reinstall)
Warning: Note that reinstalls are always dangerous. Continuing anyway...
Notice: installing into a sandbox located at
/home/emmanuel/programs/ghcjs/.cabal-sandbox
Configuring ghcjs-jquery-0.1.0.0...

In other words, cabal knows that the package is installed since it warns me that a reinstallation is dangerous...

emmanueltouzery commented 9 years ago

btw, just in case:

$ cabal --version
cabal-install version 1.22.4.0
using version 1.22.3.0 of the Cabal library 
emmanueltouzery commented 9 years ago

Also export HASKELL_PACKAGE_SANDBOX=./.cabal-sandbox/x86_64-linux-ghcjs-0.1.0-ghc7_8_3-packages.conf.d/ and export HASKELL_PACKAGE_SANDBOX=./.cabal-sandbox/x86_64-linux-ghc-7.8.3-packages.conf.d/ don't help.

luite commented 9 years ago

hmm, there also seems to be a problem with cabal sandbox hc-pkg list, I'll investigate, I think this used to work correctly at some point.

luite commented 9 years ago

It works ok if you build ghcjs with ghc 7.10, both cabal exec ghcjs-pkg list and cabal sandbox hc-pkg list work, but two things need to be done:

(I think this is a Cabal usability issue, sandboxes haven't been designed with multiple compilers in mind)

emmanueltouzery commented 9 years ago

Ok looks like i got myself the homework of installing 7.10 then :-) On 30 May 2015 13:11, "Luite Stegeman" notifications@github.com wrote:

It works ok if you build ghcjs with ghc 7.10, both cabal exec ghcjs-pkg list and cabal sandbox hc-pkg list work, but two things need to be done:

  • add compiler: ghcjs to cabal.config
  • change the package-db field in the generated cabal.sandbox.config to the location that ghcjs uses

(I think this is a Cabal usability issue, sandboxes haven't been designed with multiple compilers in mind)

— Reply to this email directly or view it on GitHub https://github.com/ghcjs/ghcjs/issues/353#issuecomment-107023505.

luite commented 9 years ago

GHCJS with 7.10 is still experimental due to some problems with 7.10.1, see the wiki page for 7.10 instructions.