rules_haskell icon indicating copy to clipboard operation
rules_haskell copied to clipboard

broken `@haddock` when using `ghc_plugin`

Open sellout opened this issue 4 years ago • 1 comments

Describe the bug

If a target depends on a ghc_plugin, then the @haddock for that target fails with "haddock: can't find a package database at bazel-out/k8-fastbuild/bin/{{{plugin library}}}" unless the target depends on the plugin's underlying library.

To Reproduce

haskell_library(
    name = "dummy_plugin",
    srcs = ["Dummy.hs"],
    deps = [...],
)

ghc_plugin(
    name = "dummy",
    module = "Dummy",
    deps = [":dummy_plugin"],
)

haskell_library(
    name = "test_dummy",
    srcs = ["Dummy/Test.hs"],
    plugins = [":dummy"],
)

then bazel build :test_dummy@haddock will fail as described.

Building and using :test_dummy otherwise behaves correctly.

Expected behavior

Should build the haddock successfully.

Environment

  • OS name + version: NixOS (kernel 5.4)
  • Bazel version: 3.3.1
  • Version of the rules: From 5 Jan 2021, "d58e2318e84f0280002ae95569fa09f593c0482f"

Additional context

This has a workaround, which is to add the plugin library as an explicit dependency on the downstream library:

haskell_library(
    name = "test_dummy",
    srcs = ["Dummy/Test.hs"],
    plugins = [":dummy"],
    deps = [":dummy_plugin"], # redundant, to make Haddock happy
)

We benefit here, I think, from the weakness of GHC's -Wunused-packages -- it doesn't always warn on transitive dependencies, and that seems to be the case here, as this builds cleanly.

sellout avatar May 12 '21 16:05 sellout

@sellout Thanks for reporting this and the repro instructions. I was able to reproduce this in https://github.com/tweag/rules_haskell/pull/1550.

I tried a quick fix by just adding plugin dependencies to the list of dependencies tracked in the haddock aspect. However, that was not sufficient. So, this needs a little more investigation.

Thanks for providing a work-around. I confirmed that it also works on the repro in #1550. Looking at the arguments passed to haddock the only difference are additional --read-interface flags:

'--read-interface=../ghc-8.8.3,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/ghc_0.haddock'
'--read-interface=../array-0.5.4.0,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/array_0.haddock'
'--read-interface=../binary-0.8.7.0,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/binary_0.haddock'
'--read-interface=../bytestring-0.10.10.0,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/bytestring_0.haddock'
'--read-interface=../deepseq-1.4.4.0,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/deepseq_0.haddock'
'--read-interface=../containers-0.6.2.1,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/containers_0.haddock'
'--read-interface=../directory-1.3.6.0,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/directory_0.haddock'
'--read-interface=../filepath-1.4.2.1,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/filepath_0.haddock'
'--read-interface=../time-1.9.3,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/time_0.haddock'
'--read-interface=../unix-2.7.2.2,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/unix_0.haddock'
'--read-interface=../ghc-boot-8.8.3,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/ghc-boot_0.haddock'
'--read-interface=../ghc-boot-th-8.8.3,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/ghc-boot-th_0.haddock'
'--read-interface=../ghc-heap-8.8.3,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/ghc-heap_0.haddock'
'--read-interface=../ghci-8.8.3,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/ghci_0.haddock'
'--read-interface=../template-haskell-2.15.0.0,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/template-haskell_0.haddock'
'--read-interface=../pretty-1.1.3.6,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/pretty_0.haddock'
'--read-interface=../transformers-0.5.6.2,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/transformers_0.haddock'
'--read-interface=../hpc-0.6.0.3,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/hpc_0.haddock'
'--read-interface=../process-1.6.8.0,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/process_0.haddock'
'--read-interface=../terminfo-0.4.1.4,external/rules_haskell_ghc_nixpkgs_haskell_toolchain/haddock/interfaces/terminfo_0.haddock'
'--read-interface=../testsZShaddock-with-pluginZSplugin-library,bazel-out/k8-fastbuild/bin/tests/haddock-with-plugin/testsZShaddock-with-pluginZSplugin-library.haddock'

aherrmann avatar May 18 '21 11:05 aherrmann