Skip to content

Commit

Permalink
Switch to GHC 8.10.3 (digital-asset#8394)
Browse files Browse the repository at this point in the history
* Switch to GHC 8.10.3

changelog_begin
changelog_end

* Update bazel-haskell-deps.bzl

Co-authored-by: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>

* Comment on rules_haskell patch

changelog_begin
changelog_end

* .

changelog_begin
changelog_end

Co-authored-by: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
  • Loading branch information
cocreature and aherrmann-da authored Jan 25, 2021
1 parent 535ed8a commit e0c5abd
Show file tree
Hide file tree
Showing 59 changed files with 1,419 additions and 963 deletions.
2 changes: 1 addition & 1 deletion BAZEL-haskell.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Those toolchains are defined in `BUILD` (we'll skip listing their definitions he
The GHC toolchain is registered within macros provided by `rules_haskell`:
```
haskell_register_ghc_nixpkgs(
attribute_path = "ghcStatic",
attribute_path = "ghc",
build_file = "@io_tweag_rules_nixpkgs//nixpkgs:BUILD.pkg",
compiler_flags = [ ... ],
...
Expand Down
12 changes: 5 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ nixpkgs_package(

nix_ghc_deps = common_nix_file_deps + [
"//nix:ghc.nix",
"//nix:overrides/ghc-8.6.5.nix",
"//nix:overrides/ghc-8.10.3.nix",
"//nix:overrides/ghc-8.6.3-binary.nix",
]

Expand Down Expand Up @@ -398,7 +398,7 @@ filegroup(
# This is used to get ghc-pkg on Linux.
nixpkgs_package(
name = "ghc_nix",
attribute_path = "ghcStatic",
attribute_path = "ghc",
build_file_content = """
package(default_visibility = ["//visibility:public"])
exports_files(glob(["lib/**/*"]))
Expand All @@ -421,7 +421,7 @@ common_ghc_flags = [

# Used by Darwin and Linux
haskell_register_ghc_nixpkgs(
attribute_path = "ghcStaticDwarf" if enable_ghc_dwarf else "ghcStatic",
attribute_path = "ghcDwarf" if enable_ghc_dwarf else "ghc",
build_file = "@io_tweag_rules_nixpkgs//nixpkgs:BUILD.pkg",

# -fexternal-dynamic-refs is required so that we produce position-independent
Expand All @@ -439,7 +439,6 @@ haskell_register_ghc_nixpkgs(
"-optc-mmacosx-version-min=10.14",
"-opta-mmacosx-version-min=10.14",
"-optl-mmacosx-version-min=10.14",
"-optP-mmacosx-version-min=10.14",
] if is_darwin else ["-optl-s"])),
compiler_flags_select = {
"@com_github_digital_asset_daml//:profiling_build": ["-fprof-auto"],
Expand All @@ -454,14 +453,13 @@ haskell_register_ghc_nixpkgs(
"-Wwarn",
],
repositories = dev_env_nix_repos,
static_runtime = True,
version = "8.6.5",
version = "8.10.3",
)

# Used by Windows
haskell_register_ghc_bindists(
compiler_flags = common_ghc_flags,
version = "8.6.5",
version = "8.10.3",
) if is_windows else None

nixpkgs_package(
Expand Down
138 changes: 107 additions & 31 deletions bazel-haskell-deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ haskell_binary(
visibility = ["//visibility:public"],
)
""",
sha256 = "216fb8b5d92afc9df70512da2331e098e926239efd55e770802079c2a13bad5e",
strip_prefix = "proto3-suite-0.4.0.0",
urls = ["http://hackage.haskell.org/package/proto3-suite-0.4.0.0/proto3-suite-0.4.0.0.tar.gz"],
sha256 = "b294ff0fe24c6c256dc8eca1d44c2a9a928b9a1bc70ddce6a1d059499edea119",
strip_prefix = "proto3-suite-0af901f9ef3b9719e08eae4fab8fd700d6c8047a",
urls = ["https://github.com/awakesecurity/proto3-suite/archive/0af901f9ef3b9719e08eae4fab8fd700d6c8047a.tar.gz"],
)

#
Expand Down Expand Up @@ -121,52 +121,126 @@ haskell_library(
patches = [
"@com_github_digital_asset_daml//bazel_tools:haskell-ghcide-binary-q.patch",
"@com_github_digital_asset_daml//bazel_tools:haskell-ghcide-expose-compat.patch",
"@com_github_digital_asset_daml//bazel_tools:haskell-ghcide-bounds.patch",
],
sha256 = GHCIDE_SHA256,
strip_prefix = "daml-ghcide-%s" % GHCIDE_REV,
urls = ["https://github.com/digital-asset/daml-ghcide/archive/%s.tar.gz" % GHCIDE_REV],
)

# The Bazel-provided grpc libs cause issues in GHCi so we get them from Nix on Linux and MacOS.
deps = '[":grpc", ":libgpr"]' if is_windows else '["@grpc_nix//:grpc_lib"]'
extra_targets = """
http_archive(
name = "grpc_haskell_core",
build_file_content = """
load("@com_github_digital_asset_daml//bazel_tools:fat_cc_library.bzl", "fat_cc_library")
load("@com_github_digital_asset_daml//bazel_tools:haskell.bzl", "c2hs_suite")
load("@rules_haskell//haskell:defs.bzl", "haskell_library")
c2hs_suite(
name = "grpc-haskell-core",
srcs = [
"src/Network/GRPC/Unsafe/Constants.hsc",
] + glob(["src/**/*.hs"]),
c2hs_src_strip_prefix = "src",
hackage_deps = ["clock", "managed", "base", "sorted-list", "bytestring", "containers", "stm", "transformers"],
c2hs_srcs = [
"src/Network/GRPC/Unsafe/Time.chs",
"src/Network/GRPC/Unsafe/ChannelArgs.chs",
"src/Network/GRPC/Unsafe/Slice.chs",
"src/Network/GRPC/Unsafe/ByteBuffer.chs",
"src/Network/GRPC/Unsafe/Metadata.chs",
"src/Network/GRPC/Unsafe/Op.chs",
"src/Network/GRPC/Unsafe.chs",
"src/Network/GRPC/Unsafe/Security.chs",
],
compiler_flags = ["-XCPP", "-Wno-unused-imports", "-Wno-unused-record-wildcards"],
visibility = ["//visibility:public"],
deps = [
":fat_cbits",
],
)
fat_cc_library(
name = "grpc",
input_lib = "@com_github_grpc_grpc//:grpc",
name = "fat_cbits",
input_lib = "cbits",
)
# Cabal requires libgpr next to libgrpc. However, fat_cc_library of grpc
# already contains gpr and providing a second copy would cause duplicate symbol
# errors. Instead, we define an empty dummy libgpr.
genrule(name = "gpr-source", outs = ["gpr.c"], cmd = "touch $(OUTS)")
cc_library(name = "gpr", srcs = [":gpr-source"])
cc_library(name = "libgpr", linkstatic = 1, srcs = [":gpr"])
""" if is_windows else ""
cc_library(
name = "cbits",
srcs = glob(["cbits/*.c"]),
hdrs = glob(["include/*.h"]),
includes = ["include/"],
deps = [
"@com_github_grpc_grpc//:grpc",
]
)
""",
patch_args = ["-p1"],
patches = [
"@com_github_digital_asset_daml//bazel_tools:grpc-haskell-core-cpp-options.patch",
],
sha256 = "531bbd4df2eca160be436074ade336a70cad3a6477df8d00d479440edfe9896b",
strip_prefix = "gRPC-haskell-0cb7999e9e89d0c17c5e1d917e97cc6e450b9346/core",
urls = ["https://github.com/awakesecurity/gRPC-haskell/archive/0cb7999e9e89d0c17c5e1d917e97cc6e450b9346.tar.gz"],
)

http_archive(
name = "grpc_haskell_core",
name = "grpc_haskell",
build_file_content = """
load("@rules_haskell//haskell:defs.bzl", "haskell_library")
load("@stackage//:packages.bzl", "packages")
haskell_library(
name = "grpc-haskell",
srcs = glob(["src/**/*.hs"]),
deps = packages["grpc-haskell"].deps,
visibility = ["//visibility:public"],
)
""",
sha256 = "531bbd4df2eca160be436074ade336a70cad3a6477df8d00d479440edfe9896b",
strip_prefix = "gRPC-haskell-0cb7999e9e89d0c17c5e1d917e97cc6e450b9346",
urls = ["https://github.com/awakesecurity/gRPC-haskell/archive/0cb7999e9e89d0c17c5e1d917e97cc6e450b9346.tar.gz"],
)

http_archive(
name = "proto3-suite",
build_file_content = """
load("@com_github_digital_asset_daml//bazel_tools:fat_cc_library.bzl", "fat_cc_library")
load("@rules_haskell//haskell:cabal.bzl", "haskell_cabal_library")
load("@stackage//:packages.bzl", "packages")
haskell_cabal_library(
name = "grpc-haskell-core",
version = "0.0.0.0",
name = "proto3-suite",
version = "0.4.2.0",
srcs = glob(["src/**", "test-files/*.bin", "tests/*", "proto3-suite.cabal"]),
haddock = False,
deps = packages["proto3-suite"].deps,
verbose = False,
visibility = ["//visibility:public"],
)
""",
sha256 = "b294ff0fe24c6c256dc8eca1d44c2a9a928b9a1bc70ddce6a1d059499edea119",
strip_prefix = "proto3-suite-0af901f9ef3b9719e08eae4fab8fd700d6c8047a",
urls = ["https://github.com/awakesecurity/proto3-suite/archive/0af901f9ef3b9719e08eae4fab8fd700d6c8047a.tar.gz"],
)

http_archive(
name = "ghc_lib",
build_file_content = """
load("@rules_haskell//haskell:cabal.bzl", "haskell_cabal_library")
load("@stackage//:packages.bzl", "packages")
haskell_cabal_library(
name = "ghc-lib",
version = "8.8.1.20210101",
srcs = glob(["**"]),
haddock = False,
deps = packages["grpc-haskell-core"].deps + {deps},
tools = ["@stackage-exe//c2hs"],
deps = packages["ghc-lib"].deps,
tools = ["@stackage-exe//happy", "@stackage-exe//alex"],
verbose = False,
visibility = ["//visibility:public"],
)
{extra_targets}
""".format(deps = deps, extra_targets = extra_targets),
patch_args = ["-p1"],
""",
patch_args = ["-p2"],
patches = [
"@com_github_digital_asset_daml//bazel_tools:grpc-haskell-core-cpp-options.patch",
"@com_github_digital_asset_daml//bazel_tools:haskell-ghc-lib.patch",
],
sha256 = "087527ec3841330b5328d123ca410901905d111529956821b724d92c436e6cdf",
strip_prefix = "grpc-haskell-core-0.0.0.0",
urls = ["http://hackage.haskell.org/package/grpc-haskell-core-0.0.0.0/grpc-haskell-core-0.0.0.0.tar.gz"],
sha256 = "7014dd6b9b277ecc6c41de8331eeb741c8f255aea784414b43aa668e98bef5d7",
strip_prefix = "ghc-lib-8.8.1.20210101",
urls = ["https://daml-binaries.da-ext.net/da-ghc-lib/ghc-lib-927591afb5343097516894c6163a6df7.tar.gz"],
)

# Note (MK)
Expand Down Expand Up @@ -357,6 +431,7 @@ exports_files(["stack.exe"], visibility = ["//visibility:public"])
"aeson",
"aeson-extra",
"aeson-pretty",
"alex",
"ansi-terminal",
"ansi-wl-pprint",
"array",
Expand Down Expand Up @@ -399,14 +474,13 @@ exports_files(["stack.exe"], visibility = ["//visibility:public"])
"ghc",
"ghc-boot",
"ghc-boot-th",
"ghc-lib",
"ghc-lib-parser",
"ghc-lib-parser-ex",
"ghc-paths",
"ghc-prim",
"gitrev",
"grpc-haskell",
"haddock-library",
"happy",
"hashable",
"haskeline",
"haskell-lsp",
Expand Down Expand Up @@ -458,7 +532,6 @@ exports_files(["stack.exe"], visibility = ["//visibility:public"])
"pretty-show",
"primitive",
"process",
"proto3-suite",
"proto3-wire",
"QuickCheck",
"quickcheck-instances",
Expand Down Expand Up @@ -527,9 +600,12 @@ exports_files(["stack.exe"], visibility = ["//visibility:public"])
vendored_packages = {
"ghcide": "@ghcide_ghc_lib//:ghcide",
"grpc-haskell-core": "@grpc_haskell_core//:grpc-haskell-core",
"grpc-haskell": "@grpc_haskell//:grpc-haskell",
"ghc-lib": "@ghc_lib//:ghc-lib",
"js-jquery": "@js_jquery//:js-jquery",
"js-dgtable": "@js_dgtable//:js-dgtable",
"js-flot": "@js_flot//:js-flot",
"proto3-suite": "@proto3-suite//:proto3-suite",
"shake": "@shake//:shake",
"zip": "@zip//:zip",
},
Expand Down
20 changes: 14 additions & 6 deletions bazel_tools/fat_cc_library.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@os_info//:os_info.bzl", "is_darwin", "is_windows")

def _fat_cc_library_impl(ctx):
Expand All @@ -27,17 +29,23 @@ def _fat_cc_library_impl(ctx):
dyn_lib = ctx.outputs.dynamic_library
static_lib = ctx.outputs.static_library

toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]
feature_configuration = cc_common.configure_features(ctx = ctx, cc_toolchain = toolchain)
toolchain = find_cpp_toolchain(ctx)
feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)

if is_windows:
compiler = toolchain.compiler + ".exe"
else:
compiler = toolchain.compiler
compiler = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = ACTION_NAMES.c_compile,
)
ctx.actions.run(
mnemonic = "CppLinkFatDynLib",
outputs = [dyn_lib],
executable = compiler,
tools = toolchain.all_files.to_list(),
arguments =
["-o", dyn_lib.path, "-shared"] +
ctx.attr.whole_archive_flag +
Expand Down
66 changes: 66 additions & 0 deletions bazel_tools/grpc-gettid.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc
index 561276f0c2..8b597b4cf2 100644
--- a/src/core/lib/gpr/log_linux.cc
+++ b/src/core/lib/gpr/log_linux.cc
@@ -40,7 +40,7 @@
#include <time.h>
#include <unistd.h>

-static long gettid(void) { return syscall(__NR_gettid); }
+static long sys_gettid(void) { return syscall(__NR_gettid); }

void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@@ -70,7 +70,7 @@ void gpr_default_log(gpr_log_func_args* args) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
static __thread long tid = 0;
- if (tid == 0) tid = gettid();
+ if (tid == 0) tid = sys_gettid();

timer = static_cast<time_t>(now.tv_sec);
final_slash = strrchr(args->file, '/');
diff --git a/src/core/lib/gpr/log_posix.cc b/src/core/lib/gpr/log_posix.cc
index b6edc14ab6..2f7c6ce376 100644
--- a/src/core/lib/gpr/log_posix.cc
+++ b/src/core/lib/gpr/log_posix.cc
@@ -31,7 +31,7 @@
#include <string.h>
#include <time.h>

-static intptr_t gettid(void) { return (intptr_t)pthread_self(); }
+static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); }

void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@@ -86,7 +86,7 @@ void gpr_default_log(gpr_log_func_args* args) {
char* prefix;
gpr_asprintf(&prefix, "%s%s.%09d %7" PRIdPTR " %s:%d]",
gpr_log_severity_string(args->severity), time_buffer,
- (int)(now.tv_nsec), gettid(), display_file, args->line);
+ (int)(now.tv_nsec), sys_gettid(), display_file, args->line);

fprintf(stderr, "%-70s %s\n", prefix, args->message);
gpr_free(prefix);
diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc
index 08116b3ab5..76f5984431 100644
--- a/src/core/lib/iomgr/ev_epollex_linux.cc
+++ b/src/core/lib/iomgr/ev_epollex_linux.cc
@@ -1102,7 +1102,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
}

#ifndef NDEBUG
-static long gettid(void) { return syscall(__NR_gettid); }
+static long sys_gettid(void) { return syscall(__NR_gettid); }
#endif

/* pollset->mu lock must be held by the caller before calling this.
@@ -1122,7 +1122,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
#define WORKER_PTR (&worker)
#endif
#ifndef NDEBUG
- WORKER_PTR->originator = gettid();
+ WORKER_PTR->originator = sys_gettid();
#endif
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO,
13 changes: 13 additions & 0 deletions bazel_tools/haskell-cc-wrapper-windows.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/haskell/private/cc_wrapper_windows.sh.tpl b/haskell/private/cc_wrapper_windows.sh.tpl
index e62c07a5..0d64de97 100644
--- a/haskell/private/cc_wrapper_windows.sh.tpl
+++ b/haskell/private/cc_wrapper_windows.sh.tpl
@@ -183,7 +183,7 @@ handle_arg() {
handle_lib_dir "$arg"
elif [[ "$arg" =~ ^@(.*)$ ]]; then
(( ++IN_RESPONSE_FILE ))
- while read -r line; do
+ while IFS=$' \t\r\n' read -r line; do
handle_arg "$line"
done < "${BASH_REMATCH[1]}"
(( --IN_RESPONSE_FILE )) || true
Loading

0 comments on commit e0c5abd

Please sign in to comment.