tweag / asterius

DEPRECATED in favor of ghc wasm backend, see https://www.tweag.io/blog/2022-11-22-wasm-backend-merged-in-ghc
1.97k stars 58 forks source link

Importing modules with ahc-link #362

Open dduenker opened 4 years ago

dduenker commented 4 years ago

Hi, i am a bit confused as of how to use this project when i am importing packages, which are not installed by default. I have a project, which uses cassava (and also other packages) and imports it via import Data.Csv. I want to export a function from my project to use it via javascript. I am able to compile using ahc-cabal, but ahc-dist does not appear to support --export-function. How can i accomplish this with ahc-link?

ahc-link --input-hs src/Lib.hs
[INFO] Compiling src/Lib.hs to WebAssembly

src/Lib.hs:9:1: error:
    Could not find module ‘Data.Csv’
    Use -v to see a list of the files searched for.
  |
9 | import Data.Csv
  | ^^^^^^^^^^^^^^^

src/Lib.hs:11:1: error:
    Could not find module ‘Data.List.Split’
    Use -v to see a list of the files searched for.
   |
11 | import Data.List.Split
   | ^^^^^^^^^^^^^^^^^^^^^^
ahc: panic! (the 'impossible' happened)
  (GHC version 8.6.5 for x86_64-unknown-linux):
        GHC.load returned Failed.
TerrorJack commented 4 years ago

Thanks for spotting yet another missing thing in documentation..for now, you can use --ghc-option=-optl--export-function=... as additional Cabal configure flag when you're building your "executable" with ahc-cabal.

Also worth noting: the prebuilt Docker image now contains cassava in the global package database, so maybe you can try using ahc-link with the image first.

dduenker commented 4 years ago

Thank you very much, i am able to continue with this :D