Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Dynamic dependencies for Haskell (discussion) #19

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cxx/preprocessor.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ def cxx_inherited_preprocessor_infos(first_order_deps: list[Dependency]) -> list
return filter(None, [x.get(CPreprocessorInfo) for x in first_order_deps])

def cxx_merge_cpreprocessors(ctx: AnalysisContext, own: list[CPreprocessor], xs: list[CPreprocessorInfo]) -> CPreprocessorInfo:
return cxx_merge_cpreprocessors_actions(ctx.actions, own, xs)

def cxx_merge_cpreprocessors_actions(actions: AnalysisActions, own: list[CPreprocessor], xs: list[CPreprocessorInfo]) -> CPreprocessorInfo:
kwargs = {"children": [x.set for x in xs]}
if own:
kwargs["value"] = own
return CPreprocessorInfo(
set = ctx.actions.tset(CPreprocessorTSet, **kwargs),
set = actions.tset(CPreprocessorTSet, **kwargs),
)

def _format_include_arg(flag: str, path: cmd_args, compiler_type: str) -> list[cmd_args]:
Expand Down
42 changes: 41 additions & 1 deletion decls/haskell_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ def _deps_arg():
from which this rules sources import modules or native linkable rules exporting symbols
this rules sources call into.
"""),
"srcs_deps": attrs.dict(attrs.source(), attrs.list(attrs.source()), default = {}, doc = """
Allows to declare dependencies for sources manually, additionally to the dependencies automatically detected.
"""),
}

def _compiler_flags_arg():
return {
"compiler_flags": attrs.list(attrs.string(), default = [], doc = """
"compiler_flags": attrs.list(attrs.arg(), default = [], doc = """
Flags to pass to the Haskell compiler when compiling this rule's sources.
"""),
}
Expand All @@ -40,9 +43,46 @@ def _exported_linker_flags_arg():
"""),
}

def _scripts_arg():
return {
"_generate_target_metadata": attrs.dep(
providers = [RunInfo],
default = "prelude//haskell/tools:generate_target_metadata",
),
"_ghc_wrapper": attrs.dep(
providers = [RunInfo],
default = "prelude//haskell/tools:ghc_wrapper",
),
}

def _external_tools_arg():
return {
"external_tools": attrs.list(attrs.dep(providers = [RunInfo]), default = [], doc = """
External executables called from Haskell compiler during preprocessing or compilation.
"""),
}

def _srcs_envs_arg():
return {
"srcs_envs": attrs.dict(attrs.source(), attrs.dict(attrs.string(), attrs.arg()), default = {}, doc = """
Individual run-time env for each source compilation.
"""),
}

def _use_argsfile_at_link_arg():
return {
"use_argsfile_at_link": attrs.bool(default = False, doc = """
Use response file at linking.
"""),
}

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,
scripts_arg = _scripts_arg,
external_tools_arg = _external_tools_arg,
srcs_envs_arg = _srcs_envs_arg,
use_argsfile_at_link_arg = _use_argsfile_at_link_arg,
)
19 changes: 19 additions & 0 deletions decls/haskell_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ haskell_binary = prelude_rule(
native_common.link_group_public_deps_label() |
native_common.link_style() |
haskell_common.srcs_arg() |
haskell_common.external_tools_arg() |
haskell_common.srcs_envs_arg () |
haskell_common.use_argsfile_at_link_arg () |
haskell_common.compiler_flags_arg() |
haskell_common.deps_arg() |
haskell_common.scripts_arg() |
buck.platform_deps_arg() |
{
"contacts": attrs.list(attrs.string(), default = []),
Expand Down Expand Up @@ -163,8 +167,12 @@ haskell_library = prelude_rule(
attrs = (
# @unsorted-dict-items
haskell_common.srcs_arg() |
haskell_common.external_tools_arg() |
haskell_common.srcs_envs_arg() |
haskell_common.use_argsfile_at_link_arg() |
haskell_common.compiler_flags_arg() |
haskell_common.deps_arg() |
haskell_common.scripts_arg() |
buck.platform_deps_arg() |
native_common.link_whole(link_whole_type = attrs.bool(default = False)) |
native_common.preferred_linkage(preferred_linkage_type = attrs.enum(Linkage.values())) |
Expand All @@ -184,6 +192,16 @@ haskell_library = prelude_rule(
),
)

haskell_toolchain_library = prelude_rule(
name = "haskell_toolchain_library",
docs = """
Declare a library available as part of the GHC toolchain.
""",
attrs = {
},
)


haskell_prebuilt_library = prelude_rule(
name = "haskell_prebuilt_library",
docs = """
Expand Down Expand Up @@ -257,4 +275,5 @@ haskell_rules = struct(
haskell_ide = haskell_ide,
haskell_library = haskell_library,
haskell_prebuilt_library = haskell_prebuilt_library,
haskell_toolchain_library = haskell_toolchain_library,
)
Loading