daml/compiler/damlc/BUILD.bazel
Gary Verhaegen 179d85362d
update copyright (#18167)
* update copyright

* undo hack from #18168

* update hash in platform-independence-pre-check
2024-01-15 20:27:42 +01:00

375 lines
11 KiB
Python

# Copyright (c) 2024 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")
load("//bazel_tools/sh:sh.bzl", "sh_inline_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
# `hpp` is linked dynamically so we run it through `package_app` to
# distribute it. However, the result of that is a tarball so it's not going
# to work if we use it as a runfile with `bazel run`. We thus use a copy of the
# dynamically linked executable ("//compiler/damlc:hpp-copy") in the runfiles of
# damlc and the tarball produced by `package_app` ("//compiler/damlc:hpp-dist")
# in the resources of damlc-dist.
copy_file(
name = "hpp-copy",
src = "@stackage-exe//hpp",
out = "hpp" + (".exe" if is_windows else ""),
allow_symlink = True,
is_executable = True,
)
package_app(
name = "hpp-dist",
binary = "@stackage-exe//hpp",
)
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-copy",
"//compiler/damlc/pkg-db",
"//compiler/damlc/stable-packages",
"//compiler/damlc:daml-base-anchors.json",
"//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-copy",
"//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"],
)
# 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-copy",
"//compiler/damlc/stable-packages",
],
hackage_deps = [
"base",
],
src_strip_prefix = "exe",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
"//sdk-version/hs:sdk-version-lib",
],
)
package_app(
name = "damlc-dist",
binary = ":damlc",
resources = [
":daml-base-anchors.json",
":ghc-pkg-dist",
"//compiler/damlc:ghcversion",
"//compiler/damlc:hpp-dist",
"//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 = "@ghc_nix//:lib/ghc-9.0.2/bin/ghc-pkg",
visibility = ["//visibility:public"],
) if not is_windows else genrule(
name = "ghc-pkg-dist",
srcs = [
"@rules_haskell_ghc_windows_amd64//:bin/ghc-pkg.exe",
"@rules_haskell_ghc_windows_amd64//:bin/ghc-pkg-9.0.2.exe",
],
outs = ["ghc-pkg-dist.tar.gz"],
cmd = """
set -eou pipefail
DIR=$$(mktemp -d)
trap "rm -rf $$DIR" EXIT
mkdir $$DIR/ghc-pkg
cp $(location @rules_haskell_ghc_windows_amd64//:bin/ghc-pkg.exe) $$DIR/ghc-pkg/
cp $(location @rules_haskell_ghc_windows_amd64//:bin/ghc-pkg-9.0.2.exe) $$DIR/ghc-pkg/
MKTGZ=$$PWD/$(execpath //bazel_tools/sh:mktgz)
OUT=$$PWD/$(location ghc-pkg-dist.tar.gz)
cd $$DIR
$$MKTGZ $$OUT ghc-pkg
""",
tools = ["//bazel_tools/sh:mktgz"],
)
da_haskell_library(
name = "damlc-lib",
srcs = glob(["lib/**/*.hs"]),
extra_srcs = [
"//:NOTICES",
],
hackage_deps = [
"aeson",
"aeson-pretty",
"ansi-wl-pprint",
"ansi-terminal",
"base",
"base64",
"base64-bytestring",
"blaze-html",
"bytestring",
"containers",
"cryptonite",
"data-default",
"directory",
"either",
"extra",
"file-embed",
"filepath",
"ghcide",
"ghc-lib",
"ghc-lib-parser",
"gitrev",
"lsp",
"lsp-types",
"lens",
"lens-aeson",
"memory",
"mtl",
"network",
"optparse-applicative",
"prettyprinter",
"process",
"proto3-suite",
"regex-tdfa",
"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",
"deepseq",
"hashable",
"binary",
] + ([] if is_windows else ["unix"]),
src_strip_prefix = "lib",
visibility = ["//visibility:public"],
deps = [
"//compiler/daml-dar-reader",
"//compiler/daml-lf-ast",
"//compiler/daml-lf-proto",
"//compiler/daml-lf-reader",
"//compiler/daml-lf-tools",
"//compiler/damlc/daml-compiler",
"//compiler/damlc/daml-desugar",
"//compiler/damlc/daml-doc",
"//compiler/damlc/daml-ide",
"//compiler/damlc/daml-ide-core",
"//compiler/damlc/daml-lf-conversion",
"//compiler/damlc/daml-opts",
"//compiler/damlc/daml-opts:daml-opts-types",
"//compiler/damlc/daml-package-config",
"//compiler/damlc/daml-rule-types",
"//compiler/repl-service/client",
"//compiler/scenario-service/client",
"//compiler/scenario-service/protos:scenario_service_haskell_proto",
"//compiler/scenario-service/protos:test_results_haskell_proto",
"//daml-assistant:daml-lib",
"//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-gcp-logger",
"//libs-haskell/da-hs-base",
"//sdk-version/hs:sdk-version-class-lib",
],
)
# 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:damlc-compile-only) -- docs \
--output=$(OUTS) \
--package-name=daml-prim \
--format=Json \
--target={} \
$(locations //compiler/damlc/daml-prim-src)
""".format(lf_docs_version),
tools = [
"//compiler/damlc:damlc-compile-only",
],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-stdlib-json-docs",
srcs = ["//compiler/damlc/daml-stdlib-src"],
outs = ["daml-stdlib.json"],
cmd = """
$(location //compiler/damlc:damlc-compile-only) -- docs \
--output=$(OUTS) \
--package-name=daml-stdlib \
--format=Json \
--target={} \
$(locations //compiler/damlc/daml-stdlib-src)
""".format(lf_docs_version),
tools = [
"//compiler/damlc:damlc-compile-only",
],
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:damlc-compile-only) -- 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 \\
--no-input-anchor \\
--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:damlc-compile-only",
],
visibility = ["//visibility:public"],
)
daml_doc_test(
name = "daml-stdlib-doctest",
package_name = "daml-stdlib",
srcs = ["//compiler/damlc/daml-stdlib-src"],
flags = [
"--no-dflags-check",
"--import-source=no",
],
ignored_srcs = [
"LibraryModules.daml",
"DA/Experimental/*.daml",
"DA/Time/Types.daml",
"DA/Action/State/Type.daml",
],
)