Skip to content

Commit b37aa57

Browse files
committed
Merge branch 'master' into release-0.14
2 parents 82bf399 + 2630f83 commit b37aa57

9 files changed

+867
-18
lines changed

haskell/assets/ghc_9_0_1_win.patch

+358
Large diffs are not rendered by default.

haskell/assets/ghc_9_2_1_mac.patch

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- Makefile 2021-12-14 12:24:30.857292020 +0000
2+
+++ Makefile 2021-12-14 12:24:44.637400564 +0000
3+
@@ -201,7 +201,7 @@ update_package_db: install_bin install_lib
4+
@echo "$(PKG_CONFS)"
5+
@echo "Updating the package DB"
6+
$(foreach p, $(PKG_CONFS),\
7+
- $(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)")))
8+
+ $(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)")))
9+
'$(WrapperBinsDir)/ghc-pkg' recache
10+
11+
install_mingw:

haskell/assets/ghc_9_2_1_win.patch

+358
Large diffs are not rendered by default.

haskell/assets/relpath.sh

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
# POSIX shell implementation of `realpath --relative-to=$1 $2.
4+
# This is an adaptation of the implementation from
5+
# <https://github.com/Offirmo/offirmo-shell-lib>.
6+
7+
# returns relative path to $2=$target from $1=$source
8+
## NOTE : path are compared in text only. They don’t have to exist
9+
## and they WONT be normalized/escaped
10+
## Result in "$return_value"# both $1 and $2 are absolute paths beginning with /
11+
12+
src="$1"
13+
target="$2"
14+
15+
common_part="$src"
16+
result=""
17+
18+
while test "${target#$common_part}" = "${target}" ; do
19+
#echo "common_part is now : \"$common_part\""
20+
#echo "result is now : \"$result\""
21+
#echo "target#common_part : \"${target#$common_part}\""
22+
# no match, means that candidate common part is not correct
23+
# go up one level (reduce common part)
24+
common_part="$(dirname "$common_part")"
25+
# and record that we went back
26+
if test -z "$result" ; then
27+
result=".."
28+
else
29+
result="../$result"
30+
fi
31+
done
32+
33+
#echo "common_part is : \"$common_part\""
34+
35+
if test "$common_part" = "/" ; then
36+
# special case for root (no common path)
37+
result="$result/"
38+
fi
39+
40+
# since we now have identified the common part,
41+
# compute the non-common part
42+
forward_part="${target#$common_part}"
43+
#echo "forward_part = \"$forward_part\""
44+
45+
if test -n "$result" && test -n "$forward_part" ; then
46+
#echo "(simple concat)"
47+
result="$result$forward_part"
48+
elif test -n "$forward_part" ; then
49+
#echo "(concat with slash removal)"
50+
result="$(printf "%s" "$forward_part" | cut -c 1-)"
51+
fi
52+
53+
printf "%s" "$result"

haskell/ghc.BUILD.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ filegroup(
3030
)
3131

3232
filegroup(
33-
name = "doc",
34-
srcs = glob(["doc/**"]),
33+
name = "%{docdir}",
34+
srcs = glob(["%{docdir}/**"]),
3535
)
3636

3737
# Expose embedded MinGW toolchain when on Windows.

haskell/ghc_bindist.bzl

+74-12
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,34 @@ GHC_BINDIST = \
338338
},
339339
}
340340

341+
GHC_BINDIST_STRIP_PREFIX = \
342+
{
343+
"9.2.1": {
344+
"darwin_amd64": "ghc-9.2.1-x86_64-apple-darwin",
345+
"windows_amd64": "ghc-9.2.1-x86_64-unknown-mingw32",
346+
},
347+
"9.0.1": {
348+
"windows_amd64": "ghc-9.0.1-x86_64-unknown-mingw32",
349+
},
350+
}
351+
352+
GHC_BINDIST_LIBDIR = \
353+
{
354+
"9.2.1": {
355+
"darwin_amd64": "lib/lib",
356+
},
357+
}
358+
359+
GHC_BINDIST_DOCDIR = \
360+
{
361+
"9.2.1": {
362+
"windows_amd64": "docs",
363+
},
364+
"9.0.1": {
365+
"windows_amd64": "docs",
366+
},
367+
}
368+
341369
def _ghc_bindist_impl(ctx):
342370
filepaths = resolve_labels(ctx, [
343371
"@rules_haskell//haskell:ghc.BUILD.tpl",
@@ -362,12 +390,16 @@ def _ghc_bindist_impl(ctx):
362390
# the raw distribution.
363391
unpack_dir = "bindist_unpacked" if os != "windows" else ""
364392

393+
stripPrefix = "ghc-" + version
394+
if GHC_BINDIST_STRIP_PREFIX.get(version) != None and GHC_BINDIST_STRIP_PREFIX[version].get(target) != None:
395+
stripPrefix = GHC_BINDIST_STRIP_PREFIX[version][target]
396+
365397
ctx.download_and_extract(
366398
url = url,
367399
output = unpack_dir,
368400
sha256 = sha256,
369401
type = "tar.xz",
370-
stripPrefix = "ghc-" + version,
402+
stripPrefix = stripPrefix,
371403
)
372404

373405
if os == "windows":
@@ -411,6 +443,13 @@ def _ghc_bindist_impl(ctx):
411443
make_loc = ctx.which("make")
412444
if not make_loc:
413445
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")
446+
447+
if version == "9.2.1":
448+
# Necessary for deterministic builds on macOS. See
449+
# https://gitlab.haskell.org/ghc/ghc/-/issues/19963
450+
ctx.file("{}/mk/relpath.sh".format(unpack_dir), ctx.read(ctx.path(ctx.attr._relpath_script)), executable = False, legacy_utf8 = False)
451+
execute_or_fail_loudly(ctx, ["chmod", "+x", "mk/relpath.sh"], working_directory = unpack_dir)
452+
414453
execute_or_fail_loudly(
415454
ctx,
416455
["make", "install"],
@@ -443,7 +482,15 @@ rm -f
443482
if len(ctx.attr.patches) > 0:
444483
execute_or_fail_loudly(ctx, ["./bin/ghc-pkg", "recache"])
445484

446-
toolchain_libraries = pkgdb_to_bzl(ctx, filepaths, "lib")
485+
libdir = "lib"
486+
if GHC_BINDIST_LIBDIR.get(version) != None and GHC_BINDIST_LIBDIR[version].get(target) != None:
487+
libdir = GHC_BINDIST_LIBDIR[version][target]
488+
489+
docdir = "doc"
490+
if GHC_BINDIST_DOCDIR.get(version) != None and GHC_BINDIST_DOCDIR[version].get(target) != None:
491+
docdir = GHC_BINDIST_DOCDIR[version][target]
492+
493+
toolchain_libraries = pkgdb_to_bzl(ctx, filepaths, libdir)
447494
locale = ctx.attr.locale or ("en_US.UTF-8" if os == "darwin" else "C.UTF-8")
448495
toolchain = define_rule(
449496
"haskell_toolchain",
@@ -452,7 +499,7 @@ rm -f
452499
libraries = "toolchain_libraries",
453500
# See Note [GHC toolchain files]
454501
libdir = [":lib"],
455-
docdir = [":doc"],
502+
docdir = [":{}".format(docdir)],
456503
version = repr(ctx.attr.version),
457504
static_runtime = os == "windows",
458505
fully_static_link = False, # XXX not yet supported for bindists.
@@ -468,6 +515,7 @@ rm -f
468515
substitutions = {
469516
"%{toolchain_libraries}": toolchain_libraries,
470517
"%{toolchain}": toolchain,
518+
"%{docdir}": docdir,
471519
},
472520
executable = False,
473521
)
@@ -507,6 +555,10 @@ _ghc_bindist = repository_rule(
507555
"locale": attr.string(
508556
mandatory = False,
509557
),
558+
"_relpath_script": attr.label(
559+
allow_single_file = True,
560+
default = Label("@rules_haskell//haskell:assets/relpath.sh"),
561+
),
510562
},
511563
)
512564

@@ -604,15 +656,25 @@ def ghc_bindist(
604656
# Recent GHC versions on Windows contain a bug:
605657
# https://gitlab.haskell.org/ghc/ghc/issues/16466
606658
# We work around this by patching the base configuration.
607-
patches = {
608-
"8.6.2": ["@rules_haskell//haskell:assets/ghc_8_6_2_win_base.patch"],
609-
"8.6.4": ["@rules_haskell//haskell:assets/ghc_8_6_4_win_base.patch"],
610-
"8.6.5": ["@rules_haskell//haskell:assets/ghc_8_6_5_win_base.patch"],
611-
"8.8.1": ["@rules_haskell//haskell:assets/ghc_8_8_1_win_base.patch"],
612-
"8.8.2": ["@rules_haskell//haskell:assets/ghc_8_8_2_win_base.patch"],
613-
"8.8.3": ["@rules_haskell//haskell:assets/ghc_8_8_3_win_base.patch"],
614-
"8.8.4": ["@rules_haskell//haskell:assets/ghc_8_8_4_win_base.patch"],
615-
}.get(version) if target == "windows_amd64" else None
659+
patches = None
660+
if target == "windows_amd64":
661+
patches = {
662+
"8.6.2": ["@rules_haskell//haskell:assets/ghc_8_6_2_win_base.patch"],
663+
"8.6.4": ["@rules_haskell//haskell:assets/ghc_8_6_4_win_base.patch"],
664+
"8.6.5": ["@rules_haskell//haskell:assets/ghc_8_6_5_win_base.patch"],
665+
"8.8.1": ["@rules_haskell//haskell:assets/ghc_8_8_1_win_base.patch"],
666+
"8.8.2": ["@rules_haskell//haskell:assets/ghc_8_8_2_win_base.patch"],
667+
"8.8.3": ["@rules_haskell//haskell:assets/ghc_8_8_3_win_base.patch"],
668+
"8.8.4": ["@rules_haskell//haskell:assets/ghc_8_8_4_win_base.patch"],
669+
"9.0.1": ["@rules_haskell//haskell:assets/ghc_9_0_1_win.patch"],
670+
"9.2.1": ["@rules_haskell//haskell:assets/ghc_9_2_1_win.patch"],
671+
}.get(version)
672+
673+
if target == "darwin_amd64":
674+
patches = {
675+
# Patch for https://gitlab.haskell.org/ghc/ghc/-/issues/19963
676+
"9.2.1": ["@rules_haskell//haskell:assets/ghc_9_2_1_mac.patch"],
677+
}.get(version)
616678

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

haskell/private/cabal_wrapper.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ def distdir_prefix():
187187
# into the 'flag hash' field of generated interface files. We try to use a
188188
# reproducible path for the distdir to keep interface files reproducible.
189189
with mkdtemp(distdir_prefix()) as distdir:
190-
enable_relocatable_flags = ["--enable-relocatable"] \
191-
if not is_windows else []
190+
enable_relocatable_flags = []
191+
if not is_windows and json_args["ghc_version"] != None and json_args["ghc_version"] < [9,2,1]:
192+
# ToDo: not work relocatable from Cabal-3.6.0.0 buildin GHC 9.2.1
193+
enable_relocatable_flags = ["--enable-relocatable"]
192194

193195
# Cabal really wants the current working directory to be directory
194196
# where the .cabal file is located. So we have no choice but to chance

haskell/private/pkgdb_to_bzl.py

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def unfold_fields(content):
4343

4444
def path_to_label(path, pkgroot):
4545
"""Substitute one pkgroot for another relative one to obtain a label."""
46+
if path.find("${pkgroot}") != -1:
47+
return os.path.normpath(path.strip("\"").replace("${pkgroot}", topdir)).replace('\\', '/')
48+
4649
topdir_relative_path = path.replace(pkgroot, "$topdir")
4750
if topdir_relative_path.find("$topdir") != -1:
4851
return os.path.normpath(topdir_relative_path.replace("$topdir", topdir)).replace('\\', '/')

haskell/toolchain.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,14 @@ def _haskell_toolchain_impl(ctx):
167167
if ctx.attr.docdir_path:
168168
docdir_path = ctx.attr.docdir_path
169169
elif docdir:
170+
docdir_path = None
171+
170172
# Find a file matching `html/libraries/base-*.*.*.*/*` and infer `docdir` from its path.
171173
# `GHC.Paths.docdir` reports paths such as `.../doc/html/libraries/base-4.13.0.0`.
172174
for f in docdir:
173-
html_start = f.path.find("html/libraries/base-")
175+
html_start = f.path.find("html/libraries/base")
174176
if html_start != -1:
175-
base_end = f.path.find("/", html_start + len("html/libraries/base-"))
177+
base_end = f.path.find("/", html_start + len("html/libraries/base"))
176178
if base_end != -1:
177179
docdir_path = f.path[:base_end]
178180
break

0 commit comments

Comments
 (0)