tweag / rules_haskell

Haskell rules for Bazel.
https://haskell.build
Apache License 2.0
266 stars 80 forks source link

Profiled builds of Cabal packages with Template Haskell fail with static RTS #1353

Closed aherrmann closed 4 years ago

aherrmann commented 4 years ago

Describe the bug Building a Cabal package in profiling mode with GHC using the static RTS fails with an error of the form

<command line>: can't load .so/.DLL for: libHSsop-core-0.4.0.0.so (libHSsop-core-0.4.0.0.so: cannot open shared object file: No such file or directory)

To Reproduce

Expected behavior The build should succeed.

Environment

Additional context The build fails on what looks like a GHCi linker error when it tries to link the library for the package sop-core. The error message mentions libHSsop-core-0.4.0.0.so without the usual GHC version suffix, this usually means that GHC is really looking for libHSsop-core-0.4.0.0.a. Looking at the artifacts produced by Cabal building sop-core we see that it produces libHSsop-core-0.4.0.0.a and libHSsop-core-0.4.0.0_p.a. However, rules_haskell only tracks the _p.a output in profiling mode meaning that the plain .a will not be made available to any actions down the line depending on sop-core. A possible solution might be to track the plain .a output as well and make it available to the Cabal build action.

aherrmann commented 4 years ago

The issue seems to be that Cabal with --enable-profiling builds both a profiled and a non-profiled version of the library. Building template Haskell in the non-profiled version will require non-profiled versions of dependencies in scope. As a proof of concept, setting --ghc-options=-prof works around the issue. Cabal will still produce both a _p.a and a .a however since -prof is set on both, GHC will be able to compile template Haskell using the dependency's _p.a output in both cases.

guibou commented 4 years ago

The issue seems to be that Cabal with --enable-profiling builds both a profiled and a non-profiled version of the library

I described this behavior in #438.

rules_haskell is currently using an approach to profiling (-fexternal-interpreter) which is not used by the rest of the world. cabal is not using it. stack is not using it. So we are facing a lot of bug because as far as I know, we are the only users of this feature.

guibou commented 4 years ago

May be related: https://gitlab.haskell.org/ghc/ghc/issues/16257#comment:11