bufbuild / protovalidate-cc

Protocol Buffer Validation for C++.
https://buf.build/bufbuild/protovalidate
Apache License 2.0
17 stars 4 forks source link

[BUG] Build fails with bazel/http_archive and v0.1.0 #50

Closed rofrankel closed 10 months ago

rofrankel commented 10 months ago

Description

I can build protovalidate-cc locally in isolation (with WSL2 running Debian), but when I try to include it via http_archive as part of another project (our internal Envoy proxy fork), I get these errors:

root@fff9119453b6:/# bazel-6.1.2 build --disk_cache=/bazel-cache --repository_cache=/bazel-repo-cache --sandbox_debug --verbose_failures //:public_gateway
INFO: Invocation ID: 1cdb737b-72ec-4294-936d-70d0bbe71a8d
INFO: Analyzed target //:public_gateway (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
INFO: From BazelWorkspaceStatusAction stable-status.txt:
fatal: No such remote 'origin'
ERROR: /root/.cache/bazel/_bazel_root/6666cd76f96956469e7be39d750cc7d9/external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/BUILD.bazel:75:11: Compiling buf/validate/internal/constraints.cc failed: (Exit 1): process-wrapper failed: error executing command
  (cd /root/.cache/bazel/_bazel_root/6666cd76f96956469e7be39d750cc7d9/sandbox/processwrapper-sandbox/63/execroot/public_gateway_proxy_filter && \
  exec env - \
    BAZEL_LINKLIBS=-l%:libstdc++.a \
    BAZEL_LINKOPTS=-lm \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
    TMPDIR=/tmp \
  /root/.cache/bazel/_bazel_root/install/7ebdb6373cb28848a230741519affc6a/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=/root/.cache/bazel/_bazel_root/6666cd76f96956469e7be39d750cc7d9/sandbox/processwrapper-sandbox/63/stats.out' /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/_objs/constraint/constraints.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/_objs/constraint/constraints.pic.o' -fPIC '-DBAZEL_CURRENT_REPOSITORY="com_github_bufbuild_protovalidate_cc"' -iquote external/com_github_bufbuild_protovalidate_cc -iquote bazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate_cc -iquote external/com_github_bufbuild_protovalidate -iquote bazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate -iquote external/com_google_protobuf -iquote bazel-out/k8-fastbuild/bin/external/com_google_protobuf -iquote external/com_google_absl -iquote bazel-out/k8-fastbuild/bin/external/com_google_absl -iquote external/com_google_cel_cpp -iquote bazel-out/k8-fastbuild/bin/external/com_google_cel_cpp -iquote external/com_google_googleapis -iquote bazel-out/k8-fastbuild/bin/external/com_google_googleapis -iquote external/antlr4_runtimes -iquote bazel-out/k8-fastbuild/bin/external/antlr4_runtimes -iquote external/com_googlesource_code_re2 -iquote bazel-out/k8-fastbuild/bin/external/com_googlesource_code_re2 -Ibazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate/proto/protovalidate/buf/validate/_virtual_includes/validate_proto -Ibazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate/proto/protovalidate/buf/validate/_virtual_includes/expression_proto -Ibazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate/proto/protovalidate/buf/validate/priv/_virtual_includes/priv_proto -Ibazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_includes/descriptor_proto -Ibazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_includes/duration_proto -Ibazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_includes/timestamp_proto -Ibazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_includes/struct_proto -Ibazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_includes/empty_proto -Ibazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_includes/any_proto -Ibazel-out/k8-fastbuild/bin/external/com_google_protobuf/_virtual_includes/wrappers_proto -isystem external/com_google_protobuf/src -isystem bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src -isystem bazel-out/k8-fastbuild/bin/external/envoy/bazel/foreign_cc/zlib/include -isystem external/antlr4_runtimes/runtime/Cpp/runtime/src -isystem bazel-out/k8-fastbuild/bin/external/antlr4_runtimes/runtime/Cpp/runtime/src '-DABSL_MIN_LOG_LEVEL=4' -fPIC -Wno-deprecated-declarations '-std=c++17' -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc -o bazel-out/k8-fastbuild/bin/external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/_objs/constraint/constraints.pic.o)
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc: In function 'absl::StatusOr<std::unique_ptr<google::api::expr::runtime::CelExpressionBuilder> > buf::validate::internal::NewConstraintBuilder(google::protobuf::Arena*)':
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc:41:11: error: 'struct google::api::expr::runtime::InterpreterOptions' has no member named 'enable_regex_precompilation'
   41 |   options.enable_regex_precompilation = true;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc: In function 'bool buf::validate::internal::isEmptyItem(google::api::expr::runtime::CelValue)':
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc:148:21: error: could not convert 'cel::Kind::kBool' from 'cel::Kind' to 'google::api::expr::runtime::CelValue::Type'
  148 |   case ::cel::Kind::kBool:
      |        ~~~~~~~~~~~~~^~~~~
      |                     |
      |                     cel::Kind
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc:150:21: error: could not convert 'cel::Kind::kInt' from 'cel::Kind' to 'google::api::expr::runtime::CelValue::Type'
  150 |   case ::cel::Kind::kInt:
      |        ~~~~~~~~~~~~~^~~~
      |                     |
      |                     cel::Kind
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc:152:21: error: could not convert 'cel::Kind::kUint' from 'cel::Kind' to 'google::api::expr::runtime::CelValue::Type'
  152 |   case ::cel::Kind::kUint:
      |        ~~~~~~~~~~~~~^~~~~
      |                     |
      |                     cel::Kind
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc:154:21: error: could not convert 'cel::Kind::kDouble' from 'cel::Kind' to 'google::api::expr::runtime::CelValue::Type'
  154 |   case ::cel::Kind::kDouble:
      |        ~~~~~~~~~~~~~^~~~~~~
      |                     |
      |                     cel::Kind
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc:156:21: error: could not convert 'cel::Kind::kString' from 'cel::Kind' to 'google::api::expr::runtime::CelValue::Type'
  156 |   case ::cel::Kind::kString:
      |        ~~~~~~~~~~~~~^~~~~~~
      |                     |
      |                     cel::Kind
