diff --git a/buf.yaml b/buf.yaml new file mode 100644 index 000000000000..2106016fa8f6 --- /dev/null +++ b/buf.yaml @@ -0,0 +1,27 @@ +# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +version: v1beta1 +build: + roots: + - daml-lf/archive/src/main/protobuf/ + - daml-lf/transaction/src/main/protobuf/ + - ledger/ledger-configuration/protobuf/ + - ledger/participant-state/kvutils/src/main/protobuf/ + excludes: + # We have to exclude these to avoid duplicate definitions of e.g. Unit within the same package. + - daml-lf/archive/src/main/protobuf/com/daml/daml_lf_1_11/ + - daml-lf/archive/src/main/protobuf/com/daml/daml_lf_1_12/ + - daml-lf/archive/src/main/protobuf/com/daml/daml_lf_1_13/ + - daml-lf/archive/src/main/protobuf/com/daml/daml_lf_1_14/ + - daml-lf/archive/src/main/protobuf/com/digitalasset/ + +lint: + use: + - DEFAULT + except: + - PACKAGE_VERSION_SUFFIX + +breaking: + use: + - WIRE_JSON diff --git a/buf_image.bin b/buf_image.bin new file mode 100644 index 000000000000..c23c88e0e396 Binary files /dev/null and b/buf_image.bin differ diff --git a/dev-env/bin/buf b/dev-env/bin/buf new file mode 120000 index 000000000000..943ba2d88c97 --- /dev/null +++ b/dev-env/bin/buf @@ -0,0 +1 @@ +../lib/dade-exec-nix-tool \ No newline at end of file diff --git a/fmt.sh b/fmt.sh index d05e66b5cf03..e6b8aa8f9fef 100755 --- a/fmt.sh +++ b/fmt.sh @@ -11,6 +11,11 @@ cd "$(dirname "$0")" # load the dev-env eval "$(dev-env/bin/dade-assist)" +# Location of reference image used for buf breaking check. +# In case breaking changes have been introduced, running './fmt.sh --rebuild-buf-image' will +# overwrite this image. +buf_image="buf_image.bin" + ## Config ## is_test= scalafmt_args=() @@ -62,6 +67,7 @@ Usage: ./fmt.sh [options] Options: -h, --help: shows this help --test: only test for formatting changes, used by CI + --rebuild-buf-image: rebuilds reference image used for buf breaking checks USAGE exit ;; @@ -79,6 +85,11 @@ USAGE scalafmt_args+=('--mode=diff' "--diff-branch=${merge_base}") diff_mode=true ;; + --rebuild-buf-image) + shift + run buf build -o "${buf_image}" + exit + ;; *) echo "fmt.sh: unknown argument $1" >&2 exit 1 @@ -144,6 +155,9 @@ run scalafmt "${scalafmt_args[@]:-}" # check for Bazel build files code formatting run bazel run "$buildifier_target" +# Run buf checks. +run buf check breaking --against "${buf_image}" + # Note that we cannot use a symlink here because Windows. if ! diff .bazelrc compatibility/.bazelrc >/dev/null; then echo ".bazelrc and compatibility/.bazelrc are out of sync:" diff --git a/nix/default.nix b/nix/default.nix index e8f47b6aa1f6..426be500faf0 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -78,6 +78,8 @@ in rec { javafmt = pkgs.callPackage ./tools/google-java-format {}; + buf = pkgs.buf; + scala = bazel_dependencies.scala_2_13; fsc = scala; scalac = scala;