GHCJS currently fails to build libraries. Any workarounds?

Heya,

I’ve started playing with ghcjs haskell and encountered this issue.

Without being able to use non-builtin libraries, I can’t really do a whole lot.

Considering that the LLVM issue is open since late February, it’s probably not going to be fixed in the next few days, so I was thinking about workarounds.

I guess I could copy the whole library into my codebase, but short of that, I don’t have any ideas.
Is there something I can do here?

First, what do you mean by “ghcjs”?

The issues you’ve linked is for GHC itself and its new javascript backend. That thing is a development preview and needs to be built from source. I’m just double checking that that’s what you did.

Second, I can build (some, not all) libraries for javascript with GHC just fine. :slight_smile: The issue you mentioned seems to be predicated on the use of -staticlib. Is that also what you (or the library you are building) is doing?

Hi :slight_smile:

You’re right, sorry about that. It was kinda late when I wrote the post :smiley:
As you expected, I do mean GHC 9.6 with the javascript backend. specifically, I’m using nixpkgs’ pkgsCross.ghcjs.haskell.packages.ghc96.ghc

That’s very useful, thank you! I’ve started a test project, added async as a dependencies and immediately ran into this. I then assumed that this affects all libraries are affected. I’ll look into forcing this off for all dependencies, that might avoid it.

3 Likes

FYI in nix, the key is this:

