Skip to content

Conversation

@iteratee
Copy link
Collaborator

@iteratee iteratee commented Oct 30, 2025

Migrated from this PR #2287 see there for additional history.

Original description below:

Previously, an empty library that only exported modules from another library failed to build. Bazel would error out when the .a file wasn't created. These libraries are becoming more common in the Haskell ecosystem, so we need to support them.

There is a straightforward way to handle these libraries. We make the package database the default output. We avoid creating an output file for any libraries if the library is marked as empty. This is all straightforward bazel dependency/output management.

Adjust the cabal wrapper to fix up the package database even in the case that there is no library. Otherwise we end up with an empty package database, which isn't what we're looking for.

Drop the check for `libraries != []` in the check for processing the
package config file. Haskell supports empty libraries. In order for
Bazel to support them, we need to process the package config, even for
empty libraries.
@iteratee iteratee requested a review from avdv as a code owner October 30, 2025 22:39
@iteratee
Copy link
Collaborator Author

This has the test you asked for. I'm not done going through the other comments.

@iteratee
Copy link
Collaborator Author

Likewise, could we use attr.label_keyed_string_dict(providers = [HaskellCabalLibraryArgs]) here instead, with a TODO to switch to string_keyed_label_dict some time later.

This makes it explicit what to expect here.

Just call _invert before passing its value to the _stack_snapshot rule.

I'm not sure we can. For the majority of cases, we want to use the same label, which means that we can't invert the dictionary. I'll add the TODO.

@iteratee
Copy link
Collaborator Author

I am not sure this file should live here. I would prefer if it would be in haskell/cabal instead. WDYT?

Moved as requested, and the references in the codebase have been updated.

Rather than continually proliferate additional settings on
haskell_cabal_library, create a rule and provider that can hold cabal
specific settings.

Add `empty_lib` as the first such setting. When building an empty lib,
bazel will look for the package file, instead of for any object files.
This will fix several packages that are currently blacklisted. It will
also allow the use of packages with sublibraries and an empty main lib.

Currently there is no way to use this with a stack snapshot, short of
vendoring a package and adding a `haskell_cabal_args` to the vendored
build file. A simpler way is planned.
Empty haskell libraries have been a longstanding problem. Add support
for an additional component type `empty_lib`, which is like `lib`,
except that an additional `haskell_cabal_args` target will be created
for the library, instructing Bazel not to look for any object files.

Remove the longstanding package blacklist for empty packages. Replace it
with the now possible correct entries for those libraries, indicating
that the main library is empty.
It can occur that a module has a source file named "Setup.hs" that isn't
a cabal setup module. The current setup finder will find such a module
and then setup will break. Add a flag to cabal_args to indicate that any
such module should be ignored.
Modules require a facade for stack_snapshot. Push components_args
through the facade and back into the main implementation.
@iteratee
Copy link
Collaborator Author

@avdv That was all of the comments on the previous PR resolved, with the exception of not using a label keyed string dict.

I also found an issue from CI with profiling and an empty haskell_cabal_library. The issue is fixed.

@iteratee
Copy link
Collaborator Author

The one failure appears to be due to a transient network issue with hackage. I would re-run just that job, but I can't do that myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants