Skip to content

Commit

Permalink
Merge branch 'master' into release-0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Xophmeister committed Dec 20, 2021
2 parents 82bf399 + 2630f83 commit b37aa57
Show file tree
Hide file tree
Showing 9 changed files with 867 additions and 18 deletions.
358 changes: 358 additions & 0 deletions haskell/assets/ghc_9_0_1_win.patch

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions haskell/assets/ghc_9_2_1_mac.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- Makefile 2021-12-14 12:24:30.857292020 +0000
+++ Makefile 2021-12-14 12:24:44.637400564 +0000
@@ -201,7 +201,7 @@ update_package_db: install_bin install_lib
@echo "$(PKG_CONFS)"
@echo "Updating the package DB"
$(foreach p, $(PKG_CONFS),\
- $(call patchpackageconf,$(shell echo $(notdir $p) | sed 's/-\([0-9]*[0-9]\.\)*conf//g'),$(shell echo "$p" | sed 's:xxx: :g'),$(docdir),$(shell realpath --relative-to="$(ActualLibsDir)" "$(docdir)")))
+ $(call patchpackageconf,$(shell echo $(notdir $p) | sed 's/-\([0-9]*[0-9]\.\)*conf//g'),$(shell echo "$p" | sed 's:xxx: :g'),$(docdir),$(shell mk/relpath.sh "$(ActualLibsDir)" "$(docdir)")))
'$(WrapperBinsDir)/ghc-pkg' recache

install_mingw:
358 changes: 358 additions & 0 deletions haskell/assets/ghc_9_2_1_win.patch

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions haskell/assets/relpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh

# POSIX shell implementation of `realpath --relative-to=$1 $2.
# This is an adaptation of the implementation from
# <https://github.com/Offirmo/offirmo-shell-lib>.

# returns relative path to $2=$target from $1=$source
## NOTE : path are compared in text only. They don’t have to exist
## and they WONT be normalized/escaped
## Result in "$return_value"# both $1 and $2 are absolute paths beginning with /

src="$1"
target="$2"

common_part="$src"
result=""

while test "${target#$common_part}" = "${target}" ; do
#echo "common_part is now : \"$common_part\""
#echo "result is now : \"$result\""
#echo "target#common_part : \"${target#$common_part}\""
# no match, means that candidate common part is not correct
# go up one level (reduce common part)
common_part="$(dirname "$common_part")"
# and record that we went back
if test -z "$result" ; then
result=".."
else
result="../$result"
fi
done

#echo "common_part is : \"$common_part\""

if test "$common_part" = "/" ; then
# special case for root (no common path)
result="$result/"
fi

# since we now have identified the common part,
# compute the non-common part
forward_part="${target#$common_part}"
#echo "forward_part = \"$forward_part\""

if test -n "$result" && test -n "$forward_part" ; then
#echo "(simple concat)"
result="$result$forward_part"
elif test -n "$forward_part" ; then
#echo "(concat with slash removal)"
result="$(printf "%s" "$forward_part" | cut -c 1-)"
fi

printf "%s" "$result"
4 changes: 2 additions & 2 deletions haskell/ghc.BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ filegroup(
)

filegroup(
name = "doc",
srcs = glob(["doc/**"]),
name = "%{docdir}",
srcs = glob(["%{docdir}/**"]),
)

# Expose embedded MinGW toolchain when on Windows.
Expand Down
86 changes: 74 additions & 12 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ GHC_BINDIST = \
},
}

GHC_BINDIST_STRIP_PREFIX = \
{
"9.2.1": {
"darwin_amd64": "ghc-9.2.1-x86_64-apple-darwin",
"windows_amd64": "ghc-9.2.1-x86_64-unknown-mingw32",
},
"9.0.1": {
"windows_amd64": "ghc-9.0.1-x86_64-unknown-mingw32",
},
}

GHC_BINDIST_LIBDIR = \
{
"9.2.1": {
"darwin_amd64": "lib/lib",
},
}

GHC_BINDIST_DOCDIR = \
{
"9.2.1": {
"windows_amd64": "docs",
},
"9.0.1": {
"windows_amd64": "docs",
},
}

