From 55583a6c1cf01d8a6537e0060dc5f94260681ff7 Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Fri, 27 Sep 2024 12:50:51 -0700 Subject: [PATCH] support virtual_modules the same as Cabal virtual-modules. This is necessary to support ghc-prim compilation. --- decls/haskell_common.bzl | 8 ++++++++ decls/haskell_rules.bzl | 1 + haskell/haskell.bzl | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/decls/haskell_common.bzl b/decls/haskell_common.bzl index 0f704f71d..ed670b2c3 100644 --- a/decls/haskell_common.bzl +++ b/decls/haskell_common.bzl @@ -76,6 +76,13 @@ def _use_argsfile_at_link_arg(): """), } +def _virtual_modules_arg(): + return { + "virtual_modules": attrs.named_set(attrs.string(), sorted = True, default = [], doc = """ + A list of virtual Haskell modules. See Cabal virtual-modules. +"""), + } + haskell_common = struct( srcs_arg = _srcs_arg, deps_arg = _deps_arg, @@ -85,4 +92,5 @@ haskell_common = struct( external_tools_arg = _external_tools_arg, srcs_envs_arg = _srcs_envs_arg, use_argsfile_at_link_arg = _use_argsfile_at_link_arg, + virtual_modules_arg = _virtual_modules_arg, ) diff --git a/decls/haskell_rules.bzl b/decls/haskell_rules.bzl index 02ac5f1a4..3472362c7 100644 --- a/decls/haskell_rules.bzl +++ b/decls/haskell_rules.bzl @@ -170,6 +170,7 @@ haskell_library = prelude_rule( haskell_common.external_tools_arg() | haskell_common.srcs_envs_arg() | haskell_common.use_argsfile_at_link_arg() | + haskell_common.virtual_modules_arg() | haskell_common.compiler_flags_arg() | haskell_common.deps_arg() | haskell_common.scripts_arg() | diff --git a/haskell/haskell.bzl b/haskell/haskell.bzl index 5eaed84b3..110ea54ec 100644 --- a/haskell/haskell.bzl +++ b/haskell/haskell.bzl @@ -455,6 +455,7 @@ def _make_package( for module in md["module_graph"].keys() if not module.endswith("-boot") ] + virtual_modules = ctx.attrs.virtual_modules # XXX use a single import dir when this package db is used for resolving dependencies with ghc -M, # which works around an issue with multiple import dirs resulting in GHC trying to locate interface files @@ -469,7 +470,7 @@ def _make_package( "id: " + pkgname, "key: " + pkgname, "exposed: False", - "exposed-modules: " + ", ".join(modules), + "exposed-modules: " + ", ".join(modules + virtual_modules), "import-dirs:" + ", ".join(import_dirs), "depends: " + ", ".join([lib.id for lib in hlis]), ]