|
1 | 1 | """Implementation of core Haskell rules"""
|
2 | 2 |
|
3 | 3 | load("@bazel_skylib//lib:dicts.bzl", "dicts")
|
4 |
| -load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain") |
5 | 4 | load(
|
6 | 5 | ":providers.bzl",
|
7 | 6 | "C2hsLibraryInfo",
|
@@ -35,9 +34,7 @@ load(":private/mode.bzl", "is_profiling_enabled")
|
35 | 34 | load(
|
36 | 35 | ":private/path_utils.bzl",
|
37 | 36 | "determine_module_names",
|
38 |
| - "get_dynamic_hs_lib_name", |
39 | 37 | "get_lib_extension",
|
40 |
| - "get_static_hs_lib_name", |
41 | 38 | "infer_main_module",
|
42 | 39 | "match_label",
|
43 | 40 | "parse_pattern",
|
@@ -795,7 +792,8 @@ def haskell_toolchain_library_impl(ctx):
|
795 | 792 | else:
|
796 | 793 | package = ctx.label.name
|
797 | 794 |
|
798 |
| - libraries = ctx.attr._toolchain_libraries[HaskellToolchainLibraries].libraries |
| 795 | + libraries = hs.toolchain.new_libraries.libraries |
| 796 | + |
799 | 797 | target = libraries.get(package)
|
800 | 798 |
|
801 | 799 | if not target:
|
@@ -823,154 +821,6 @@ The following toolchain libraries are available:
|
823 | 821 | )),
|
824 | 822 | ]
|
825 | 823 |
|
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 |
| - |
974 | 824 | def haskell_import_impl(ctx):
|
975 | 825 | # The `allow_files` attribute of `rule` cannot define patterns of accepted
|
976 | 826 | # file extensions like `.so.*`. Instead, we check for the correct file
|
|
0 commit comments