def _ghc_bindist_impl(ctx):
filepaths = resolve_labels(ctx, [
"@rules_haskell//haskell:ghc.BUILD.tpl",
Expand All @@ -362,12 +390,16 @@ def _ghc_bindist_impl(ctx):
# the raw distribution.
unpack_dir = "bindist_unpacked" if os != "windows" else ""

stripPrefix = "ghc-" + version
if GHC_BINDIST_STRIP_PREFIX.get(version) != None and GHC_BINDIST_STRIP_PREFIX[version].get(target) != None:
stripPrefix = GHC_BINDIST_STRIP_PREFIX[version][target]

ctx.download_and_extract(
url = url,
output = unpack_dir,
sha256 = sha256,
type = "tar.xz",
stripPrefix = "ghc-" + version,
stripPrefix = stripPrefix,
)

if os == "windows":
Expand Down Expand Up @@ -411,6 +443,13 @@ def _ghc_bindist_impl(ctx):
make_loc = ctx.which("make")
if not make_loc:
fail("It looks like the build-essential package might be missing, because there is no make in PATH. Are the required dependencies installed? https://rules-haskell.readthedocs.io/en/latest/haskell.html#before-you-begin")

if version == "9.2.1":
# Necessary for deterministic builds on macOS. See
# https://gitlab.haskell.org/ghc/ghc/-/issues/19963
ctx.file("{}/mk/relpath.sh".format(unpack_dir), ctx.read(ctx.path(ctx.attr._relpath_script)), executable = False, legacy_utf8 = False)
execute_or_fail_loudly(ctx, ["chmod", "+x", "mk/relpath.sh"], working_directory = unpack_dir)

execute_or_fail_loudly(
ctx,
["make", "install"],
Expand Down Expand Up @@ -443,7 +482,15 @@ rm -f
if len(ctx.attr.patches) > 0:
execute_or_fail_loudly(ctx, ["./bin/ghc-pkg", "recache"])

toolchain_libraries = pkgdb_to_bzl(ctx, filepaths, "lib")
libdir = "lib"
if GHC_BINDIST_LIBDIR.get(version) != None and GHC_BINDIST_LIBDIR[version].get(target) != None:
libdir = GHC_BINDIST_LIBDIR[version][target]

docdir = "doc"
if GHC_BINDIST_DOCDIR.get(version) != None and GHC_BINDIST_DOCDIR[version].get(target) != None:
docdir = GHC_BINDIST_DOCDIR[version][target]

toolchain_libraries = pkgdb_to_bzl(ctx, filepaths, libdir)
locale = ctx.attr.locale or ("en_US.UTF-8" if os == "darwin" else "C.UTF-8")
toolchain = define_rule(
"haskell_toolchain",
Expand All @@ -452,7 +499,7 @@ rm -f
libraries = "toolchain_libraries",
# See Note [GHC toolchain files]
libdir = [":lib"],
docdir = [":doc"],
docdir = [":{}".format(docdir)],
version = repr(ctx.attr.version),
static_runtime = os == "windows",
fully_static_link = False, # XXX not yet supported for bindists.
Expand All @@ -468,6 +515,7 @@ rm -f
substitutions = {
"%{toolchain_libraries}": toolchain_libraries,
"%{toolchain}": toolchain,
"%{docdir}": docdir,
},
executable = False,
)
Expand Down Expand Up @@ -507,6 +555,10 @@ _ghc_bindist = repository_rule(
"locale": attr.string(
mandatory = False,
),
"_relpath_script": attr.label(
allow_single_file = True,
default = Label("@rules_haskell//haskell:assets/relpath.sh"),
),
},
)

Expand Down Expand Up @@ -604,15 +656,25 @@ def ghc_bindist(
# Recent GHC versions on Windows contain a bug:
# https://gitlab.haskell.org/ghc/ghc/issues/16466
# We work around this by patching the base configuration.
patches = {
"8.6.2": ["@rules_haskell//haskell:assets/ghc_8_6_2_win_base.patch"],
"8.6.4": ["@rules_haskell//haskell:assets/ghc_8_6_4_win_base.patch"],
"8.6.5": ["@rules_haskell//haskell:assets/ghc_8_6_5_win_base.patch"],
"8.8.1": ["@rules_haskell//haskell:assets/ghc_8_8_1_win_base.patch"],
"8.8.2": ["@rules_haskell//haskell:assets/ghc_8_8_2_win_base.patch"],
"8.8.3": ["@rules_haskell//haskell:assets/ghc_8_8_3_win_base.patch"],
"8.8.4": ["@rules_haskell//haskell:assets/ghc_8_8_4_win_base.patch"],
}.get(version) if target == "windows_amd64" else None
patches = None
if target == "windows_amd64":
patches = {
"8.6.2": ["@rules_haskell//haskell:assets/ghc_8_6_2_win_base.patch"],
"8.6.4": ["@rules_haskell//haskell:assets/ghc_8_6_4_win_base.patch"],
"8.6.5": ["@rules_haskell//haskell:assets/ghc_8_6_5_win_base.patch"],
"8.8.1": ["@rules_haskell//haskell:assets/ghc_8_8_1_win_base.patch"],
"8.8.2": ["@rules_haskell//haskell:assets/ghc_8_8_2_win_base.patch"],
"8.8.3": ["@rules_haskell//haskell:assets/ghc_8_8_3_win_base.patch"],
"8.8.4": ["@rules_haskell//haskell:assets/ghc_8_8_4_win_base.patch"],
"9.0.1": ["@rules_haskell//haskell:assets/ghc_9_0_1_win.patch"],
"9.2.1": ["@rules_haskell//haskell:assets/ghc_9_2_1_win.patch"],
}.get(version)

if target == "darwin_amd64":
patches = {
# Patch for https://gitlab.haskell.org/ghc/ghc/-/issues/19963
"9.2.1": ["@rules_haskell//haskell:assets/ghc_9_2_1_mac.patch"],
}.get(version)

extra_attrs = {"patches": patches, "patch_args": ["-p0"]} if patches else {}

Expand Down
6 changes: 4 additions & 2 deletions haskell/private/cabal_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ def distdir_prefix():
# 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 []
enable_relocatable_flags = []
if not is_windows and json_args["ghc_version"] != None and json_args["ghc_version"] < [9,2,1]:
# ToDo: not work relocatable from Cabal-3.6.0.0 buildin GHC 9.2.1
enable_relocatable_flags = ["--enable-relocatable"]

# Cabal really wants the current working directory to be directory
# where the .cabal file is located. So we have no choice but to chance
Expand Down
3 changes: 3 additions & 0 deletions haskell/private/pkgdb_to_bzl.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def unfold_fields(content):

def path_to_label(path, pkgroot):
"""Substitute one pkgroot for another relative one to obtain a label."""
if path.find("${pkgroot}") != -1:
return os.path.normpath(path.strip("\"").replace("${pkgroot}", topdir)).replace('\\', '/')

topdir_relative_path = path.replace(pkgroot, "$topdir")
if topdir_relative_path.find("$topdir") != -1:
return os.path.normpath(topdir_relative_path.replace("$topdir", topdir)).replace('\\', '/')
Expand Down
6 changes: 4 additions & 2 deletions haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ def _haskell_toolchain_impl(ctx):
if ctx.attr.docdir_path:
docdir_path = ctx.attr.docdir_path
elif docdir:
docdir_path = None

# Find a file matching `html/libraries/base-*.*.*.*/*` and infer `docdir` from its path.
# `GHC.Paths.docdir` reports paths such as `.../doc/html/libraries/base-4.13.0.0`.
for f in docdir:
html_start = f.path.find("html/libraries/base-")
html_start = f.path.find("html/libraries/base")
if html_start != -1:
base_end = f.path.find("/", html_start + len("html/libraries/base-"))
base_end = f.path.find("/", html_start + len("html/libraries/base"))
if base_end != -1:
docdir_path = f.path[:base_end]
break
Expand Down

0 comments on commit b37aa57

Please sign in to comment.