Skip to content

Commit

Permalink
Merge pull request #1331 from tweag/coverage
Browse files Browse the repository at this point in the history
Update to GHC 8.8
  • Loading branch information
mergify[bot] authored May 26, 2020
2 parents 5410b89 + e5492ae commit 844f87f
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 56 deletions.
33 changes: 18 additions & 15 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ http_archive(
load("@rules_haskell//haskell:cabal.bzl", "haskell_cabal_binary")
haskell_cabal_binary(name = "happy", srcs = glob(["**"]), visibility = ["//visibility:public"])
""",
sha256 = "22eb606c97105b396e1c7dc27e120ca02025a87f3e44d2ea52be6a653a52caed",
strip_prefix = "happy-1.19.10",
urls = ["http://hackage.haskell.org/package/happy-1.19.10/happy-1.19.10.tar.gz"],
sha256 = "fb9a23e41401711a3b288f93cf0a66db9f97da1ce32ec4fffea4b78a0daeb40f",
strip_prefix = "happy-1.19.12",
urls = ["http://hackage.haskell.org/package/happy-1.19.12/happy-1.19.12.tar.gz"],
)

http_archive(
Expand All @@ -65,11 +65,16 @@ haskell_cabal_binary(
visibility = ["//visibility:public"],
)
""",
sha256 = "161dcee2aed780f62c01522c86afce61721cf89c0143f157efefb1bd1fa1d164",
strip_prefix = "proto-lens-protoc-0.5.0.0",
urls = ["http://hackage.haskell.org/package/proto-lens-protoc-0.5.0.0/proto-lens-protoc-0.5.0.0.tar.gz"],
sha256 = "b946740b94c8d300cd8e278ded9045905ef1985824cef6b81af0d79b119927be",
strip_prefix = "proto-lens-protoc-0.6.0.0",
urls = ["http://hackage.haskell.org/package/proto-lens-protoc-0.6.0.0/proto-lens-protoc-0.6.0.0.tar.gz"],
)

load(
"@rules_haskell//:constants.bzl",
"test_ghc_version",
"test_stack_snapshot",
)
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")