hspkgs = pkgsCross.ghcjs.haskell.packages.ghc96.extend (self: super: {
  hashable = disableStaticLibraries super.hashable;
};

But I’m getting another error now. As far as I understand it, the stock ghc libraries now also need to be compiled dynamically?

> nix build .#hspkgs-js.hashable
...

> nix log /nix/store/z62kkfmq67hpms6vz3f8w2g0d606d9vs-hashable-1.4.2.0.drv
@nix { "action": "setPhase", "phase": "setupCompilerEnvironmentPhase" }
setupCompilerEnvironmentPhase
Build with /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1.
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/zcsfhhlwz4kr6apgjpsxs25h8sdhpb59-hashable-1.4.2.0.tar.gz
source root is hashable-1.4.2.0
setting SOURCE_DATE_EPOCH to timestamp 1000000000 of file hashable-1.4.2.0/tests/Regress/Mmap.hsc
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
Replace Cabal file with edited version from mirror://hackage/hashable-1.4.2.0/revision/1.cabal.
@nix { "action": "setPhase", "phase": "compileBuildDriverPhase" }
compileBuildDriverPhase
setupCompileFlags: -package-db=/build/tmp.wQxag50d2q/setup-package.conf.d -j6 -threaded -rtsopts
[1 of 2] Compiling Main             ( Setup.hs, /build/tmp.wQxag50d2q/Main.o )
[2 of 2] Linking Setup
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
configureFlags: --verbose --prefix=/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0 --libdir=$prefix/lib/$compiler/lib --libsubdir=$abi/$libname --docdir=/nix/store/fqff94i1nip929fpkv1v3554r15535xk-hashable-1.4.2.0-doc/share/doc/hashable-1.4.2.0 --package-db=/build/tmp.wQxag50d2q/package.conf.d --ghc-options=-j6 --disable-split-objs --enable-library-profiling --profiling-detail=exported-functions --disable-profiling --disable-shared --disable-coverage --disable-static --disable-executable-dynamic --disable-tests --disable-benchmarks --enable-library-vanilla --disable-library-for-ghci --ghc-option=-split-sections --disable-library-stripping --disable-executable-stripping --configure-option=--host=javascript-unknown-ghcjs --with-ghc=javascript-unknown-ghcjs-ghc --with-ghc-pkg=javascript-unknown-ghcjs-ghc-pkg --with-gcc=gcc --hsc2hs-option=--cross-compile --ghc-options=-haddock --extra-include-dirs=/nix/store/l0rmvql1af1yj677g8ljhgixm4v6v74s-nodejs-slim-18.15.0/include --extra-lib-dirs=/nix/store/l0rmvql1af1yj677g8ljhgixm4v6v74s-nodejs-slim-18.15.0/lib
Using Parsec parser
Configuring hashable-1.4.2.0...
Flags chosen: integer-gmp=True, random-initial-seed=False
Dependency base >=4.10.1.0 && <4.19: using base-4.18.0.0
Dependency bytestring >=0.10.8.2 && <0.12: using bytestring-0.11.4.0
Dependency containers >=0.5.10.2 && <0.7: using containers-0.6.7
Dependency deepseq >=1.4.3.0 && <1.5: using deepseq-1.4.8.1
Dependency filepath >=1.4.1.2 && <1.5: using filepath-1.4.100.1
Dependency ghc-bignum >=1.0 && <1.4: using ghc-bignum-1.3
Dependency ghc-prim: using ghc-prim-0.10.0
Dependency text >=1.2.3.0 && <1.3 || >=2.0 && <2.1: using text-2.0.2
Source component graph: component lib
Configured component graph:
    component hashable-1.4.2.0-HkcOg0xvY4vGKtL2nyMhCP
        include base-4.18.0.0
        include bytestring-0.11.4.0
        include containers-0.6.7
        include deepseq-1.4.8.1
        include filepath-1.4.100.1
        include ghc-bignum-1.3
        include ghc-prim-0.10.0
        include text-2.0.2
Linked component graph:
    unit hashable-1.4.2.0-HkcOg0xvY4vGKtL2nyMhCP
        include base-4.18.0.0
        include bytestring-0.11.4.0
        include containers-0.6.7
        include deepseq-1.4.8.1
        include filepath-1.4.100.1
        include ghc-bignum-1.3
        include ghc-prim-0.10.0
        include text-2.0.2
        Data.Hashable=hashable-1.4.2.0-HkcOg0xvY4vGKtL2nyMhCP:Data.Hashable,Data.Hashable.Generic=hashable-1.4.2.0-HkcOg0xvY4vGKtL2nyMhCP:Data.Hashable.Generic,Data.Hashable.Lifted=hashable-1.4.2.0-HkcOg0xvY4vGKtL2nyMhCP:Data.Hashable.Lifted
Ready component graph:
    definite hashable-1.4.2.0-HkcOg0xvY4vGKtL2nyMhCP
        depends base-4.18.0.0
        depends bytestring-0.11.4.0
        depends containers-0.6.7
        depends deepseq-1.4.8.1
        depends filepath-1.4.100.1
        depends ghc-bignum-1.3
        depends ghc-prim-0.10.0
        depends text-2.0.2
Using Cabal-3.10.1.0 compiled by ghc-9.6
Using compiler: ghc-9.6.1
Using install prefix:
/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0
Executables installed in:
/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0/bin
Libraries installed in:
/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0/lib/ghc-9.6.1/lib/javascript-ghcjs-ghc-9.6.1/hashable-1.4.2.0-HkcOg0xvY4vGKtL2nyMhCP
Dynamic Libraries installed in:
/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0/lib/ghc-9.6.1/lib/javascript-ghcjs-ghc-9.6.1
Private executables installed in:
/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0/libexec/javascript-ghcjs-ghc-9.6.1/hashable-1.4.2.0
Data files installed in:
/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0/share/javascript-ghcjs-ghc-9.6.1/hashable-1.4.2.0
Documentation installed in:
/nix/store/fqff94i1nip929fpkv1v3554r15535xk-hashable-1.4.2.0-doc/share/doc/hashable-1.4.2.0
Configuration files installed in:
/nix/store/hlprvqlxx130m5gdwx7y7jzzzsxcsfhp-hashable-1.4.2.0/etc
No alex found
Using ar found on system at:
/nix/store/p3ly54qifr2lyhyyd61vxcdd8nv9ivxd-emscripten-3.1.24/bin/emar
No c2hs found
No cpphs found
No doctest found
Using gcc version 12.2.0 given by user at:
/nix/store/nlgyw2fv0cm8rkz8qm1jyw78vyif1bl9-gcc-wrapper-12.2.0/bin/gcc
Using ghc version 9.6.1 given by user at:
/nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/bin/javascript-unknown-ghcjs-ghc
Using ghc-pkg version 9.6.1 given by user at:
/nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/bin/javascript-unknown-ghcjs-ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.28.0 found on system at:
/nix/store/1pr94zb2a4n0x7ybl3wmyf1nss5wirb1-ghc-9.6.1/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.68 found on system at:
/nix/store/1pr94zb2a4n0x7ybl3wmyf1nss5wirb1-ghc-9.6.1/bin/hpc
Using hsc2hs version 0.68.9 found on system at:
/nix/store/1pr94zb2a4n0x7ybl3wmyf1nss5wirb1-ghc-9.6.1/bin/hsc2hs
Using hscolour version 1.24 found on system at:
/nix/store/bjqlr6sg89jjqaxp5mk6nxi0vgvhvm1x-hscolour-1.24.4/bin/HsColour
No jhc found
Using ld found on system at:
/nix/store/p3ly54qifr2lyhyyd61vxcdd8nv9ivxd-emscripten-3.1.24/bin/emcc
No pkg-config found
Using runghc version 9.6.1 found on system at:
/nix/store/1pr94zb2a4n0x7ybl3wmyf1nss5wirb1-ghc-9.6.1/bin/runghc
Using strip version 2.40 found on system at:
/nix/store/nlgyw2fv0cm8rkz8qm1jyw78vyif1bl9-gcc-wrapper-12.2.0/bin/strip
Using tar found on system at:
/nix/store/lcfhnr6wrj9ssd3dxs39sprvz6qrxlj5-gnutar-1.34/bin/tar
No uhc found
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Preprocessing library for hashable-1.4.2.0..
Building library for hashable-1.4.2.0..
[1 of 7] Compiling Data.Hashable.Imports ( src/Data/Hashable/Imports.hs, dist/build/Data/Hashable/Imports.o )
[2 of 7] Compiling Data.Hashable.LowLevel ( src/Data/Hashable/LowLevel.hs, dist/build/Data/Hashable/LowLevel.o )
[3 of 7] Compiling Data.Hashable.Class ( src/Data/Hashable/Class.hs, dist/build/Data/Hashable/Class.o )
[4 of 7] Compiling Data.Hashable.Lifted ( src/Data/Hashable/Lifted.hs, dist/build/Data/Hashable/Lifted.o )
[5 of 7] Compiling Data.Hashable.Generic.Instances ( src/Data/Hashable/Generic/Instances.hs, dist/build/Data/Hashable/Generic/Instances.o )

src/Data/Hashable/Generic/Instances.hs:5:14: warning: [GHC-19244] [-Wtrustworthy-safe]
    ‘Data.Hashable.Generic.Instances’ is marked as Trustworthy but has been inferred as safe!
  |
5 | {-# LANGUAGE Trustworthy #-}
  |              ^^^^^^^^^^^
[6 of 7] Compiling Data.Hashable.Generic ( src/Data/Hashable/Generic.hs, dist/build/Data/Hashable/Generic.o )
[7 of 7] Compiling Data.Hashable    ( src/Data/Hashable.hs, dist/build/Data/Hashable.o )
[1 of 7] Compiling Data.Hashable.Imports ( src/Data/Hashable/Imports.hs, dist/build/Data/Hashable/Imports.p_o )
[2 of 7] Compiling Data.Hashable.LowLevel ( src/Data/Hashable/LowLevel.hs, dist/build/Data/Hashable/LowLevel.p_o )
[3 of 7] Compiling Data.Hashable.Class ( src/Data/Hashable/Class.hs, dist/build/Data/Hashable/Class.p_o )
[4 of 7] Compiling Data.Hashable.Lifted ( src/Data/Hashable/Lifted.hs, dist/build/Data/Hashable/Lifted.p_o )
[5 of 7] Compiling Data.Hashable.Generic.Instances ( src/Data/Hashable/Generic/Instances.hs, dist/build/Data/Hashable/Generic/Instances.p_o )

src/Data/Hashable/Generic/Instances.hs:5:14: warning: [GHC-19244] [-Wtrustworthy-safe]
    ‘Data.Hashable.Generic.Instances’ is marked as Trustworthy but has been inferred as safe!
  |
5 | {-# LANGUAGE Trustworthy #-}
  |              ^^^^^^^^^^^
[6 of 7] Compiling Data.Hashable.Generic ( src/Data/Hashable/Generic.hs, dist/build/Data/Hashable/Generic.p_o )
[7 of 7] Compiling Data.Hashable    ( src/Data/Hashable.hs, dist/build/Data/Hashable.p_o )
@nix { "action": "setPhase", "phase": "haddockPhase" }
haddockPhase
Preprocessing library for hashable-1.4.2.0..
Running Haddock on library for hashable-1.4.2.0..
Warning: The documentation for the following packages are not installed. No
links will be generated to these packages: array-0.5.5.0, base-4.18.0.0,
binary-0.8.9.1, bytestring-0.11.4.0, containers-0.6.7, deepseq-1.4.8.1,
exceptions-0.10.7, filepath-1.4.100.1, ghc-bignum-1.3, ghc-boot-th-9.6.1,
ghc-prim-0.10.0, mtl-2.3.1, pretty-1.1.3.6, stm-2.5.1.0,
template-haskell-2.20.0.0, text-2.0.2, transformers-0.6.1.0
Warning: --source-* options are ignored when --hyperlinked-source is enabled.

src/Data/Hashable/Imports.hs:10:1: error:
    Failed to load dynamic interface file for Prelude:
    Bad interface file: /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Prelude.dyn_hi
        /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Prelude.dyn_hi: withBinaryFile: does not exist (No such file or directory)
   |
10 | import Prelude ()
   | ^^^^^^^^^^^^^^^^^

src/Data/Hashable/Imports.hs:11:1: error:
    Failed to load dynamic interface file for Data.Int:
    Bad interface file: /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Data/Int.dyn_hi
        /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Data/Int.dyn_hi: withBinaryFile: does not exist (No such file or directory)
   |
11 | import Data.Int (Int64, Int32)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/Data/Hashable/Imports.hs:12:1: error:
    Failed to load dynamic interface file for Data.Word:
    Bad interface file: /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Data/Word.dyn_hi
        /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Data/Word.dyn_hi: withBinaryFile: does not exist (No such file or directory)
   |
12 | import Data.Word (Word64, Word32)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/Data/Hashable/Imports.hs:13:1: error:
    Failed to load dynamic interface file for Data.Bits:
    Bad interface file: /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Data/Bits.dyn_hi
        /nix/store/2y18x162h244cxsia7gaj056h7r5rkx2-javascript-unknown-ghcjs-ghc-native-bignum-9.6.1/lib/javascript-unknown-ghcjs-ghc-9.6.1/lib/../lib/javascript-ghcjs-ghc-9.6.1/base-4.18.0.0/Data/Bits.dyn_hi: withBinaryFile: does not exist (No such file or directory)
   |
13 | import Data.Bits (xor, shiftR, shiftL)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
haddock: Cannot typecheck modules

I’ll keep looking into this. It might need an annoying amount of recompilation, but I’m pretty sure there’s a secret magical nix button to make all of this fall into place.

1 Like