Skip to content

Commit

Permalink
Update rules_haskell and static GHC (digital-asset#1515)
Browse files Browse the repository at this point in the history
* Update rules_haskell and static GHC

Remove patches that have been upstreamed or are no longer required.
Update still required patches to match the new rules_haskell version.

Previously we patched rules_haskell to coerce GHC into using static
Haskell libraries in most places. In particular we moved hs-libraries
entries into extra-libraries entries in the package configuration files.
A much cleaner approach is to compile GHC with a static RTS, then GHC
will by itself choose to load static Haskell libraries.

* Remove haskell_cc_import

* da-hs-daml-cli -> daml-cli

* da-hs-damlc-app -> damlc-app
  • Loading branch information
aherrmann-da authored Jul 1, 2019
1 parent 6919b07 commit 93d8e01
Show file tree
Hide file tree
Showing 59 changed files with 132 additions and 322 deletions.
1 change: 0 additions & 1 deletion 3rdparty/haskell/BUILD.clock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package(default_visibility = ["//visibility:public"])

load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
"haskell_cc_import",
)
load("@ai_formation_hazel//:hazel.bzl", "hazel_library")

Expand Down
1 change: 0 additions & 1 deletion 3rdparty/haskell/BUILD.streaming-commons
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package(default_visibility = ["//visibility:public"])

load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
"haskell_cc_import",
)
load("@ai_formation_hazel//:hazel.bzl", "hazel_library")

Expand Down
1 change: 0 additions & 1 deletion 3rdparty/haskell/BUILD.zlib
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package(default_visibility = ["//visibility:public"])

load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
"haskell_cc_import",
)
load("@ai_formation_hazel//:hazel.bzl", "hazel_library")

Expand Down
9 changes: 3 additions & 6 deletions BAZEL-haskell.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,17 @@ sets the default visibility property globally for our targets as `public`. This
The `load` statments
```
load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_toolchain", "haskell_toolchain_library", "haskell_cc_import",
"haskell_toolchain", "haskell_toolchain_library",
)
load("@io_tweag_rules_haskell//haskell:c2hs.bzl",
"c2hs_toolchain",
)
```
bring the macros `haskell_toolchain`, `haskell_toolchain_library`, `haskell_cc_import` and `c2hs_toolchain` into scope from `rules_haskell`.
bring the macros `haskell_toolchain`, `haskell_toolchain_library`, and `c2hs_toolchain` into scope from `rules_haskell`.

`haskell_toolchain_library`:
- import a package that is prebuilt outside of Bazel

`haskell_cc_import`:
- import a C library that is prebuilt outside of Bazel

`haskell_toolchain`:
- declare a GHC compiler toolchain

Expand All @@ -184,7 +181,7 @@ Lastly, there are some aliases defined here. For example,
```
alias(
name = "damlc",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app"
actual = "//daml-foundations/daml-tools/damlc-app"
)
```

