diff --git a/decls/haskell_common.bzl b/decls/haskell_common.bzl index 711a3c2ad..0a9eaa729 100644 --- a/decls/haskell_common.bzl +++ b/decls/haskell_common.bzl @@ -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, @@ -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, ) diff --git a/decls/haskell_rules.bzl b/decls/haskell_rules.bzl index 17923f930..f20cc98c1 100644 --- a/decls/haskell_rules.bzl +++ b/decls/haskell_rules.bzl @@ -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 = []), @@ -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())) | diff --git a/haskell/compile.bzl b/haskell/compile.bzl index 7c85c0d50..3efa4d480 100644 --- a/haskell/compile.bzl +++ b/haskell/compile.bzl @@ -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) @@ -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) @@ -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]