From 7bcce7c1aab71aa0df87d4d1859eef17b0ece856 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Wed, 26 Jan 2022 10:12:30 +0100 Subject: [PATCH] Upgrade rules-haskell (#12580) Spun out from the GHC 9 upgrade. changelog_begin changelog_end --- bazel_tools/haskell-cabal-reproducible.patch | 86 ------------------- .../haskell-windows-extra-libraries.patch | 8 +- deps.bzl | 7 +- 3 files changed, 6 insertions(+), 95 deletions(-) delete mode 100644 bazel_tools/haskell-cabal-reproducible.patch diff --git a/bazel_tools/haskell-cabal-reproducible.patch b/bazel_tools/haskell-cabal-reproducible.patch deleted file mode 100644 index 7d9a8eceb8d6..000000000000 --- a/bazel_tools/haskell-cabal-reproducible.patch +++ /dev/null @@ -1,86 +0,0 @@ -diff --git a/haskell/private/cabal_wrapper.py b/haskell/private/cabal_wrapper.py -index a01db36e..fc3f8bfc 100755 ---- a/haskell/private/cabal_wrapper.py -+++ b/haskell/private/cabal_wrapper.py -@@ -37,7 +37,9 @@ from __future__ import print_function - - from contextlib import contextmanager - from glob import glob -+import itertools - import json -+import hashlib - import os - import os.path - import re -@@ -134,32 +136,57 @@ def recache_db(): - recache_db() - - @contextmanager --def tmpdir(): -- """This is a reimplementation of `tempfile.TemporaryDirectory` because -- the latter isn't available in python2 -+def mkdtemp(prefix): -+ """Create a temporary directory. -+ -+ This is a context manager that will create the directory on entry and -+ delete it on exit. -+ -+ The directory will be created under the given `prefix` path with an -+ optional suffix to avoid conflict with already existing directories. - """ -+ candidates = itertools.chain([prefix], ("{}_{}".format(prefix, i) for i in itertools.count(1))) -+ for candidate in candidates: -+ dirname = os.path.abspath(candidate) -+ try: -+ os.makedirs(dirname, mode=0o700, exist_ok=False) -+ break -+ except FileExistsError: -+ pass -+ try: -+ yield dirname -+ finally: -+ shutil.rmtree(dirname, ignore_errors = True) -+ -+def distdir_prefix(): - # Build into a sibling path of the final binary output location. - # This is to ensure that relative `RUNPATH`s are valid in the intermediate - # output in the `--builddir` as well as in the final output in `--bindir`. - # Executables are placed into `/build//`. - # Libraries are placed into `/build/`. I.e. there is an - # extra subdirectory for libraries. -- # -- # On Windows we don't do dynamic linking and prefer shorter paths to avoid -- # exceeding `MAX_PATH`. - if is_windows: -- distdir = tempfile.mkdtemp() -+ # On Windows we don't do dynamic linking and prefer shorter paths to -+ # avoid exceeding `MAX_PATH`. -+ distdir_root = tempfile.gettempdir() - else: - if component.startswith("exe:"): -- distdir = tempfile.mkdtemp(dir=os.path.dirname(os.path.dirname(pkgroot))) -+ distdir_root = os.path.dirname(os.path.dirname(pkgroot)) - else: -- distdir = tempfile.mkdtemp(dir=os.path.dirname(pkgroot)) -- try: -- yield distdir -- finally: -- shutil.rmtree(distdir, ignore_errors = True) -+ distdir_root = os.path.dirname(pkgroot) -+ if is_windows: -+ # On Windows we use a fixed length directory name to avoid exceeding -+ # `MAX_PATH` on targets with long names. -+ distdir_name = hashlib.md5(name.encode("utf-8")).hexdigest() -+ else: -+ distdir_name = name -+ return os.path.join(distdir_root, name) - --with tmpdir() as distdir: -+# Build into a temporary distdir that will be cleaned up after the build. The -+# path to this distdir enters into flags that are passed to GHC and thereby -+# into the 'flag hash' field of generated interface files. We try to use a -+# reproducible path for the distdir to keep interface files reproducible. -+with mkdtemp(distdir_prefix()) as distdir: - enable_relocatable_flags = ["--enable-relocatable"] \ - if not is_windows else [] - diff --git a/bazel_tools/haskell-windows-extra-libraries.patch b/bazel_tools/haskell-windows-extra-libraries.patch index b0149e28b23b..e4c5f24ffb37 100644 --- a/bazel_tools/haskell-windows-extra-libraries.patch +++ b/bazel_tools/haskell-windows-extra-libraries.patch @@ -1,10 +1,10 @@ diff --git a/haskell/private/actions/package.bzl b/haskell/private/actions/package.bzl -index bebeaa1a..f8fecb63 100644 +index fddf30fd..564da872 100644 --- a/haskell/private/actions/package.bzl +++ b/haskell/private/actions/package.bzl -@@ -98,7 +98,12 @@ def package( - "library-dirs": ["${pkgroot}"] + extra_lib_dirs, - "dynamic-library-dirs": ["${pkgroot}"] + extra_dynamic_lib_dirs, +@@ -105,7 +105,12 @@ def package( + "library-dirs": [pkgroot_lib_path] + extra_lib_dirs, + "dynamic-library-dirs": [pkgroot_lib_path] + extra_dynamic_lib_dirs, "hs-libraries": [pkg_id.library_name(hs, my_pkg_id)] if has_hs_library else [], - "extra-libraries": extra_libs, + "extra-libraries": extra_libs + ([ diff --git a/deps.bzl b/deps.bzl index acfca68f0146..55c7d3229feb 100644 --- a/deps.bzl +++ b/deps.bzl @@ -33,17 +33,14 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") rules_scala_version = "17791a18aa966cdf2babb004822e6c70a7decc76" rules_scala_sha256 = "a8faef92f59a4f1428ed9a93c7c313a996466a66ad64c119fc49b5c7dea98c59" -rules_haskell_version = "a7241fa64c7cd36462a1f6ac4c660d1247d5e07b" -rules_haskell_sha256 = "9ca581c79dbda507da05ca4c3e958eb5865c9fbc7e393656cdcb8216b20d8821" +rules_haskell_version = "156b091fc1b8d0736ad9f072cdc9abdadacbf57f" +rules_haskell_sha256 = "e3fb9e6da187d0ef79f1e6240325092c011dd1c7db207cd3f3793806642bd2c4" rules_haskell_patches = [ # This is a daml specific patch and not upstreamable. "@com_github_digital_asset_daml//bazel_tools:haskell-windows-extra-libraries.patch", # This should be made configurable in rules_haskell. # Remove this patch once that's available. "@com_github_digital_asset_daml//bazel_tools:haskell-opt.patch", - # This can be removed once the following upstream PR has been merged: - # https://github.com/tweag/rules_haskell/pull/1648 - "@com_github_digital_asset_daml//bazel_tools:haskell-cabal-reproducible.patch", ] rules_nixpkgs_version = "81f61c4b5afcf50665b7073f7fce4c1755b4b9a3" rules_nixpkgs_sha256 = "33fd540d0283cf9956d0a5a640acb1430c81539a84069114beaf9640c96d221a"