Skip to content

Commit e0346c8

Browse files
authored
Merge branch 'master' into gh2099_env_specific_config
2 parents 96dd564 + 0039f48 commit e0346c8

File tree

5 files changed

+160
-166
lines changed

5 files changed

+160
-166
lines changed

haskell/BUILD.bazel

-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
3-
load(
4-
"@rules_haskell//haskell:private/haskell_impl.bzl",
5-
"haskell_toolchain_libraries",
6-
)
73
load(
84
"@rules_haskell//haskell:private/cc_wrapper.bzl",
95
"cc_wrapper",
@@ -167,10 +163,6 @@ toolchain_type(
167163
# implemented, yet. See
168164
# https://github.com/bazelbuild/proposals/blob/master/designs/2019-02-12-toolchain-transitions.md
169165
# This will need to be revisited once that proposal is implemented.
170-
haskell_toolchain_libraries(
171-
name = "toolchain-libraries",
172-
visibility = ["//visibility:public"],
173-
)
174166

175167
config_setting(
176168
name = "use_worker",

haskell/defs.bzl

-3
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,6 @@ haskell_toolchain_library = rule(
670670
package = attr.string(
671671
doc = "The name of a GHC package not built by Bazel. Defaults to the name of the rule.",
672672
),
673-
_toolchain_libraries = attr.label(
674-
default = Label("@rules_haskell//haskell:toolchain-libraries"),
675-
),
676673
),
677674
toolchains = [
678675
"@rules_haskell//haskell:toolchain",

haskell/private/haskell_impl.bzl

+2-152
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Implementation of core Haskell rules"""
22

33
load("@bazel_skylib//lib:dicts.bzl", "dicts")
4-
load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
54
load(
65
":providers.bzl",
76
"C2hsLibraryInfo",
@@ -35,9 +34,7 @@ load(":private/mode.bzl", "is_profiling_enabled")
3534
load(
3635
":private/path_utils.bzl",
3736
"determine_module_names",
38-
"get_dynamic_hs_lib_name",
3937
"get_lib_extension",
40-
"get_static_hs_lib_name",
4138
"infer_main_module",
4239
"match_label",
4340
"parse_pattern",
@@ -795,7 +792,8 @@ def haskell_toolchain_library_impl(ctx):
795792
else:
796793
package = ctx.label.name
797794

798-
libraries = ctx.attr._toolchain_libraries[HaskellToolchainLibraries].libraries
795+
libraries = hs.toolchain.new_libraries.libraries
796+
799797
target = libraries.get(package)
800798

801799
if not target:
@@ -823,154 +821,6 @@ The following toolchain libraries are available:
823821
)),
824822
]
825823

826-
def _toolchain_library_symlink(dynamic_library):
827-
prefix = dynamic_library.owner.workspace_root.replace("_", "_U").replace("/", "_S")
828-
basename = dynamic_library.basename
829-
return paths.join(prefix, basename)
830-
831-
def haskell_toolchain_libraries_impl(ctx):
832-
hs = haskell_context(ctx)
833-
with_profiling = is_profiling_enabled(hs)
834-
with_threaded = "-threaded" in hs.toolchain.ghcopts
835-
836-
cc_toolchain = find_cc_toolchain(ctx)
837-
feature_configuration = cc_common.configure_features(
838-
ctx = ctx,
839-
cc_toolchain = cc_toolchain,
840-
requested_features = ctx.features,
841-
unsupported_features = ctx.disabled_features,
842-
)
843-
844-
libraries = hs.toolchain.libraries
845-
846-
# List of library in left-to-right post-ordering
847-
# Meaning, if package B depends on package A, then A will appear before B.
848-
ordered = depset(transitive = [
849-
target[HaskellImportHack].transitive_depends
850-
for target in hs.toolchain.libraries.values()
851-
])
852-
853-
library_dict = {}
854-
for package in ordered.to_list():
855-
target = libraries[package]
856-
857-
# Construct CcInfo
858-
if with_profiling:
859-
# GHC does not provide dynamic profiling mode libraries. The dynamic
860-
# libraries that are available are missing profiling symbols, that
861-
# other profiling mode build results will reference. Therefore, we
862-
# don't import dynamic libraries in profiling mode.
863-
libs = {
864-
get_static_hs_lib_name(hs.toolchain.version, lib): {"static": lib}
865-
for lib in target[HaskellImportHack].static_profiling_libraries.to_list()
866-
}
867-
else:
868-
# Workaround for https://github.com/tweag/rules_haskell/issues/881
869-
# Static and dynamic libraries don't necessarily pair up 1 to 1.
870-
# E.g. the rts package in the Unix GHC bindist contains the
871-
# dynamic libHSrts and the static libCffi and libHSrts.
872-
libs = {}
873-
for lib in target[HaskellImportHack].dynamic_libraries.to_list():
874-
libname = get_dynamic_hs_lib_name(hs.toolchain.version, lib)
875-
if libname == "ffi" and libname in libs:
876-
# Make sure that the file of libffi matching its soname
877-
# ends up in target runfiles. Otherwise, execution will
878-
# fail with "cannot open shared object file" errors.
879-
# On Linux libffi comes in three shapes:
880-
# libffi.so, libffi.so.7, libffi.so.7.1.0
881-
# (version numbers may vary)
882-
# The soname is then libffi.so.7, meaning, at runtime the
883-
# dynamic linker will look for libffi.so.7. So, that file
884-
# should be the LibraryToLink.dynamic_library.
885-
ext_components = get_lib_extension(lib).split(".")
886-
if len(ext_components) == 2 and ext_components[0] == "so":
887-
libs[libname]["dynamic"] = lib
888-
else:
889-
libs[libname] = {"dynamic": lib}
890-
for lib in target[HaskellImportHack].static_libraries.to_list():
891-
name = get_static_hs_lib_name(with_profiling, lib)
892-
entry = libs.get(name, {})
893-
entry["static"] = lib
894-
libs[name] = entry
895-
896-
# Avoid duplicate runtime and ffi libraries. These libraries come
897-
# in threaded and non-threaded flavors. Depending on the
898-
# compilation mode we want to forward only one or the other.
899-
# XXX: Threaded mode should be a per-target property. Use Bazel
900-
# build configurations and transitions to select the threaded or
901-
# non-threaded runtime and ffi on a per-target basis.
902-
if "HSrts_thr" in libs:
903-
if with_threaded:
904-
libs["HSrts"] = libs["HSrts_thr"]
905-
libs.pop("HSrts_thr")
906-
if "Cffi_thr" in libs:
907-
if with_threaded:
908-
libs["ffi"]["static"] = libs["Cffi_thr"]["static"]
909-
libs.pop("Cffi_thr")
910-
linker_inputs = [
911-
cc_common.create_linker_input(
912-
owner = ctx.label,
913-
libraries = depset(direct = [
914-
cc_common.create_library_to_link(
915-
actions = ctx.actions,
916-
feature_configuration = feature_configuration,
917-
dynamic_library = lib.get("dynamic", None),
918-
dynamic_library_symlink_path =
919-
_toolchain_library_symlink(lib["dynamic"]) if lib.get("dynamic") else "",
920-
static_library = lib.get("static", None),
921-
cc_toolchain = cc_toolchain,
922-
)
923-
for lib in libs.values()
924-
]),
925-
user_link_flags = depset(direct = target[HaskellImportHack].linkopts),
926-
),
927-
]
928-
compilation_context = cc_common.create_compilation_context(
929-
headers = target[HaskellImportHack].headers,
930-
includes = target[HaskellImportHack].includes,
931-
)
932-
linking_context = cc_common.create_linking_context(
933-
linker_inputs = depset(direct = linker_inputs),
934-
)
935-
cc_info = CcInfo(
936-
compilation_context = compilation_context,
937-
linking_context = linking_context,
938-
)
939-
library_dict[package] = struct(
940-
default_info = target[DefaultInfo],
941-
hs_info = target[HaskellInfo],
942-
hs_lib_info = target[HaskellLibraryInfo],
943-
cc_info = cc_common.merge_cc_infos(cc_infos = [cc_info] + [
944-
library_dict[dep].cc_info
945-
for dep in target[HaskellImportHack].depends
946-
]),
947-
haddock_info = target[HaddockInfo],
948-
)
949-
950-
return [HaskellToolchainLibraries(libraries = library_dict)]
951-
952-
haskell_toolchain_libraries = rule(
953-
haskell_toolchain_libraries_impl,
954-
attrs = {
955-
"_cc_toolchain": attr.label(
956-
default = Label("@rules_cc//cc:current_cc_toolchain"),
957-
),
958-
},
959-
toolchains = use_cc_toolchain() + [
960-
"@rules_haskell//haskell:toolchain",
961-
],
962-
fragments = ["cpp"],
963-
)
964-
"""Generate Haskell toolchain libraries.
965-
966-
This is an internal rule and should not be user facing.
967-
968-
This rule is a work-around for toolchain transitions not being implemented,
969-
yet. See
970-
https://github.com/bazelbuild/proposals/blob/master/designs/2019-02-12-toolchain-transitions.md
971-
This will need to be revisited once that proposal is implemented.
972-
"""
973-
974824
def haskell_import_impl(ctx):
975825
# The `allow_files` attribute of `rule` cannot define patterns of accepted
976826
# file extensions like `.so.*`. Instead, we check for the correct file

0 commit comments

Comments
 (0)