daml/compiler/damlc/BUILD.bazel
Moritz Kiefer edff8a416d
Move files in daml-foundations/daml-ghc to compiler/damlc (#2037)
* Move files in daml-foundations/daml-ghc to compiler/damlc

There is also a bit of refactoring going on to actually split things
apart into sensible targets. What is still missing is a cleanup of the
module hierarchy and a cleanup of the test targets but I’ll leave
those for separate PRs.

As a nice bonus, this also reduces dependencies between targets so it
will speed up compiles.

* Update .hie-bios
2019-07-08 17:55:51 +02:00

422 lines
11 KiB
Python

# Copyright (c) 2019 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_test")
load("//rules_daml:daml.bzl", "daml_compile")
load("@os_info//:os_info.bzl", "is_windows")
load("//bazel_tools/packaging:packaging.bzl", "package_app")
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/pkg-db",
"//compiler/scenario-service/server:scenario_service_jar",
],
hazel_deps = [
"base",
],
src_strip_prefix = "src",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
],
)
# 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 [],
hazel_deps = [
"base",
],
src_strip_prefix = "src",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
],
)
package_app(
name = "damlc-dist",
binary = ":damlc",
resources = [
":ghc-pkg-dist",
"//compiler/damlc/pkg-db",
"//compiler/scenario-service/server:scenario_service_jar",
],
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 = "@io_tweag_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",
],
hazel_deps = [
"aeson-pretty",
"aeson",
"ansi-wl-pprint",
"base",
"bytestring",
"containers",
"cryptonite",
"directory",
"extra",
"file-embed",
"filepath",
"ghc-lib",
"ghc-lib-parser",
"gitrev",
"haskell-lsp",
"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",
"vector",
"xml",
"yaml",
"zip-archive",
"unordered-containers",
"uniplate",
],
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/hie-core",
"//compiler/scenario-service/client",
"//compiler/scenario-service/protos:scenario_service_haskell_proto",
"//daml-assistant:daml-project-config",
"//daml-lf/archive:daml_lf_haskell_proto",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
],
)
# Tests for the lax CLI parser
da_haskell_test(
name = "damlc-cliparser-test",
srcs = ["cli-tests/CliParser.hs"],
hazel_deps = [
"tasty",
"base",
"optparse-applicative",
"tasty-hunit",
],
main_function = "Cli.main",
src_strip_prefix = "tests",
visibility = ["//visibility:private"],
deps = [
":damlc-lib",
],
)
# Tests for damlc visual
da_haskell_test(
name = "damlc-visual-test",
srcs = ["cli-tests/DamlcVisual.hs"],
data = [
":cli-tests/visual/Basic.dot",
":visual-test-daml.dar",
],
hazel_deps = [
"tasty",
"base",
"extra",
"filepath",
"tasty-golden",
],
main_function = "VisualTest.main",
src_strip_prefix = "tests",
visibility = ["//visibility:private"],
deps = [
":damlc-lib",
"//libs-haskell/bazel-runfiles",
],
)
# Test file used in damlc-visual-test
daml_compile(
name = "visual-test-daml",
main_src = "cli-tests/visual/Basic.daml",
)
# Tests for damlc test
da_haskell_test(
name = "damlc-test-test",
srcs = ["cli-tests/DamlcTest.hs"],
data = [
"//compiler/damlc/pkg-db",
"//compiler/scenario-service/server:scenario_service_jar",
],
hazel_deps = [
"base",
"extra",
"tasty",
"tasty-hunit",
],
main_function = "DamlcTest.main",
src_strip_prefix = "tests",
visibility = ["//visibility:private"],
deps = [
":damlc-lib",
"//compiler/damlc/daml-opts:daml-opts-types",
"//compiler/hie-core",
"//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-prefix",
srcs = ["base-hoogle-prefix.txt"],
visibility = ["__pkg__"],
)
filegroup(
name = "daml-base-rst-prefix",
srcs = ["base-rst-prefix.rst"],
visibility = ["__pkg__"],
)
genrule(
name = "daml-base-hoogle-docs",
srcs = [
":daml-base-files",
":daml-base-hoogle-prefix",
],
outs = ["daml-base-hoogle.txt"],
cmd = "$(location //compiler/damlc) -- docs --output=$(OUTS) --format=Hoogle $(locations :daml-base-files) --prefix=$(location :daml-base-hoogle-prefix)",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
genrule(
name = "daml-base-rst-docs",
srcs = [
":daml-base-files",
":daml-base-rst-prefix",
],
outs = ["daml-base.rst"],
cmd = "$(location //compiler/damlc) -- docs --output=$(OUTS) --format=Rst $(locations :daml-base-files) --prefix=$(location :daml-base-rst-prefix)",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
load(
":util.bzl",
"daml_ghc_compile_test",
"daml_ghc_integration_test",
)
load("@os_info//:os_info.bzl", "is_windows")
# Runs the tests with all non-dev DAML-LF versions
daml_ghc_integration_test("daml-ghc-test-stable", "DA.Test.GHC.mainAll")
# Runs the tests with DAML-LF 1.dev
daml_ghc_integration_test("daml-ghc-test-dev", "DA.Test.GHC.main")
da_haskell_test(
name = "tasty-test",
srcs = ["test-src/DA/Test/TastyMain.hs"],
data = [
":test-files",
"//compiler/damlc/pkg-db",
],
hazel_deps = [
"base",
"tasty-hunit",
"text",
],
main_function = "DA.Test.TastyMain.main",
src_strip_prefix = "test-src",
visibility = ["//visibility:public"],
deps = [
"//compiler/damlc:damlc-lib",
"//compiler/damlc/daml-doc:daml-doc-testing",
"//libs-haskell/da-hs-base",
],
)
da_haskell_test(
name = "damlc-shake-tests",
size = "large",
# this test takes a while and often time out -- tell that to bazel
timeout = "long",
srcs = ["test-src/DA/Test/ShakeIdeClient.hs"],
data = [
"//compiler/damlc/pkg-db",
"//compiler/scenario-service/server:scenario_service_jar",
],
hazel_deps = [
"base",
"directory",
"tasty-hunit",
"text",
],
main_function = "DA.Test.ShakeIdeClient.main",
src_strip_prefix = "test-src",
visibility = ["//visibility:public"],
deps = [
"//compiler/damlc/daml-compiler",
"//compiler/damlc/daml-ide-core",
"//compiler/damlc/daml-ide-core:ide-testing",
"//compiler/hie-core",
"//libs-haskell/da-hs-base",
],
)
da_haskell_binary(
name = "generate-module-tree",
srcs = ["test-src/DA/Test/GenerateModuleTree.hs"],
hazel_deps = [
"base",
"filepath",
],
main_function = "DA.Test.GenerateModuleTree.main",
src_strip_prefix = "test-src",
deps = ["//libs-haskell/da-hs-base"],
)
genrule(
name = "module-tree-test",
outs = ["FatTree{i}.daml".format(i = i) for i in range(1, 19)],
cmd = "$(location :generate-module-tree) $(@D) 18",
tools = [":generate-module-tree"],
visibility = ["//visibility:public"],
)
daml_ghc_compile_test(
name = "module-tree-memory",
srcs = [":module-tree-test"],
main = "FatTree18.daml",
visibility = ["//visibility:public"],
)
daml_ghc_compile_test(
name = "compile-subdir",
srcs = [":test-files"],
main = "test-files/Subdir/Examples.daml",
)
daml_ghc_compile_test(
name = "compile-empty",
srcs = [":test-files"],
main = "test-files/Empty.daml",
)
daml_ghc_compile_test(
name = "examples-memory",
srcs = [":test-files"],
heap_limit = "200M",
main = "test-files/Examples.daml",
stack_limit = "230K",
)
daml_ghc_compile_test(
name = "bond-trading-memory",
srcs = [":bond-trading"],
heap_limit = "200M" if is_windows else "100M",
main = "bond-trading/Test.daml",
stack_limit = "35K",
)
filegroup(
name = "test-files",
srcs = glob(["test-files/**"]),
visibility = [
"__pkg__",
"//daml-foundations/integration-tests:__pkg__",
],
)
filegroup(
name = "bond-trading",
srcs = glob(["bond-trading/**"]),
visibility = [
"__pkg__",
"//daml-foundations/integration-tests:__pkg__",
],
)
# Check that DAML compilation is deterministic.
sh_test(
name = "daml-ghc-deterministic",
srcs = ["test-files/daml-ghc-deterministic.sh"],
args = [
"$(location //compiler/damlc)",
"$(location @com_google_protobuf//:protoc)",
],
data = [
":test-files",
"//compiler/damlc",
"//compiler/damlc/pkg-db",
"@com_google_protobuf//:protoc",
],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)