external/com_github_bufbuild_protovalidate_cc/buf/validate/internal/constraints.cc:158:21: error: could not convert 'cel::Kind::kBytes' from 'cel::Kind' to 'google::api::expr::runtime::CelValue::Type'
  158 |   case ::cel::Kind::kBytes:
      |        ~~~~~~~~~~~~~^~~~~~
      |                     |
      |                     cel::Kind
Target //:public_gateway failed to build
INFO: Elapsed time: 4.181s, Critical Path: 3.63s
INFO: 7 processes: 7 internal.
FAILED: Build did NOT complete successfully

Steps to Reproduce

  1. Added this to my WORKSPACE file:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "com_github_bufbuild_protovalidate_cc",
    sha256 = "6a111c0dd50794d9f0e1ee08fced2da705f144634c38cb44bf169b067dcdf9a6",
    strip_prefix = "protovalidate-cc-0.1.0",
    urls = [
        "https://github.com/bufbuild/protovalidate-cc/archive/v0.1.0.tar.gz",
    ],
)
load("@com_github_bufbuild_protovalidate_cc//bazel:deps.bzl", "protovalidate_cc_dependencies")
protovalidate_cc_dependencies()
  1. Copied the example Envoy filter to a new directory named "protovalidate", updated includes accordingly, and added this build dependency to the filter_lib target: "@com_github_bufbuild_protovalidate_cc//buf/validate:validator".
  2. Ran the existing build command bazel-6.1.2 build --disk_cache=/bazel-cache --repository_cache=/bazel-repo-cache //:public_gateway

Expected Behavior

Build succeeds.

Actual Behavior

Build fails (see error above).

Screenshots/Logs

See above.

Environment

Possible Solution

I see that enable_regex_precompilation exists, and has for a while, so I don't have an explanation for that error.

I think I understand the other errors, on some level - comparing two different enum types does seem like something that might cause build errors in a stricter mode - and maybe building protovalidate-cc via bazel/http_archive from a project with its own C++ config is affecting how the C++ compiler gets invoked, because protovalidate-cc's build configuration isn't fully encapsulated?

Additional Context

rofrankel commented 10 months ago

For posterity, @Alfus and I chatted about this on Slack (thanks Alfred!) and this isn't a protovalidate-cc bug, it's an issue with our using a slightly earlier version of Envoy that depends on an different version of https://github.com/google/cel-cpp that's incompatible with protovalidate, plus the fact that protovalidate loads its cel-cpp dependency with maybe, which means it doesn't load it if any version of cel-cpp (even an incompatible one) is present. (This is a Bazel limitation, not something protovalidate can really fix.)

I think the "right" solution probably involves Bzlmod. Short term workarounds we discussed include A) upgrading our Envoy dependency (which hopefully depends on a compatible version of cel-cpp); or B) locally modifying protovalidate-cc to use the same version of cel-cpp as our current Envoy version, then creating a patch file representing those modifications, and having Bazel apply that patch when it pulls in the protovalidate dependency.