Skip to content

Commit

Permalink
Use --always-use-cache with ghc-pkg
Browse files Browse the repository at this point in the history
Summary: This will speed up builds a bit, see the comment.

Reviewed By: IanChilds

Differential Revision: D67206232

fbshipit-source-id: 5e90f6b05f4630883d0e53fd75ced000e9b22375
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Dec 16, 2024
1 parent 59d0523 commit 524b7f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion prelude/haskell/haskell.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ set -eu
GHC_PKG=$1
DB=$2
PKGCONF=$3
ALWAYS_USE_CACHE=$4
"$GHC_PKG" init "$DB"
"$GHC_PKG" register --package-conf "$DB" --no-expand-pkgroot "$PKGCONF"
"$GHC_PKG" register --package-conf "$DB" --no-expand-pkgroot $ALWAYS_USE_CACHE "$PKGCONF"
"""

# Create a package
Expand Down Expand Up @@ -470,6 +471,17 @@ def _make_package(
)

haskell_toolchain = ctx.attrs._haskell_toolchain[HaskellToolchainInfo]

# --always-use-cache is a custom option to ghc-pkg that tells it to ignore the
# modification time on the package cache and use it anyway. This is useful in
# RE where file modification times can't be relied upon; without this option
# ghc-pkg will fall back to reading all the package configs which is much
# slower.
if haskell_toolchain.support_always_use_cache:
use_cache_arg = "--always-use-cache"
else:
use_cache_arg = ""

ctx.actions.run(
cmd_args(
[
Expand All @@ -480,6 +492,7 @@ def _make_package(
haskell_toolchain.packager,
db.as_output(),
pkg_conf,
use_cache_arg,
],
# needs hi, because ghc-pkg checks that the .hi files exist
hidden = hi.values() + lib.values(),
Expand Down
1 change: 1 addition & 0 deletions prelude/haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ HaskellToolchainInfo = provider(
"compiler_major_version": provider_field(typing.Any, default = None),
"package_name_prefix": provider_field(typing.Any, default = None),
"packager": provider_field(typing.Any, default = None),
"support_always_use_cache": provider_field(bool, default = False),
"use_argsfile": provider_field(typing.Any, default = None),
"support_expose_package": provider_field(bool, default = False),
"archive_contents": provider_field(typing.Any, default = None),
Expand Down

0 comments on commit 524b7f8

Please sign in to comment.