tweag / rules_haskell

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

haskell_doc should support haskell_proto_library #1030

Open ghorn opened 5 years ago

ghorn commented 5 years ago

rules_haskell rev dabf7afd9d5dc622d187a71169e2bb6b54ca3a8f bazel version 0.28

I have a build file something like:

load("@io_tweag_rules_haskell//haskell:haskell.bzl", 
    "haskell_library",
    "haskell_proto_library",
    "haskell_doc")

proto_library(
    name = "hello_world_proto",
    srcs = ["hello_world.proto"],
)

haskell_proto_library(
    name = "hello_world_haskell_proto",
    deps = [
        ":hello_world_proto",
    ],
)

kitty_haskell_library(
    name = "hello_world_haskell",
    srcs = ["HelloWorld.hs"],  # Just imports the proto and does something trivial
    deps = [
        ":hello_world_haskell_proto",
        "//ghc_pkgs:base",
        "//ghc_pkgs:lens",
        "//ghc_pkgs:text",
    ],
)

# Haddocks version A: depend on just the haskell_library
haskell_doc(
    name = "haddocks_a",
    deps = [
        ":hello_world_haskell",
    ],
)

# Haddocks version B: depend on both haskell_library and haskell_proto_library
haskell_doc(
    name = "haddocks_b",
    deps = [
        ":hello_world_haskell",
        ":hello_world_haskell_proto",
    ],
)

It's a bazel proto_library which a haskell_proto_library depends on, and a normal haskell_library which imports the haskell_proto_library.

When I try to generate haddocks depending only on the haskell_library I get a warning that the proto is not in scope:

samples/protobufs/HelloWorld.hs:1:1:
    Could not find link destinations for:

    - Proto.Samples.Protobufs.HelloWorld.HelloWorld

When I try to generate haddocks depending also on the haskell_proto_library, I get a rules_haskell error something like:

ERROR: /home/greg/the_project/samples/protobufs/BUILD.bazel:38:1: in haskell_doc rule //samples/protobufs:haddocks_b: 
Traceback (most recent call last):
    File "/home/greg/the_project/samples/protobufs/BUILD.bazel", line 38
        haskell_doc(name = 'haddocks_b')
    File "/home/greg/.cache/bazel/_bazel_greg/105d860db94dde3a6fc3b4a248924017/external/io_tweag_rules_haskell/haskell/haddock.bzl", line 254, in _haskell_doc_rule_impl
        haddock_dict[package_id]
key None not found in dictionary

I assume that this is unsupported functionality.

This is important to us adopting haskell_proto_library because we hacked haddock to error on warnings.

ghorn commented 5 years ago

Any estimates on how hard this would be? This is blocking the use of protobufs for us.

Profpatsch commented 5 years ago

cc @flokli @guibou

guibou commented 5 years ago

1108 is a PR which reproduces both issue and provide a fix for the build failure.

@ghorn for now you can just add Proto.Samples.Protobufs.HelloWorld.HelloWorld in the ignore list of your custom haddock.

flokli commented 5 years ago

GitHub autoclosed this due to the description in #1108, but it's not yet fixed, so reopening.

aherrmann commented 2 years ago

This seems to still be an issue.

$ bazel test //tests/haddock_protobuf:all
...
INFO: From HaskellHaddock //tests/haddock_protobuf:hello_world_haskell:
Warning: HelloWorld: could not find link destinations for:

        - Proto.Tests.HaddockProtobuf.HelloWorld.Person
...

And the generated haddocs don't include the protobuf symbols.