By default, rules_haskell rebuilds all modules in a library if any module changes because it does not analyze source code dependencies. To enable incremental builds and avoid unnecessary recompilation, you can use the haskell_module rule (from @rules_haskell//haskell/experimental:defs.bzl) to explicitly define module-level dependencies.
When using haskell_module, you must use the modules attribute in haskell_library instead of srcs.
Dependencies for a haskell_module can be:
- Internal modules: Listed in the
deps attribute of the haskell_module rule. - Library dependencies: Any library listed in the
deps attribute of the enclosing haskell_library. - Specific modules from other libraries: Listed in the
cross_library_deps attribute of the haskell_module rule (requires the target library to be listed in narrowed_deps of the enclosing library).
load("@rules_haskell//haskell:defs.bzl", "haskell_library")
load("@rules_haskell//haskell/experimental:defs.bzl", "haskell_module")
haskell_module(
name = "LibMod1",
src = "src/LibMod1.hs",
src_strip_prefix = "src",
deps = [":LibMod2"],
enable_th = True,
)
haskell_module(
name = "LibMod2",
src = "src/LibMod2.hs",
src_strip_prefix = "src",
)
haskell_library(
name = "lib",
modules = [
"LibMod1",
"LibMod2",
],
deps = [
"//:base",
"//:template-haskell",
],
)