cabal-buck2-0.6.0.0: buck2/prelude/decls/haskell_common.bzl
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is dual-licensed under either the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree or the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree. You may select, at your option, one of the
# above-listed licenses.
# TODO(cjhopman): This was generated by scripts/hacks/rules_shim_with_docs.py,
# but should be manually edited going forward. There may be some errors in
# the generated docs, and so those should be verified to be accurate and
# well-formatted (and then delete this TODO)
def _srcs_arg():
return {
"srcs": attrs.named_set(
attrs.source(),
sorted = True,
default = [],
doc = """
A list of Haskell sources to be built by this rule. In the list form,
each source file must match the module name with "." replaced by "/", e.g.
`[ "Main.hs", "Other/Module.hs" ]`.
If the source files don't match the module names 1:1, then you
can use the dict form, in which the keys are module names, e.g.
`{ "Main": "src/test.hs", "Other.Module" : "src/Other/Module.hs" }`
""",
),
}
def _deps_arg():
return {
"deps": attrs.list(
attrs.dep(),
default = [],
doc = """
Either `haskell_library()` or `prebuilt_haskell_library()` rules
from which this rules sources import modules or native linkable rules exporting symbols
this rules sources call into.
""",
),
}
def _compiler_flags_arg():
return {
# attrs.arg(), not attrs.string(): lets a flag carry a
# `$(location ...)`/`$(exe ...)` macro that resolves to a real
# dependency edge.
"compiler_flags": attrs.list(
attrs.arg(),
default = [],
doc = """
Flags to pass to the Haskell compiler when compiling this rule's sources.
""",
),
}
def _build_tool_depends_arg():
return {
"build_tool_depends": attrs.list(
attrs.exec_dep(),
default = [],
doc = """
Executables (haskell_binary(), export_exe(), or anything else with a
single default output) that this rule's own GHC invocation needs
reachable via PATH by bare name. The executables can then be used
with -pgmL or -pgmF flags for example, either as a command-line
arg or in a {-# OPTIONS_GHC ... #-} pragma.
The build_tool_depends attribute is used to implement Cabal's
build-tool-depends: field.
""",
),
}
def _run_tool_depends_arg():
return {
"run_tool_depends": attrs.list(
attrs.dep(),
default = [],
doc = """
Executables that the binary needs on PATH when it runs.
These are on PATH whenever the binary runs through its
RunInfo: with `buck2 run`, as a test, or as a tool of another rule.
This is used to implement Cabal's missing run-tool-depends field.
""",
),
}
def _exported_linker_flags_arg():
return {
"exported_linker_flags": attrs.list(
attrs.string(),
default = [],
doc = """
Linker flags used by dependent rules when linking with this library.
""",
),
}
def _data_dirs_arg():
return {
"data_dirs": attrs.dict(
attrs.string(),
attrs.dep(),
sorted = False,
default = {},
doc = """
Directories of data files, each keyed by the name of the environment
variable that should point at it (for a Cabal package, `<pkg>_datadir`,
which its Paths_<pkg> module reads).
When this rule's sources are compiled, the compile sets only the
variables that its Template Haskell splices could read. These are the
variables for the rule's own Paths_<pkg> modules, and the variables for
the Paths_<pkg> modules of any library whose code the splices can run.
If the compile might run one of the rule's build tools, it sets all of
the rule's variables instead, because a build tool might read data files
of its own.
For a haskell_binary, all the variables are also set whenever the binary
is run through its RunInfo. That happens with `buck2 run`, when the
binary runs as a test, and when it runs as a tool of another rule.
""",
),
}
haskell_common = struct(
srcs_arg = _srcs_arg,
deps_arg = _deps_arg,
compiler_flags_arg = _compiler_flags_arg,
exported_linker_flags_arg = _exported_linker_flags_arg,
build_tool_depends_arg = _build_tool_depends_arg,
data_dirs_arg = _data_dirs_arg,
run_tool_depends_arg = _run_tool_depends_arg,
)