haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.63k stars 695 forks source link

javascript-unknown-ghcjs-ghc: unknown unit #9010

Open chreekat opened 1 year ago

chreekat commented 1 year ago

Bug Symptom

While using the GHC javascript backend, I tried to use Cabal HEAD to build my application. It eventually fails. It says the command that failed is

/home/b/Projects/usort/usort-web/ghc/_build/stage1/bin/javascript-unknown-ghcjs-ghc \
    --make -fbuilding-cabal-package -O -static \
    -outputdir /home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web-tmp \
    -odir /home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web-tmp \
    -hidir /home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web-tmp \
    -stubdir /home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web-tmp \
    -i -ihs-app \
    -i/home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web-tmp \
    -i/home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/autogen \
    -i/home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/global-autogen \
    -I/home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/autogen \
    -I/home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/global-autogen \
    -I/home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web-tmp \
    -optP-include \
    -optP/home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/autogen/cabal_macros.h \
    -this-unit-id usort-web-0.1.0.0-inplace-usort-web \
    -hide-all-packages -Wmissing-home-modules -no-user-package-db \
    -package-db /home/b/.cabal/store/ghc-9.7.20230421/package.db \
    -package-db /home/b/Projects/usort/dist-newstyle/packagedb/ghc-9.7.20230421 \
    -package-db /home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/package.conf.inplace \
    -package-id base-4.18.0.0-inplace \
    -package-id usort-web-0.1.0.0-inplace \
    -XHaskell2010 hs-app/Main.hs \
    -o /home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web \
    -hide-all-packages

and the failure from that command is

[2 of 2] Linking /home/b/Projects/usort/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230421/usort-web-0.1.0.0/x/usort-web/build/usort-web/usort-web.jsexe [Objects changed]
javascript-unknown-ghcjs-ghc: unknown unit: usort-web-0.1.0.0-inplace-usort-web

I bisected the failure and it started with 94615d6ac6ef585329eab192ed70486e722eeca1 (sorry @mpickering).

To Reproduce

This failure can be reproduced with a basic empty Cabal package.

  1. Build the javascript backend
  2. Set GHC=path/to/stage1/bin/javascript-unknown-ghcjs-ghc
  3. Build cabal from 94615d6ac6ef585329eab192ed70486e722eeca1 or later
  4. Set CABAL=path/to/dist-newstyle/build/x86_64-linux/ghc-9.2.7/cabal-install-3.11.0.0/x/cabal/build/cabal/cabal
  5. cabal init -n repro
  6. cd repro
  7. $CABAL -w $GHC --hc-pkg ${GHC}-pkg build

Additional context

Versions of GHC tried:

  1. Failed with 9d1a8d87c2364321f27f4fc224a7042d5e47612d and the javascript backend
  2. Succeeds with ghc-9.2.4 for x86_64 (from NixOS-23.05 nixpkgs)
hsyl20 commented 1 month ago

It's probably linked to https://gitlab.haskell.org/ghc/ghc/-/issues/23013: the JS linker has its own code paths compared to the native one. It may not work with multiple components yet.