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

Support virtual_modules #47

Draft
wants to merge 3 commits into
base: wavewave/no-more-special-base
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
8 changes: 8 additions & 0 deletions decls/haskell_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
2 changes: 2 additions & 0 deletions decls/haskell_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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() |
Expand All @@ -188,6 +189,7 @@ haskell_library = prelude_rule(
"linker_flags": attrs.list(attrs.arg(), default = []),
"platform": attrs.option(attrs.string(), default = None),
"platform_linker_flags": attrs.list(attrs.tuple(attrs.regex(), attrs.list(attrs.arg())), default = []),
"use_same_package_name": attrs.bool(default = False),
}
),
)
Expand Down
3 changes: 1 addition & 2 deletions haskell/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def _dynamic_target_metadata_impl(actions, artifacts, dynamic_values, outputs, a
package_flag = _package_flag(arg.haskell_toolchain)
ghc_args = cmd_args()
ghc_args.add("-hide-all-packages")
ghc_args.add(package_flag, "base")

ghc_args.add(cmd_args(arg.toolchain_libs, prepend=package_flag))
ghc_args.add(cmd_args(packages_info.exposed_package_args))
Expand Down Expand Up @@ -346,7 +345,7 @@ def get_packages_info2(
hidden_args = [l for lib in libs.traverse() for l in lib.libs]

exposed_package_libs = cmd_args()
exposed_package_args = cmd_args([package_flag, "base"], hidden = hidden_args)
exposed_package_args = cmd_args()

if for_deps:
package_db_projection = "deps_package_db"
Expand Down
11 changes: 8 additions & 3 deletions haskell/haskell.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]),
]
Expand Down Expand Up @@ -810,8 +811,12 @@ def haskell_library_impl(ctx: AnalysisContext) -> list[Provider]:
indexing_tsets = {}
sub_targets = {}

libname = repr(ctx.label.path).replace("//", "_").replace("/", "_") + "_" + ctx.label.name
pkgname = libname.replace("_", "-")
if(ctx.attrs.use_same_package_name):
libname = ctx.label.name
pkgname = libname
else:
libname = repr(ctx.label.path).replace("//", "_").replace("/", "_") + "_" + ctx.label.name
pkgname = libname.replace("_", "-")

md_file = target_metadata(
ctx,
Expand Down