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

Handle missing library in haskell_toolchain_library #882

Merged
merged 2 commits into from
May 21, 2019
Merged
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
25 changes: 19 additions & 6 deletions haskell/private/haskell_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ load(":private/java.bzl", "java_interop_info")
load(":private/mode.bzl", "is_profiling_enabled")
load(
":private/path_utils.bzl",
"get_dynamic_hs_lib_name",
"get_lib_name",
"ln",
"match_label",
"parse_pattern",
Expand Down Expand Up @@ -634,18 +636,29 @@ Check that it ships with your version of GHC.
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)

# Workaround for https://github.com/tweag/rules_haskell/issues/881
# Static and dynamic libraries don't necessarily pair up 1 to 1.
# E.g. the rts package in the Unix GHC bindist contains the
# dynamic libHSrts and the static libCffi and libHSrts.
libs = {
get_dynamic_hs_lib_name(hs.toolchain.version, lib): {"dynamic": lib}
for lib in target[HaskellImportHack].dynamic_libraries
}
for lib in target[HaskellImportHack].static_libraries:
name = get_lib_name(lib)
entry = libs.get(name, {})
entry["static"] = lib
libs[name] = entry
libraries_to_link = [
cc_common.create_library_to_link(
actions = ctx.actions,
feature_configuration = feature_configuration,
dynamic_library = dynamic_library,
static_library = static_library,
dynamic_library = lib.get("dynamic", None),
static_library = lib.get("static", None),
cc_toolchain = cc_toolchain,
)
for (dynamic_library, static_library) in zip(
target[HaskellImportHack].dynamic_libraries,
target[HaskellImportHack].static_libraries,
)
for lib in libs.values()
]
compilation_context = cc_common.create_compilation_context(
headers = target[HaskellImportHack].headers,
Expand Down
17 changes: 17 additions & 0 deletions haskell/private/path_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ def get_lib_name(lib):
end = paths.replace_extension(base, "") if n == -1 else base[:n]
return end

def get_dynamic_hs_lib_name(ghc_version, lib):
"""Return name of library by dropping extension,
"lib" prefix, and GHC version suffix.

Args:
version: GHC version.
lib: The library File.

Returns:
String: name of library.
"""
name = get_lib_name(lib)
suffix = "-ghc{}".format(ghc_version)
if name.endswith(suffix):
name = name[:-len(suffix)]
return name

def link_libraries(libs_to_link, args):
"""Add linker flags to link against the given libraries.

Expand Down