mirror of
https://github.com/digital-asset/daml.git
synced 2024-10-26 05:09:36 +03:00
Update rules_haskell (#4751)
* Update rules_haskell The workaround for linking against `Cffi` in the REPL has been upstreamed in a more generalized form. CHANGELOG_BEGIN CHANGELOG_END * ghcide: Use rules_haskell's hie-bios support * Document `ghcide` Bazel integration * Rename files to match module names Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
This commit is contained in:
parent
05403da7d3
commit
559c78003e
31
.hie-bios
31
.hie-bios
@ -1,2 +1,29 @@
|
||||
#!/bin/sh
|
||||
cat "$HIE_BIOS_ARGS" | sed "s/'//g" | sed "s/-qg//g" | sed "s/+RTS.*-RTS//" | sed "s|/bazel-out|bazel-out|g" | sed "s/-fexternal-interpreter//g" | tr " " "\n" > "$HIE_BIOS_OUTPUT"
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
hie_bios_flags() {
|
||||
bazel build //compiler/damlc:damlc@ghci \
|
||||
--output_groups=hie_bios \
|
||||
--experimental_show_artifacts \
|
||||
2>&1 \
|
||||
| awk '
|
||||
BEGIN { rts_opts = false }
|
||||
/^>>>/ {
|
||||
while ((getline line < substr($1, 4)) > 0) {
|
||||
if (rts_opts) {
|
||||
if (line == "-RTS") {
|
||||
rts_opts = false
|
||||
}
|
||||
} else if (line == "+RTS") {
|
||||
rts_opts = true
|
||||
} else if (match(line, "-qg|-fexternal-interpreter")) {
|
||||
} else {
|
||||
print line
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
if [[ -z "${HIE_BIOS_OUTPUT-}" ]]; then
|
||||
hie_bios_flags
|
||||
else
|
||||
hie_bios_flags >"$HIE_BIOS_OUTPUT"
|
||||
fi
|
||||
|
@ -226,6 +226,23 @@ alias(
|
||||
)
|
||||
```
|
||||
|
||||
## Editor integration
|
||||
|
||||
The `daml` repository is configured to support [`ghcide`][ghcide] with Bazel
|
||||
and the `ghcide` executable is provided by the `dev-env`. Take a look at the
|
||||
[setup section][ghcide_setup] for example configurations for various editors.
|
||||
`ghcide` has to be built with the same `ghc` as the project you're working on.
|
||||
Be sure to either point your editor to the `dev-env` provided `ghcide` by
|
||||
absolute path, or make sure that the `dev-env` provided `ghcide` is in `$PATH`
|
||||
for your editor.
|
||||
|
||||
Note, `ghcide` itself is built by Bazel and to load a target into the editor
|
||||
some of its dependencies have to be built by Bazel. This means that start-up
|
||||
may take some time if the required artifacts are not built or cached already.
|
||||
|
||||
[ghcide]: https://github.com/digital-asset/ghcide
|
||||
[ghcide_setup]: https://github.com/digital-asset/ghcide#using-with-vs-code
|
||||
|
||||
## Further reading:
|
||||
|
||||
- ["Bazel User Guide"](https://github.com/digital-asset/daml/blob/master/BAZEL.md) (DAML specific)
|
||||
|
@ -12,7 +12,6 @@ exports_files(
|
||||
"haskell-arx.patch",
|
||||
"haskell-win-sys-includes.patch",
|
||||
"haskell-drop-fake-static.patch",
|
||||
"ghci-template.sh",
|
||||
"pom_template.xml",
|
||||
],
|
||||
visibility = ["//:__subpackages__"],
|
||||
|
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2020 The DAML Authors. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
ENV_FILE=$1
|
||||
ARGS_FILE=$2
|
||||
RULES_HASKELL_EXEC_ROOT=bazel-$(basename ${BUILD_WORKSPACE_DIRECTORY})/
|
||||
# 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.
|
||||
PGM_ARGS="-pgma {CC} -pgmc {CC} -pgml {CC} -pgmP {CC} -optc-fno-stack-protector -optP-E -optP-undef -optP-traditional"
|
||||
echo "{ENV}" > "$ENV_FILE"
|
||||
echo $PGM_ARGS "{ARGS}" > "$ARGS_FILE"
|
@ -1,25 +0,0 @@
|
||||
From 5210265a3b95327038865b0c8a6cc3cf982626e6 Mon Sep 17 00:00:00 2001
|
||||
From: Andreas Herrmann <andreas.herrmann@tweag.io>
|
||||
Date: Tue, 25 Feb 2020 18:02:38 +0100
|
||||
Subject: [PATCH] Explicitly check for "Cffi" in `is_hs_library`
|
||||
|
||||
---
|
||||
haskell/private/path_utils.bzl | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/haskell/private/path_utils.bzl b/haskell/private/path_utils.bzl
|
||||
index 2327c3aa..5e0a986e 100644
|
||||
--- a/haskell/private/path_utils.bzl
|
||||
+++ b/haskell/private/path_utils.bzl
|
||||
@@ -187,7 +187,7 @@ def is_hs_library(lib):
|
||||
# linked against directly, but rather through the package configuration. In
|
||||
# particular ffi, if included in the GHC bindist, comes in different
|
||||
# flavours for different GHC ways (e.g. threaded).
|
||||
- return libname.startswith("HS") or lib.owner == Label("@rules_haskell//haskell:toolchain-libraries")
|
||||
+ return libname.startswith("HS") or libname == "Cffi" or lib.owner == Label("@rules_haskell//haskell:toolchain-libraries")
|
||||
|
||||
def get_dynamic_hs_lib_name(ghc_version, lib):
|
||||
"""Return name of library by dropping extension,
|
||||
--
|
||||
2.20.1
|
||||
|
1254
bazel_tools/haskell-strict-source-names.patch
Normal file
1254
bazel_tools/haskell-strict-source-names.patch
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,10 @@
|
||||
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 d4ae130e..25dcfbb7 100644
|
||||
index bcb83c73..46148f16 100644
|
||||
--- a/haskell/private/actions/package.bzl
|
||||
+++ b/haskell/private/actions/package.bzl
|
||||
@@ -123,7 +123,12 @@ def package(
|
||||
@@ -97,7 +97,12 @@ def package(
|
||||
"library-dirs": ["${pkgroot}"] + extra_lib_dirs,
|
||||
"dynamic-library-dirs": ["${pkgroot}"] + extra_dynamic_lib_dirs,
|
||||
"hs-libraries": [pkg_id.library_name(hs, my_pkg_id)] if has_hs_library else [],
|
||||
@ -16,5 +16,5 @@ index d4ae130e..25dcfbb7 100644
|
||||
+ "ws2_32",
|
||||
+ ] if hs.toolchain.is_windows else []),
|
||||
"depends": hs.package_ids,
|
||||
"exposed-modules": exposed_modules,
|
||||
})
|
||||
|
||||
|
@ -247,10 +247,6 @@ def da_haskell_repl(**kwargs):
|
||||
"//conditions:default": False,
|
||||
}),
|
||||
experimental_from_binary = ["//nix/..."],
|
||||
ghci_repl_wrapper = select({
|
||||
"//:hie_bios_ghci": "//bazel_tools:ghci-template.sh",
|
||||
"//conditions:default": "@rules_haskell//haskell:private/ghci_repl_wrapper.sh",
|
||||
}),
|
||||
repl_ghci_args = [
|
||||
"-fexternal-interpreter",
|
||||
"-j",
|
||||
|
@ -1,22 +0,0 @@
|
||||
diff --git a/haskell/repl.bzl b/haskell/repl.bzl
|
||||
index 1d31257..6037b84 100644
|
||||
--- a/haskell/repl.bzl
|
||||
+++ b/haskell/repl.bzl
|
||||
@@ -278,7 +278,7 @@ def _create_repl(hs, ctx, repl_info, output):
|
||||
)
|
||||
|
||||
hs.actions.expand_template(
|
||||
- template = ctx.file._ghci_repl_wrapper,
|
||||
+ template = ctx.file.ghci_repl_wrapper,
|
||||
output = output,
|
||||
is_executable = True,
|
||||
substitutions = {
|
||||
@@ -361,7 +361,7 @@ haskell_repl = rule(
|
||||
allow_single_file = True,
|
||||
default = Label("@rules_haskell//haskell:assets/ghci_script"),
|
||||
),
|
||||
- "_ghci_repl_wrapper": attr.label(
|
||||
+ "ghci_repl_wrapper": attr.label(
|
||||
allow_single_file = True,
|
||||
default = Label("@rules_haskell//haskell:private/ghci_repl_wrapper.sh"),
|
||||
),
|
2
build.sh
2
build.sh
@ -39,5 +39,5 @@ if [[ "$(uname)" != "Darwin" ]]; then
|
||||
da-ghci --data yes //compiler/damlc:damlc -e ':main --help'
|
||||
fi
|
||||
# Check that our IDE works on our codebase
|
||||
./compiler/ghcide-daml.sh compiler/damlc/exe/Main.hs 2>&1 | tee ide-log
|
||||
ghcide compiler/damlc/exe/Main.hs 2>&1 | tee ide-log
|
||||
grep -q "1 file worked, 0 files failed" ide-log
|
||||
|
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2020 The DAML Authors. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"/..
|
||||
export RULES_HASKELL_EXEC_ROOT=$PWD/
|
||||
ENV_FILE=$(mktemp)
|
||||
ARGS_FILE=$(mktemp)
|
||||
bazel build @ghcide//:ghcide >/dev/null 2>&1
|
||||
bazel run --define hie_bios_ghci=True //compiler/damlc:damlc@ghci -- "$ENV_FILE" "$ARGS_FILE" >/dev/null 2>&1
|
||||
source "$ENV_FILE"
|
||||
export HIE_BIOS_ARGS="$ARGS_FILE"
|
||||
./bazel-bin/external/ghcide/_install/bin/ghcide $@
|
13
deps.bzl
13
deps.bzl
@ -31,8 +31,8 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
||||
|
||||
rules_scala_version = "6c16cff213b76a4126bdc850956046da5db1daaa"
|
||||
|
||||
rules_haskell_version = "eaa89858c44913f65fb48637d75e3190a912f3ae"
|
||||
rules_haskell_sha256 = "c2b42f35ecc4c90bf8a5a4d90a1c1e3937513309904809d4c02ce12cf9cc4093"
|
||||
rules_haskell_version = "d59ccf9e7785553fd392924fb083d926c7e01134"
|
||||
rules_haskell_sha256 = "c29e779f512f72126c774bceb0bee5c01ca8149d30acc400058014f4b2275710"
|
||||
rules_nixpkgs_version = "c966bb8bd335f1e244c03efe6e7a1afa9784038e"
|
||||
rules_nixpkgs_sha256 = "ccafea4fc4d5fa2ddba2882f76728558bfe2c12657f7f56078ece43a31761148"
|
||||
davl_version = "51d3977be2ab22f7f4434fd4692ca2e17a7cce23"
|
||||
@ -45,23 +45,20 @@ def daml_deps():
|
||||
strip_prefix = "rules_haskell-%s" % rules_haskell_version,
|
||||
urls = ["https://github.com/tweag/rules_haskell/archive/%s.tar.gz" % rules_haskell_version],
|
||||
patches = [
|
||||
# Update and remove this patch once this is upstreamed.
|
||||
# See https://github.com/tweag/rules_haskell/pull/1281
|
||||
"@com_github_digital_asset_daml//bazel_tools:haskell-strict-source-names.patch",
|
||||
# The fake libs issue should be fixed in upstream rules_haskell
|
||||
# or GHC. Remove this patch once that's available.
|
||||
"@com_github_digital_asset_daml//bazel_tools:haskell-windows-remove-fake-libs.patch",
|
||||
# This is a daml specific patch and not upstreamable.
|
||||
"@com_github_digital_asset_daml//bazel_tools:haskell-windows-extra-libraries.patch",
|
||||
# This is a daml specific patch and not upstreamable.
|
||||
# rules_haskell should have builtin support for hie-bios.
|
||||
# Remove this patch once that's available.
|
||||
"@com_github_digital_asset_daml//bazel_tools:haskell_public_ghci_repl_wrapper.patch",
|
||||
# This fixes a ghc-lib specific build issue and is not upstreamable.
|
||||
# This might also be fixed by using `stack_snapshot` in the future.
|
||||
"@com_github_digital_asset_daml//bazel_tools:haskell-no-isystem.patch",
|
||||
# This should be made configurable in rules_haskell.
|
||||
# Remove this patch once that's available.
|
||||
"@com_github_digital_asset_daml//bazel_tools:haskell-opt.patch",
|
||||
# This should be fixed in upstream rules_haskell.
|
||||
"@com_github_digital_asset_daml//bazel_tools:haskell-cffi.patch",
|
||||
],
|
||||
patch_args = ["-p1"],
|
||||
sha256 = rules_haskell_sha256,
|
||||
|
4
dev-env/bin/ghcide
Executable file
4
dev-env/bin/ghcide
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"
|
||||
bazel build @ghcide//:ghcide && bazel-bin/external/ghcide/_install/bin/ghcide "$@"
|
Loading…
Reference in New Issue
Block a user