daml/daml-lf/archive/BUILD.bazel

229 lines
6.5 KiB
Python

# Copyright (c) 2019 The DAML Authors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load("//bazel_tools:haskell.bzl", "da_haskell_library")
load("//bazel_tools:pkg.bzl", "pkg_tar")
load("//bazel_tools:proto.bzl", "proto_gen")
load(
"//bazel_tools:scala.bzl",
"da_scala_library",
"da_scala_test_suite",
"lf_scalacopts",
)
load(
"//rules_daml:daml.bzl",
"daml_compile",
)
load("//bazel_tools:pom_file.bzl", "pom_file")
load("@os_info//:os_info.bzl", "is_windows")
load("//bazel_tools:javadoc_library.bzl", "javadoc_library")
LF_MAJOR_VERSIONS = [
"0",
"1",
]
filegroup(
name = "daml-lf-archive-srcs",
srcs = ["da/daml_lf.proto"] + ["da/daml_lf_%s.proto" % v for v in LF_MAJOR_VERSIONS],
visibility = ["//visibility:public"],
)
exports_files(
["da/daml_lf_%s.proto" % v for v in LF_MAJOR_VERSIONS],
)
proto_library(
name = "daml_lf_proto",
srcs = [":daml-lf-archive-srcs"],
proto_source_root = "daml-lf/archive",
visibility = ["//:__subpackages__"],
)
proto_gen(
name = "daml_lf_java_proto_srcs",
srcs = [":daml_lf_proto"],
plugin_name = "java",
)
java_library(
name = "daml_lf_java_proto",
srcs = [":daml_lf_java_proto_srcs"],
tags = ["maven_coordinates=com.digitalasset:daml-lf-archive:__VERSION__"],
visibility = ["//visibility:public"],
exports = ["//3rdparty/jvm/com/google/protobuf:protobuf_java"],
deps = ["//3rdparty/jvm/com/google/protobuf:protobuf_java"],
)
# FIXME(JM): Clean this up
genrule(
name = "daml_lf_haskell_proto_src",
srcs = glob(["da/*.proto"]),
outs = ["Da/DamlLf.hs"] + ["Da/DamlLf%s.hs" % v.title() for v in LF_MAJOR_VERSIONS],
cmd =
"ORIGPWD=`pwd`\ncd daml-lf/archive\n" +
"\n".join(
[
"$$ORIGPWD/$(location @haskell_proto3__suite//:compile-proto-file) --proto da/daml_lf%s.proto --out $$ORIGPWD/$(@D)" % vx
for vx in [""] + ["_%s" % v for v in LF_MAJOR_VERSIONS]
],
),
tools = [
"@haskell_proto3__suite//:compile-proto-file",
],
)
da_haskell_library(
name = "daml_lf_haskell_proto",
srcs = [":daml_lf_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_scala",
srcs = glob(["src/main/**/*.scala"]),
scalacopts = lf_scalacopts,
tags = ["maven_coordinates=com.digitalasset:daml-lf-archive-scala:__VERSION__"],
visibility = ["//visibility:public"],
deps = [
":daml_lf_java_proto",
"//3rdparty/jvm/com/google/protobuf:protobuf_java",
"//3rdparty/jvm/commons_io",
"//3rdparty/jvm/org/scalaz:scalaz_core",
"//daml-lf/data",
"//daml-lf/language",
],
)
da_scala_test_suite(
name = "daml_lf_archive_scala_tests",
size = "small",
srcs = glob(["src/test/**/*.scala"]),
data = [
":DarReaderTest.dalf",
":DarReaderTest.dar",
],
scalacopts = lf_scalacopts,
deps = [
":daml_lf_archive_scala",
":daml_lf_java_proto",
"//3rdparty/jvm/com/google/protobuf:protobuf_java",
"//3rdparty/jvm/org/scalacheck",
"//3rdparty/jvm/org/scalatest",
"//3rdparty/jvm/org/scalaz:scalaz_core",
"//3rdparty/jvm/org/scalaz:scalaz_scalacheck_binding",
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/data",
"//daml-lf/data-scalacheck",
"//daml-lf/language",
"//daml-lf/parser",
"//daml-lf/validation",
],
)
daml_compile(
name = "DarReaderTest",
main_src = "src/test/daml/DarReaderTest.daml",
)
filegroup(
name = "proto_srcs",
srcs = ["da/daml_lf.proto"] + ["da/daml_lf_%s.proto" % v for v in LF_MAJOR_VERSIONS],
)
proto_library(
name = "daml_lf_proto_lib",
srcs = [":proto_srcs"],
proto_source_root = "daml-lf/archive",
)
java_proto_library(
name = "daml_lf_proto_lib_java",
visibility = ["//visibility:public"],
deps = [":daml_lf_proto_lib"],
)
javadoc_library(
name = "daml_lf_archive_java_javadoc",
srcs = [":daml_lf_proto_lib_java"],
root_packages = ["com.digitalasset.daml_lf"],
visibility = ["//visibility:public"],
deps = [":daml_lf_proto_lib_java"],
)
# This is an hack to avoid having to complicate the release logic.
# Once we stop bundling proto files in daml_lf_archive_java
# we can remove this.
genrule(
name = "daml_lf_archive_java_srcjar",
srcs = ["daml_lf_proto_lib_java"],
outs = ["daml_lf_archive_java_srcjar.jar"],
cmd = """
for file in $(locations :daml_lf_proto_lib_java); do
if [[ $$file == *src* ]]; then
cp $$file $(location daml_lf_archive_java_srcjar.jar)
fi
done
""",
visibility = ["//visibility:public"],
)
# NOTE(MH): The pre-bazel release process put the `.proto` files in
# `daml-lf-archive.jar` as well. This rule is replicating this old behavior.
# This will very likely change in the future to not include the `.proto` files.
genrule(
name = "daml_lf_archive_java",
srcs = [
":proto_srcs",
":daml_lf_proto_lib_java",
],
outs = ["daml_lf_archive_java.jar"],
cmd = """
INPUT=$$(echo "$(locations :daml_lf_proto_lib_java)" | tr ' ' '\n' | grep -v '\-src.jar')
cp -L $$INPUT $@
chmod u+w $@
$(location @zip_dev_env//:zip) -g $@ $(locations :proto_srcs)
""",
tags = ["maven_coordinates=com.digitalasset:daml-lf-archive:__VERSION__"],
tools = ["@zip_dev_env//:zip"],
visibility = ["//visibility:public"],
)
pom_file(
name = "daml_lf_archive_java_pom",
target = ":daml_lf_archive_java",
visibility = ["//visibility:public"],
)
genrule(
name = "daml_lf_archive_protos_zip",
srcs = [":proto_srcs"],
outs = ["daml_lf_archive_protos_zip.zip"],
cmd = """
mkdir -p daml-lf-archive-protos/protobuf/com/digitalasset/daml_lf
cp $(SRCS) daml-lf-archive-protos/protobuf/com/digitalasset/daml_lf
$(location @zip_dev_env//:zip) -r $@ daml-lf-archive-protos
""",
tools = ["@zip_dev_env//:zip"],
visibility = ["//visibility:public"],
)
pkg_tar(
name = "daml_lf_archive_protos_tarball",
srcs = [":proto_srcs"],
extension = "tar.gz",
package_dir = "daml-lf-archive-protos/protobuf/da",
visibility = ["//visibility:public"],
)