Expand Down
6 changes: 3 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ genrule(

alias(
name = "damlc",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app",
actual = "//daml-foundations/daml-tools/damlc-app:damlc-app",
)

alias(
name = "damlc@ghci",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app@ghci",
actual = "//daml-foundations/daml-tools/damlc-app:damlc-app@ghci",
)

alias(
name = "damlc-dist",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:damlc-dist",
actual = "//daml-foundations/daml-tools/damlc-app:damlc-dist",
)

alias(
Expand Down
18 changes: 18 additions & 0 deletions bazel_tools/haskell-darwin-symlink-dylib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rules_haskell generates symbolic links for dynamic library dependencies to
avoid too long load commands and too many RUNPATH commands and to convert .so
file extensions to .dylib file extensions on MacOS. On Windows creating the
symbolic links can fail due to too long file paths. The symlinks are only
really required on MacOS, so we limit their creation to MacOS.
diff --git a/haskell/providers.bzl b/haskell/providers.bzl
index 7574456..e5b7c2e 100644
--- a/haskell/providers.bzl
+++ b/haskell/providers.bzl
@@ -266,7 +266,7 @@ def get_extra_libs(hs, cc_info, dynamic = False, pic = None, fixup_dir = "_libs"
elif lib_to_link.static_library and not pic_required:
static_lib = lib_to_link.static_library

- if dynamic_lib:
+ if dynamic_lib and hs.toolchain.is_darwin:
dynamic_lib = symlink_dynamic_library(hs, dynamic_lib, fixed_lib_dir)
static_lib = mangle_static_library(hs, dynamic_lib, static_lib, fixed_lib_dir)

3 changes: 2 additions & 1 deletion bazel_tools/haskell-drop-fake-static.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ diff --git a/haskell/ghc_bindist.bzl b/haskell/ghc_bindist.bzl
index 3a58776..69852f0 100644
--- a/haskell/ghc_bindist.bzl
+++ b/haskell/ghc_bindist.bzl
@@ -258,6 +258,11 @@ haskell_toolchain(
@@ -258,6 +258,12 @@ haskell_toolchain(
haddock_flags = ctx.attr.haddock_flags,
repl_ghci_args = ctx.attr.repl_ghci_args,
)
+
+ if os == "windows":
+ _execute_fail_loudly(ctx, ["rm", "mingw/lib/gcc/x86_64-w64-mingw32/7.2.0/libstdc++.dll.a"])
+ _execute_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libpthread.dll.a"])
+ _execute_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libwinpthread.dll.a"])
+
ctx.template(
Expand Down
16 changes: 16 additions & 0 deletions bazel_tools/haskell-ghci-grpc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
On MacOS GHCi fails to load grpc fat_cbits statically due to duplicate symbols.
diff --git a/haskell/providers.bzl b/haskell/providers.bzl
index 7574456..a5241e1 100644
--- a/haskell/providers.bzl
+++ b/haskell/providers.bzl
@@ -270,6 +270,10 @@ def get_extra_libs(hs, cc_info, dynamic = False, pic = None, fixup_dir = "_libs"
dynamic_lib = symlink_dynamic_library(hs, dynamic_lib, fixed_lib_dir)
static_lib = mangle_static_library(hs, dynamic_lib, static_lib, fixed_lib_dir)

+ if fixup_dir == "_ghci_libs" and dynamic_lib and get_lib_name(dynamic_lib) == "fat_cbits":
+ dynamic_libs.append(dynamic_lib)
+ continue
+
if static_lib and not (dynamic and dynamic_lib):
static_libs.append(static_lib)
elif dynamic_lib:
25 changes: 0 additions & 25 deletions bazel_tools/haskell-keep-hs-extra-libs.patch

This file was deleted.

100 changes: 0 additions & 100 deletions bazel_tools/haskell-package-env.patch

This file was deleted.

48 changes: 0 additions & 48 deletions bazel_tools/haskell-static-linking.patch

This file was deleted.

19 changes: 19 additions & 0 deletions bazel_tools/haskell-windows-extra-libraries.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Some packages, network in particular, require to link additional libraries to
avoid missing symbol errors when linking on Windows.
diff --git a/haskell/private/actions/package.bzl b/haskell/private/actions/package.bzl
index 2b56388..0c5c37c 100644
--- a/haskell/private/actions/package.bzl
+++ b/haskell/private/actions/package.bzl
@@ -107,7 +107,12 @@ def package(
"library-dirs": ["${pkgroot}"] + extra_lib_dirs,
"dynamic-library-dirs": ["${pkgroot}"] + extra_lib_dirs,
"hs-libraries": [pkg_id.library_name(hs, my_pkg_id)],
- "extra-libraries": extra_libs,
+ "extra-libraries": extra_libs + ([
+ "stdc++",
+ "crypt32",
+ "shlwapi",
+ "ws2_32",
+ ] if hs.toolchain.is_windows else []),
"depends": hs.package_ids,
})
65 changes: 0 additions & 65 deletions bazel_tools/haskell_ghci_repl_toolchain_lib.patch

This file was deleted.

2 changes: 1 addition & 1 deletion compiler/lsp-tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ da_haskell_test(
name = "lsp-tests",
srcs = glob(["src/**/*.hs"]),
data = [
"//daml-foundations/daml-tools/da-hs-damlc-app",
"//daml-foundations/daml-tools/damlc-app",
],
# For some reason this test sometimes seems to time out on Windows.
# It hits the Bazel timeout rather than the timeout in lsp-tests
Expand Down
Loading

0 comments on commit 93d8e01

Please sign in to comment.