daml/daml-lf/archive/BUILD.bazel
Sergey Kisel 9a27edd656
Improve MessageDigest and Mac instance creation to solve lock contention [DPP-956] (#13221)
* Improve MessageDigest and Mac instance creation to solve lock contention problem [DPP-956]

changelog_begin
Scalability bottleneck in regard to hashing has been fixed in multiple places.
changelog_end
2022-03-09 22:15:32 +01:00

218 lines
6.8 KiB
Python

# Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load("//bazel_tools:haskell.bzl", "da_haskell_library")
load("//bazel_tools:javadoc_library.bzl", "javadoc_library")
load("//bazel_tools:pom_file.bzl", "pom_file")
load("//bazel_tools:proto.bzl", "proto_jars")
load(
"//bazel_tools:scala.bzl",
"da_scala_binary",
"da_scala_library",
"da_scala_test_suite",
"lf_scalacopts",
"lf_scalacopts_stricter",
)
load("//daml-lf/language:daml-lf.bzl", "LF_MAJOR_VERSIONS", "PROTO_LF_VERSIONS", "mangle_for_java", "versions")
load(
"//rules_daml:daml.bzl",
"daml_compile",
"daml_compile_with_dalf",
)
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")
load("@os_info//:os_info.bzl", "is_windows")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
[
[
filegroup(
name = "daml_lf_%s_archive_proto_srcs" % version,
srcs = glob([
"src/{directory}/protobuf/com/daml/daml_lf_{version}/*.proto".format(
directory = directory,
version = mangled_version,
),
]),
),
proto_jars(
name = "daml_lf_%s_archive_proto" % version,
srcs = [":daml_lf_%s_archive_proto_srcs" % version],
javadoc_root_packages = ["com.daml.daml_lf_%s" % mangled_version],
maven_artifact_prefix = "daml-lf-%s-archive" % short_version,
maven_group = "com.daml",
strip_import_prefix = "src/%s/protobuf" % directory,
visibility = ["//visibility:public"],
),
]
for version in PROTO_LF_VERSIONS
for short_version in ["dev" if version == "1.dev" else version]
for mangled_version in [mangle_for_java(short_version)]
for directory in ["main" if version == "1.dev" else "stable"]
]
# FIXME(JM): Clean this up
genrule(
name = "daml_lf_dev_archive_haskell_proto_src",
srcs = ["daml_lf_1.dev_archive_proto_srcs"],
outs = ["Com/Daml/DamlLfDev/DamlLf.hs"] +
["Com/Daml/DamlLfDev/DamlLf%s.hs" % v.title() for v in LF_MAJOR_VERSIONS],
cmd =
"\n".join(
[
"""
$(location @proto3-suite//:compile-proto-file) \
--includeDir daml-lf/archive/src/main/protobuf/ \
--proto com/daml/daml_lf_dev/daml_lf%s.proto \
--out $(@D)
""" % vx
for vx in [""] + ["_%s" % v for v in LF_MAJOR_VERSIONS]
],
),
tools = [
"@proto3-suite//:compile-proto-file",
],
)
da_haskell_library(
name = "daml_lf_dev_archive_haskell_proto",
srcs = [":daml_lf_dev_archive_haskell_proto_src"],
compiler_flags = [
"-O0",
], # disable optimization as this is otherwise way too slow to compile.
hackage_deps = [
"base",
"bytestring",
"containers",
"deepseq",
"proto3-suite",
"proto3-wire",
"text",
"vector",
],
visibility = ["//visibility:public"],
)
da_scala_library(
name = "daml_lf_archive_reader",
srcs = glob(["src/main/scala/**/*.scala"]),
scala_deps = [
"@maven//:org_scalaz_scalaz_core",
],
scalacopts = lf_scalacopts_stricter,
tags = ["maven_coordinates=com.daml:daml-lf-archive-reader:__VERSION__"],
visibility = ["//visibility:public"],
deps = [
":daml_lf_1.dev_archive_proto_java",
"//daml-lf/data",
"//daml-lf/language",
"//libs-scala/crypto",
"//libs-scala/nameof",
"//libs-scala/scala-utils",
"@maven//:com_google_protobuf_protobuf_java",
],
)
da_scala_test_suite(
name = "daml_lf_archive_reader_tests",
size = "small",
srcs = glob(
["src/test/scala/**/*.scala"],
exclude = ["src/test/scala/com/digitalasset/daml/lf/archive/ZipBombDetectionSpec.scala"],
),
data = [
":DarReaderTest.dalf",
":DarReaderTest.dar",
],
scala_deps = [
"@maven//:org_scalacheck_scalacheck",
"@maven//:org_scalatest_scalatest_core",
"@maven//:org_scalatest_scalatest_flatspec",
"@maven//:org_scalatest_scalatest_matchers_core",
"@maven//:org_scalatest_scalatest_shouldmatchers",
"@maven//:org_scalatestplus_scalacheck_1_15",
"@maven//:org_scalaz_scalaz_core",
"@maven//:org_scalaz_scalaz_scalacheck_binding",
],
scalacopts = lf_scalacopts,
deps = [
":daml_lf_1.dev_archive_proto_java",
":daml_lf_archive_reader",
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/data",
"//daml-lf/language",
"//daml-lf/transaction",
"//libs-scala/scalatest-utils",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_scalatest_scalatest_compatible",
],
)
da_scala_test_suite(
name = "daml_lf_archive_reader_zipbomb_tests",
srcs = ["src/test/scala/com/digitalasset/daml/lf/archive/ZipBombDetectionSpec.scala"],
data = [
":DarReaderTest.dar",
],
scala_deps = [
"@maven//:org_scalacheck_scalacheck",
"@maven//:org_scalatestplus_scalacheck_1_15",
],
scalacopts = lf_scalacopts,
deps = [
":daml_lf_1.14_archive_proto_java",
":daml_lf_1.dev_archive_proto_java",
":daml_lf_archive_reader",
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/data",
"@maven//:com_google_protobuf_protobuf_java",
],
)
daml_compile_with_dalf(
name = "DarReaderTest",
srcs = ["src/test/daml/DarReaderTest.daml"],
)
# An ad-hoc tool for testing, benchmarking and profiling package decoding performance in isolation.
da_scala_binary(
name = "decode-tester",
srcs = ["src/test/scala/com/digitalasset/daml/lf/archive/DecodeMain.scala"],
main_class = "com.daml.lf.archive.DecodeMain",
deps = [
":daml_lf_archive_reader",
"//daml-lf/data",
"//daml-lf/language",
],
)
SNASPSHOT_VERSIONS = [ver for ver in PROTO_LF_VERSIONS if ver != "1.dev"]
[
sh_test(
name = "proto_breaking_changes_%s_test" % version,
srcs = ["proto_breaking_changes.sh"],
args = [
"$(location @buf//:bin/buf)",
"%s" % mangle_for_java(version),
],
data = [
"buf.yaml",
"proto_breaking_changes.sh",
"src/main/protobuf/com/daml/daml_lf_dev",
":daml_lf_%s_archive_proto_srcs" % version,
":daml_lf_1.dev_archive_proto_srcs",
"@buf//:bin/buf",
],
)
for version in SNASPSHOT_VERSIONS
] if not is_windows else []
sh_test(
name = "proto_immutability_test",
srcs = ["proto_check_hash.sh"],
data = [
":daml_lf_%s_archive_proto_srcs" % version
for version in SNASPSHOT_VERSIONS
],
) if not is_windows else []