daml/compiler/damlc/BUILD.bazel
Robin Krom 8c64f120da
pkgid data deps (#9153)
* damlc: Allow package IDs in data-dependencies.

This is the next step outlined in issue #8976. If package id's are
present in the `data-dependency` section of the daml.yaml file, we try
to fetch them (and their transitive dependencies) from the default
ledger of the project.

CHANGELOG_BEGIN
CHANGELOG_END
2021-03-18 12:17:38 +01:00

326 lines
9.0 KiB
Python

# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "da_haskell_repl", "da_haskell_test")
load("//daml-lf/language:daml-lf.bzl", "lf_docs_version")
load("//rules_daml:daml.bzl", "daml_doc_test")
load("@os_info//:os_info.bzl", "is_windows")
load("//bazel_tools/packaging:packaging.bzl", "package_app")
load("//bazel_tools/runfiles:defs.bzl", "add_data")
load(":util.bzl", "ghc_pkg")
damlc_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:hpp",
"//compiler/damlc/pkg-db",
"//compiler/damlc/stable-packages",
"//compiler/repl-service/server:repl_service_jar",
"//compiler/scenario-service/server:scenario_service_jar",
]
add_data(
name = "damlc-compile-only",
data = [
ghc_pkg,
"//compiler/damlc:ghcversion",
"//compiler/damlc:hpp",
"//compiler/damlc/pkg-db",
],
executable = ":damlc-bootstrap",
visibility = ["//visibility:public"],
)
add_data(
name = "damlc",
data = damlc_data,
executable = ":damlc-bootstrap",
visibility = ["//visibility:public"],
)
da_haskell_repl(
name = "damlc@ghci",
data = damlc_data,
repl_ghci_commands = [":m Main"],
visibility = ["//visibility:public"],
deps = [":damlc-bootstrap"],
)
genrule(
name = "ghcversion",
srcs = [],
outs = ["ghcversion.h"],
cmd = """
echo > $(OUTS)
""",
tools = [],
visibility = ["//visibility:public"],
)
genrule(
name = "hpp-rule",
srcs = ["@stackage-exe//hpp"],
outs = ["hpp"],
cmd = """
cp $(location @stackage-exe//hpp) $(OUTS)
""",
tools = [],
visibility = ["//visibility:public"],
)
# 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",
"//compiler/damlc:hpp",
"//compiler/damlc/stable-packages",
],
hackage_deps = [
"base",
],
src_strip_prefix = "exe",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
],
)
package_app(
name = "damlc-dist",
binary = ":damlc",
resources = [
":daml-base-anchors.json",
":ghc-pkg-dist",
"//compiler/damlc:ghcversion",
"//compiler/damlc:hpp",
"//compiler/damlc/daml-ide-core:dlint.yaml",
"//compiler/damlc/pkg-db",
"//compiler/damlc/stable-packages",
"//compiler/repl-service/server:repl_service_jar",
"//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.10.3/bin/ghc-pkg",
visibility = ["//visibility:public"],
)
da_haskell_library(
name = "damlc-lib",
srcs = glob(["lib/**/*.hs"]),
extra_srcs = [
"//:NOTICES",
],
hackage_deps = [
"aeson",
"aeson-pretty",
"ansi-wl-pprint",
"base",
"base64",
"base64-bytestring",
"bytestring",
"containers",
"cryptonite",
"data-default",
"directory",
"either",
"extra",
"file-embed",
"filepath",
"ghcide",
"ghc-lib",
"ghc-lib-parser",
"gitrev",
"haskell-lsp",
"haskell-lsp-types",
"lens",
"lens-aeson",
"memory",
"mtl",
"network",
"optparse-applicative",
"prettyprinter",
"process",
"proto3-suite",
"safe",
"safe-exceptions",
"shake",
"split",
"tasty",
"tasty-ant-xml",
"tasty-hunit",
"temporary",
"text",
"transformers",
"uniplate",
"unordered-containers",
"utf8-string",
"vector",
"xml",
"yaml",
"zip",
"zip-archive",
] + ([] 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-package-config",
"//compiler/damlc/daml-rule-types",
"//compiler/damlc/daml-visual",
"//compiler/repl-service/client",
"//compiler/scenario-service/client",
"//compiler/scenario-service/protos:scenario_service_haskell_proto",
"//daml-assistant:daml-project-config",
"//daml-assistant/daml-helper:daml-helper-lib",
"//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-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-rst-index-template",
srcs = ["base-rst-index-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 \
--target={} \
$(locations //compiler/damlc/daml-prim-src)
""".format(lf_docs_version),
tools = [
"//compiler/damlc",
],
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 \
--target={} \
$(locations //compiler/damlc/daml-stdlib-src)
""".format(lf_docs_version),
tools = [
"//compiler/damlc",
],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-base-docs",
srcs = [
":daml-prim.json",
":daml-stdlib.json",
":daml-base-hoogle-template",
":daml-base-rst-index-template",
":daml-base-rst-template",
],
outs = [
"daml-base-anchors.json",
"daml-base-rst.tar.gz",
"daml-base-hoogle.txt",
],
cmd = """
$(location //compiler/damlc) -- docs \\
--output=daml-base-rst \\
--input-format=json \\
--format=Rst \\
--exclude-instances=HasField \\
--drop-orphan-instances \\
--template=$(location :daml-base-rst-template) \\
--index-template=$(location :daml-base-rst-index-template) \\
--hoogle-template=$(location :daml-base-hoogle-template) \\
--base-url=https://docs.daml.com/daml/stdlib \\
--output-hoogle=$(location :daml-base-hoogle.txt) \\
--output-anchor=$(location :daml-base-anchors.json) \\
--target={} \\
$(location :daml-stdlib.json) $(location :daml-prim.json)
$(execpath //bazel_tools/sh:mktgz) $(location :daml-base-rst.tar.gz) daml-base-rst
""".format(lf_docs_version),
tools = [
"//bazel_tools/sh:mktgz",
"//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",
"DA/Time/Types.daml",
],
)