daml/compiler/damlc/BUILD.bazel
Moritz Kiefer 36719717fa
Update to current state of progress reporting in LSP (#3211)
* Update to current state of progress reporting in LSP

* fix ide-debug-driver

* Fix tests

* Fix build of ghcide executable
2019-10-17 16:14:49 +02:00

335 lines
9.3 KiB
Python

# Copyright (c) 2019 The DAML Authors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "da_haskell_test")
load("//rules_daml:daml.bzl", "daml_compile", "daml_doc_test")
load("@os_info//:os_info.bzl", "is_windows")
load("//bazel_tools/packaging:packaging.bzl", "package_app")
# This is a gross hack: ghc-pkg is linked dynamically so to distribute
# it we have to throw it at package_app. However, the result of that
# is a tarball so if we try to add that to resources `bazel run` is
# not going to work. We thus use the dynamically linked executable in the runfiles of damlc
# and the tarball produced by package_app in the resources of damlc-dist.
ghc_pkg = "@rules_haskell_ghc_windows_amd64//:bin/ghc-pkg.exe" if is_windows else "@ghc_nix//:lib/ghc-8.6.5/bin/ghc-pkg"
da_haskell_binary(
name = "damlc",
srcs = ["exe/Main.hs"],
# We need to tell the linker to statically link pthread on Windows
# otherwise the library is not found at runtime.
compiler_flags = [
"-optl-static",
"-optl-pthread",
] if is_windows else [],
data = [
"//compiler/damlc/daml-ide-core:dlint.yaml",
"@static_asset_d3plus//:js/d3.min.js",
"@static_asset_d3plus//:js/d3plus.min.js",
ghc_pkg,
"//compiler/damlc:ghcversion",
"//compiler/damlc/pkg-db",
"//compiler/scenario-service/server:scenario_service_jar",
],
hackage_deps = [
"base",
],
src_strip_prefix = "exe",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
],
)
genrule(
name = "ghcversion",
srcs = [],
outs = ["ghcversion.h"],
cmd = """
echo > $(OUTS)
""",
tools = [],
visibility = ["__pkg__"],
)
# damlc without runfiles. We use that to build the daml-prim and daml-stdlib
# package databases.
da_haskell_binary(
name = "damlc-bootstrap",
srcs = ["exe/Main.hs"],
# We need to tell the linker to statically link pthread on Windows
# otherwise the library is not found at runtime.
compiler_flags = [
"-optl-static",
"-optl-pthread",
] if is_windows else [],
data = ["//compiler/damlc:ghcversion"],
hackage_deps = [
"base",
],
src_strip_prefix = "exe",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
],
)
package_app(
name = "damlc-dist",
binary = ":damlc",
resources = [
":ghc-pkg-dist",
"//compiler/damlc/daml-ide-core:dlint.yaml",
"//compiler/damlc/pkg-db",
"//compiler/scenario-service/server:scenario_service_jar",
"@static_asset_d3plus//:js/d3.min.js",
"@static_asset_d3plus//:js/d3plus.min.js",
],
tags = ["no-cache"],
visibility = ["//visibility:public"],
)
# ghc-pkg is linked dynamically on Linux by default so we need to run it through package_app
# before we distribute it.
package_app(
name = "ghc-pkg-dist",
# bin/ghc-pkg is actually a wrapper script on Unix systems so it is
# important that we use lib/ghc-$VERSION/bin/ghc-pkg instead which is the
# actual executable.
binary = "@rules_haskell_ghc_windows_amd64//:bin/ghc-pkg.exe" if is_windows else "@ghc_nix//:lib/ghc-8.6.5/bin/ghc-pkg",
visibility = ["//visibility:public"],
)
da_haskell_library(
name = "damlc-lib",
srcs = glob(["lib/**/*.hs"]),
extra_srcs = [
"//compiler/daml-licenses/licenses:licensing.md",
],
hackage_deps = [
"aeson-pretty",
"aeson",
"ansi-wl-pprint",
"base",
"bytestring",
"containers",
"cryptonite",
"directory",
"extra",
"file-embed",
"filepath",
"ghc-lib",
"ghc-lib-parser",
"ghcide",
"gitrev",
"haskell-lsp",
"haskell-lsp-types",
"lens-aeson",
"lens",
"memory",
"mtl",
"network",
"optparse-applicative",
"prettyprinter",
"process",
"proto3-suite",
"safe",
"safe-exceptions",
"shake",
"split",
"tasty-ant-xml",
"tasty-hunit",
"tasty",
"temporary",
"text",
"utf8-string",
"vector",
"xml",
"yaml",
"zip",
"zip-archive",
"unordered-containers",
"uniplate",
] + ([] if is_windows else ["unix"]),
src_strip_prefix = "lib",
visibility = ["//visibility:public"],
deps = [
"//:sdk-version-hs-lib",
"//compiler/daml-lf-ast",
"//compiler/daml-lf-proto",
"//compiler/daml-lf-reader",
"//compiler/daml-lf-tools",
"//compiler/damlc/daml-compiler",
"//compiler/damlc/daml-doc",
"//compiler/damlc/daml-ide",
"//compiler/damlc/daml-ide-core",
"//compiler/damlc/daml-opts",
"//compiler/damlc/daml-opts:daml-opts-types",
"//compiler/damlc/daml-visual",
"//compiler/scenario-service/client",
"//compiler/scenario-service/protos:scenario_service_haskell_proto",
"//daml-assistant:daml-project-config",
"//daml-lf/archive:daml_lf_dev_archive_haskell_proto",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
],
)
# Generating DAML stdlib docs.
filegroup(
name = "daml-base-files", # DAML files to be included in DAML base docs.
srcs = [
"//compiler/damlc/daml-prim-src",
"//compiler/damlc/daml-stdlib-src",
],
visibility = ["__pkg__"],
)
filegroup(
name = "daml-base-hoogle-template",
srcs = ["base-hoogle-template.txt"],
visibility = ["__pkg__"],
)
filegroup(
name = "daml-base-rst-template",
srcs = ["base-rst-template.rst"],
visibility = ["__pkg__"],
)
filegroup(
name = "daml-base-md-template",
srcs = ["base-md-template.md"],
visibility = ["__pkg__"],
)
genrule(
name = "daml-prim-json-docs",
srcs = ["//compiler/damlc/daml-prim-src"],
outs = ["daml-prim.json"],
cmd = """
$(location //compiler/damlc) -- docs \
--output=$(OUTS) \
--package-name=daml-prim \
--format=Json \
--cpp $(location @haskell_hpp//:bin) \
$(locations //compiler/damlc/daml-prim-src)
""",
tools = [
"//compiler/damlc",
"@haskell_hpp//:bin",
],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-stdlib-json-docs",
srcs = ["//compiler/damlc/daml-stdlib-src"],
outs = ["daml-stdlib.json"],
cmd = """
$(location //compiler/damlc) -- docs \
--output=$(OUTS) \
--package-name=daml-stdlib \
--format=Json \
--cpp $(location @haskell_hpp//:bin) \
$(locations //compiler/damlc/daml-stdlib-src)
""",
tools = [
"//compiler/damlc",
"@haskell_hpp//:bin",
],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-base-hoogle-docs",
srcs = [
":daml-prim.json",
":daml-stdlib.json",
":daml-base-hoogle-template",
],
outs = ["daml-base-hoogle.txt"],
cmd = """
$(location //compiler/damlc) -- docs \
--output=$(OUTS) \
--input-format=json \
--format=Hoogle \
--template=$(location :daml-base-hoogle-template) \
$(location :daml-stdlib.json) $(location :daml-prim.json)
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-base-rst-docs",
srcs = [
":daml-prim.json",
":daml-stdlib.json",
":daml-base-rst-template",
],
outs = ["daml-base.rst"],
cmd = """
$(location //compiler/damlc) -- docs \
--combine \
--output=$(OUTS) \
--input-format=json \
--format=Rst \
--template=$(location :daml-base-rst-template) \
$(location :daml-stdlib.json) $(location :daml-prim.json)
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-base-md-docs",
srcs = [
":daml-prim.json",
":daml-stdlib.json",
":daml-base-md-template",
],
outs = ["daml-base.md"],
cmd = """
$(location //compiler/damlc) -- docs \
--combine \
--output=$(OUTS) \
--input-format=json \
--format=Markdown \
--template=$(location :daml-base-md-template) \
$(location :daml-stdlib.json) $(location :daml-prim.json)
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-base-html-docs",
srcs = [
":daml-prim.json",
":daml-stdlib.json",
],
outs = ["daml-base-html.tar.gz"],
cmd = """
$(location //compiler/damlc) -- docs \
--output=daml-base-html \
--input-format=json \
--format=Html \
$(location :daml-stdlib.json) $(location :daml-prim.json)
tar czf $(OUTS) daml-base-html
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
daml_doc_test(
name = "daml-stdlib-doctest",
package_name = "daml-stdlib",
srcs = ["//compiler/damlc/daml-stdlib-src"],
flags = ["--no-dflags-check"],
ignored_srcs = ["LibraryModules.daml"],
)