stack_snapshot(
Expand Down Expand Up @@ -99,9 +104,10 @@ stack_snapshot(
"data-default-class",
"proto-lens",
"proto-lens-protoc",
"proto-lens-runtime",
"lens-family",
],
snapshot = "lts-14.4",
snapshot = test_stack_snapshot,
tools = [
"@alex",
"@happy",
Expand All @@ -113,7 +119,7 @@ stack_snapshot(
name = "stackage-zlib",
extra_deps = {"zlib": ["@zlib.win//:zlib" if is_windows else "@zlib.dev//:zlib"]},
packages = ["zlib"],
snapshot = "lts-13.15",
snapshot = test_stack_snapshot,
)

load(
Expand Down Expand Up @@ -165,20 +171,17 @@ test_repl_ghci_args = [
"-XOverloadedStrings",
]

load(
"@rules_haskell//:constants.bzl",
"test_ghc_version",
)
load(
"@rules_haskell//haskell:nixpkgs.bzl",
"haskell_register_ghc_nixpkgs",
)

haskell_register_ghc_nixpkgs(
attribute_path = "haskell.compiler.ghc865",
attribute_path = "",
compiler_flags = test_compiler_flags,
haddock_flags = test_haddock_flags,
locale_archive = "@glibc_locales//:locale-archive",
nix_file_content = """with import <nixpkgs> {}; haskell.packages.ghc883.ghc""",
repl_ghci_args = test_repl_ghci_args,
repository = "@nixpkgs_default",
version = test_ghc_version,
Expand Down Expand Up @@ -232,13 +235,13 @@ cc_library(

nixpkgs_package(
name = "c2hs",
attribute_path = "haskell.packages.ghc865.c2hs",
attribute_path = "haskell.packages.ghc883.c2hs",
repository = "@nixpkgs_default",
)

nixpkgs_package(
name = "doctest",
attribute_path = "haskell.packages.ghc865.doctest",
attribute_path = "haskell.packages.ghc883.doctest",
repository = "@nixpkgs_default",
)

Expand Down
18 changes: 17 additions & 1 deletion constants.bzl
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
test_ghc_version = "8.6.5"
load("@os_info//:os_info.bzl", "is_linux", "is_nix_shell", "is_windows")

# Windows builds fail with the following error on CI
#
# Access violation in generated code when writing 0x0
#
# Attempting to reconstruct a stack trace...
#
# Frame Code address
# * 0x461dab0 0x37f7b66 C:\users\vssadministrator\_bazel_vssadministrator\w3d6ug6o\execroot\rules_haskell\external\rules_haskell_ghc_windows_amd64\bin\ghc.exe+0x33f7b66
# * 0x461dab8 0x3277bb9 C:\users\vssadministrator\_bazel_vssadministrator\w3d6ug6o\execroot\rules_haskell\external\rules_haskell_ghc_windows_amd64\bin\ghc.exe+0x2e77bb9
# * 0x461dac0 0x3
#
# This seems to be an instance of https://gitlab.haskell.org/ghc/ghc/issues/17926.
# Until a fix is released we fall back to an older GHC release on Windows.
test_ghc_version = "8.8.3" if not is_windows else "8.6.5"
test_stack_snapshot = "lts-15.4" if not is_windows else "lts-14.4"
1 change: 1 addition & 0 deletions haskell/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bzl_library(
"@bazel_skylib//lib:dicts",
"@bazel_skylib//lib:paths",
"@bazel_skylib//lib:shell",
"@bazel_skylib//lib:versions",
"@io_tweag_rules_nixpkgs//nixpkgs",
"@rules_sh//sh:posix",
],
Expand Down
11 changes: 11 additions & 0 deletions haskell/assets/ghc_8_8_1_win_base.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- lib/package.conf.d/base-4.13.0.0.conf 2020-05-15 18:12:39.720103041 +0200
+++ lib/package.conf.d/base-4.13.0.0.conf 2020-05-15 18:12:33.996061352 +0200
@@ -83,7 +83,7 @@
dynamic-library-dirs: $topdir\base-4.13.0.0
data-dir: $topdir\x86_64-windows-ghc-8.8.1\base-4.13.0.0
hs-libraries: HSbase-4.13.0.0
-extra-libraries: wsock32 user32 shell32 msvcrt mingw32 mingwex
+extra-libraries: wsock32 user32 shell32 msvcrt mingw32 mingwex shlwapi
include-dirs: $topdir\base-4.13.0.0\include
includes: HsBase.h
depends: ghc-prim-0.5.3 integer-gmp-1.0.2.0 rts
11 changes: 11 additions & 0 deletions haskell/assets/ghc_8_8_2_win_base.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- lib/package.conf.d/base-4.13.0.0.conf 2020-05-15 18:14:01.100696756 +0200
+++ lib/package.conf.d/base-4.13.0.0.conf 2020-05-15 18:13:58.168675334 +0200
@@ -83,7 +83,7 @@
dynamic-library-dirs: $topdir\base-4.13.0.0
data-dir: $topdir\x86_64-windows-ghc-8.8.2\base-4.13.0.0
hs-libraries: HSbase-4.13.0.0
-extra-libraries: wsock32 user32 shell32 msvcrt mingw32 mingwex
+extra-libraries: wsock32 user32 shell32 msvcrt mingw32 mingwex shlwapi
include-dirs: $topdir\base-4.13.0.0\include
includes: HsBase.h
depends: ghc-prim-0.5.3 integer-gmp-1.0.2.0 rts
11 changes: 11 additions & 0 deletions haskell/assets/ghc_8_8_3_win_base.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- lib/package.conf.d/base-4.13.0.0.conf 2020-05-15 18:14:57.233107286 +0200
+++ lib/package.conf.d/base-4.13.0.0.conf 2020-05-15 18:14:55.009091007 +0200
@@ -83,7 +83,7 @@
dynamic-library-dirs: $topdir\base-4.13.0.0
data-dir: $topdir\x86_64-windows-ghc-8.8.3\base-4.13.0.0
hs-libraries: HSbase-4.13.0.0
-extra-libraries: wsock32 user32 shell32 msvcrt mingw32 mingwex
+extra-libraries: wsock32 user32 shell32 msvcrt mingw32 mingwex shlwapi
include-dirs: $topdir\base-4.13.0.0\include
includes: HsBase.h
depends: ghc-prim-0.5.3 integer-gmp-1.0.2.0 rts
17 changes: 11 additions & 6 deletions haskell/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,27 @@ def ghc_cc_program_args(cc):
Returns:
list of string, GHC arguments.
"""
return [
args = [
# GHC uses C compiler for assemly, linking and preprocessing as well.
"-pgma",
cc,
"-pgmc",
cc,
"-pgml",
cc,
"-pgmP",
cc,
# Setting -pgm* flags explicitly has the unfortunate side effect
# of resetting any program flags in the GHC settings file. So we
# restore them here. See
# https://ghc.haskell.org/trac/ghc/ticket/7929.
#
# Since GHC 8.8 the semantics of `-optP` have changed and these flags
# are now also forwarded to `cc` via `-Xpreprocessor`, which breaks the
# default flags `-E -undef -traditional`. GHC happens to word split the
# argument to `-pgmP` which allows to pass these flags to `gcc` itself
# as the preprocessor. See
# https://gitlab.haskell.org/ghc/ghc/issues/17185#note_261599.
"-pgmP",
cc + " -E -undef -traditional",
"-optc-fno-stack-protector",
"-optP-E",
"-optP-undef",
"-optP-traditional",
]
return args
3 changes: 3 additions & 0 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ def ghc_bindist(
"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"],
}.get(version) if target == "windows_amd64" else None

extra_attrs = {"patches": patches, "patch_args": ["-p0"]} if patches else {}
Expand Down
56 changes: 50 additions & 6 deletions haskell/private/cc_wrapper.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ used to avoid command line length limitations.
gcc's --print-file-name feature to work around this mismatch in file
extension.
- Corrects instances of `-Xpreprocessor @rsp`.
Starting from version 8.8 GHC forwards `-optP` flags to `cc` prefixed by
`-Xpreprocessor`, including response file arguments. `gcc` will then inline
the contents of the response file into its own command-line without
prefixing each argument with `-Xpreprocessor` which will wrongly pass
preprocessor arguments to cpp itself. This wrapper corrects this by loading
the response file and prefixing each argument with `-Xpreprocessor`.
See https://gitlab.haskell.org/ghc/ghc/issues/17185.
"""

from bazel_tools.tools.python.runfiles import runfiles as bazel_runfiles
Expand Down Expand Up @@ -165,7 +176,9 @@ class Args:
# reference to the list of arguments to forward. The handler must
# return True if it consumes the argument, and return False if
# another handler should consume the argument.
if self._handle_output(arg, args, out):
if self._handle_xpreprocessor(arg, args, out):
pass
elif self._handle_output(arg, args, out):
pass
elif self._handle_include_path(arg, args, out):
pass
Expand All @@ -185,6 +198,14 @@ class Args:
for out_arg in out:
yield out_arg

def _handle_xpreprocessor(self, arg, args, out):
consumed, cpp_arg = argument(arg, args, long = "-Xpreprocessor")

if consumed:
out.extend(["-Xpreprocessor", cpp_arg])

return consumed

def _handle_output(self, arg, args, out):
consumed, output = argument(arg, args, short = "-o")

Expand Down Expand Up @@ -362,29 +383,52 @@ def argument(arg, args, short = None, long = None):
return False, None


def load_response_files(args):
def load_response_files(args, max_depth=100):
"""Generator that loads arguments from response files.
Passes through any regular arguments.
Recursively loads arguments from response files. I.e. if a response file
points to another response file that will be followed recursively up to
`max_depth`.
Args:
args: Iterable of arguments.
max_depth: Maximum response file nesting depth.
Yields:
All arguments, with response files replaced by their contained arguments.
"""
def response_file_iter(filename):
if max_depth == 0:
raise RuntimeError("Exceeded maximum response file nesting depth.")
with open(filename, "r") as rsp:
rsp_args = (
arg
for line in rsp
for arg in parse_response_line(line)
)
for arg in load_response_files(rsp_args, max_depth - 1):
yield arg
args = iter(args)
for arg in args:
if arg == "-install_name":
# macOS only: The install_name may start with an '@' character.
yield arg
yield next(args)
elif arg == "-Xpreprocessor":
cpp_arg = next(args)
if cpp_arg.startswith("@"):
for rsp_arg in response_file_iter(cpp_arg[1:]):
yield "-Xpreprocessor"
yield rsp_arg
else:
yield arg
yield cpp_arg
elif arg.startswith("@"):
with open(arg[1:], "r") as rsp:
for line in rsp:
for rsp_arg in parse_response_line(line):
yield rsp_arg
for rsp_arg in response_file_iter(arg[1:]):
yield rsp_arg
else:
yield arg

Expand Down
28 changes: 24 additions & 4 deletions haskell/private/cc_wrapper_windows.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
# references (..). This can exceed the maximum path length, which
# will cause compiler failures. This wrapper shortens include paths
# to avoid that issue.
#
# - Corrects instances of `-Xpreprocessor @rsp`.
#
# Starting from version 8.8 GHC forwards `-optP` flags to `cc` prefixed by
# `-Xpreprocessor`, including response file arguments. `gcc` will then inline
# the contents of the response file into its own command-line without
# prefixing each argument with `-Xpreprocessor` which will wrongly pass
# preprocessor arguments to cpp itself. This wrapper corrects this by loading
# the response file and prefixing each argument with `-Xpreprocessor`.
#
# See https://gitlab.haskell.org/ghc/ghc/issues/17185

# The runfiles.bash initialization triggers "Can't follow non-constant source".
# Disabling the warning locally is insufficient, so we disable it globally.
Expand Down Expand Up @@ -102,16 +113,23 @@ unquote_arg() {
}

add_arg() {
if [[ -n $XPREPROCESSOR_COMING ]]; then
quote_arg "-Xpreprocessor" >> "$RESPONSE_FILE"
if [[ $XPREPROCESSOR_COMING -eq $IN_RESPONSE_FILE ]]; then
XPREPROCESSOR_COMING=
fi
fi
quote_arg "$1" >> "$RESPONSE_FILE"
}

# ----------------------------------------------------------
# Parse arguments

IN_RESPONSE_FILE=
IN_RESPONSE_FILE=0
INCLUDE_DIR_COMING=
INCLUDE_FLAG=
LIB_DIR_COMING=
XPREPROCESSOR_COMING=

shorten_path() {
local -n shortest="$1"
Expand Down Expand Up @@ -153,7 +171,7 @@ handle_lib_dir() {

handle_arg() {
local arg="$1"
if [[ $IN_RESPONSE_FILE = 1 ]]; then
if [[ $IN_RESPONSE_FILE -gt 0 ]]; then
unquote_arg arg "$arg"
fi
if [[ $INCLUDE_DIR_COMING = 1 ]]; then
Expand All @@ -164,11 +182,11 @@ handle_arg() {
LIB_DIR_COMING=
handle_lib_dir "$arg"
elif [[ "$arg" =~ ^@(.*)$ ]]; then
IN_RESPONSE_FILE=1
(( ++IN_RESPONSE_FILE ))
while read -r line; do
handle_arg "$line"
done < "${BASH_REMATCH[1]}"
IN_RESPONSE_FILE=
(( --IN_RESPONSE_FILE )) || true
elif [[ "$arg" =~ ^(-I|-iquote|-isystem|-idirafter)(.*)$ ]]; then
handle_include_dir "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
elif [[ "$arg" = -I || "$arg" = -iquote || "$arg" = -isystem || "$arg" = -idirafter ]]; then
Expand All @@ -178,6 +196,8 @@ handle_arg() {
handle_lib_dir "${BASH_REMATCH[1]}"
elif [[ "$arg" = -L || "$arg" = --library-path ]]; then
LIB_DIR_COMING=1
elif [[ "$arg" = -Xpreprocessor ]]; then
XPREPROCESSOR_COMING=$IN_RESPONSE_FILE
else
add_arg "$arg"
fi
Expand Down
10 changes: 7 additions & 3 deletions haskell/repl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,13 @@ def _compiler_flags_and_inputs(hs, repl_info, path_prefix = ""):
args,
)

args.extend(ghc_cc_program_args(
paths.join(path_prefix, hs.toolchain.cc_wrapper.executable.path),
))
# The `-pgmP` argument needs to be quoted.
args.extend([
'"{}"'.format(arg)
for arg in ghc_cc_program_args(
paths.join(path_prefix, hs.toolchain.cc_wrapper.executable.path),
)
])

# Add import directories
for import_dir in repl_info.load_info.import_dirs.to_list():
Expand Down
Loading

0 comments on commit 844f87f

Please sign in to comment.