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

module_prefix for adjusting interface file (hi/dyn_hi) path #60

Open
wants to merge 1 commit into
base: wavewave/worker-id
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions decls/haskell_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def _extra_libraries_arg():
"""),
}

def _module_prefix_arg():
return {
"module_prefix": attrs.option(attrs.string(), default = None, doc = """
Module prefix if needed
"""),
}

haskell_common = struct(
srcs_arg = _srcs_arg,
deps_arg = _deps_arg,
Expand All @@ -93,4 +100,5 @@ haskell_common = struct(
srcs_envs_arg = _srcs_envs_arg,
use_argsfile_at_link_arg = _use_argsfile_at_link_arg,
extra_libraries_arg = _extra_libraries_arg,
module_prefix_arg = _module_prefix_arg,
)
2 changes: 2 additions & 0 deletions decls/haskell_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ haskell_binary = prelude_rule(
haskell_common.compiler_flags_arg() |
haskell_common.deps_arg() |
haskell_common.scripts_arg() |
haskell_common.module_prefix_arg() |
buck.platform_deps_arg() |
{
"contacts": attrs.list(attrs.string(), default = []),
Expand Down Expand Up @@ -175,6 +176,7 @@ haskell_library = prelude_rule(
haskell_common.compiler_flags_arg() |
haskell_common.deps_arg() |
haskell_common.scripts_arg() |
haskell_common.module_prefix_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 Down
9 changes: 6 additions & 3 deletions haskell/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _strip_prefix(prefix, s):
return stripped if stripped != None else s


def _modules_by_name(ctx: AnalysisContext, *, sources: list[Artifact], link_style: LinkStyle, enable_profiling: bool, suffix: str) -> dict[str, _Module]:
def _modules_by_name(ctx: AnalysisContext, *, sources: list[Artifact], link_style: LinkStyle, enable_profiling: bool, suffix: str, module_prefix: str | None) -> dict[str, _Module]:
modules = {}

osuf, hisuf = output_extensions(link_style, enable_profiling)
Expand All @@ -137,7 +137,10 @@ def _modules_by_name(ctx: AnalysisContext, *, sources: list[Artifact], link_styl
continue

module_name = src_to_module_name(src.short_path) + bootsuf
interface_path = paths.replace_extension(src.short_path, "." + hisuf + bootsuf)
if module_prefix:
interface_path = paths.replace_extension(module_prefix.replace(".", "/") + "/" + src.short_path, "." + hisuf + bootsuf)
else:
interface_path = paths.replace_extension(src.short_path, "." + hisuf + bootsuf)
interface = ctx.actions.declare_output("mod-" + suffix, interface_path)
interfaces = [interface]
object_path = paths.replace_extension(src.short_path, "." + osuf + bootsuf)
Expand Down Expand Up @@ -832,7 +835,7 @@ def compile(
pkgname: str | None = None) -> CompileResultInfo:
artifact_suffix = get_artifact_suffix(link_style, enable_profiling)

modules = _modules_by_name(ctx, sources = ctx.attrs.srcs, link_style = link_style, enable_profiling = enable_profiling, suffix = artifact_suffix)
modules = _modules_by_name(ctx, sources = ctx.attrs.srcs, link_style = link_style, enable_profiling = enable_profiling, suffix = artifact_suffix, module_prefix = ctx.attrs.module_prefix)

haskell_toolchain = ctx.attrs._haskell_toolchain[HaskellToolchainInfo]

Expand Down