Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

//src/google/protobuf/json:parser depends on @com_google_googletest//:gtest_main #11409

Closed
monkeynova opened this issue Dec 26, 2022 · 3 comments

Comments

@monkeynova
Copy link

//src/google/protobuf/json:parser is a library (and transitively included in //:protobuf). This means any attempt to link with //:protobuf brings in an implementation of main which could be called instead of the caller's main.

The chain I see in my local repository (where I'm having the incorrect main called) is

... local dependencies...
@com_google_protobuf//:protobuf
@com_google_protobuf//src/google/protobuf/util:json_util
@com_google_protobuf//src/google/protobuf/json:json
@com_google_protobuf//src/google/protobuf/json:parser
@com_google_googletest//:gtest_main
@com_google_googletest//:googlemock/src/gmock_main.cc

This is the location of the dependency I think is in error: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/json/BUILD.bazel#L197

@monkeynova monkeynova added the untriaged auto added to all issues by default when created. label Dec 26, 2022
@deannagarcia
Copy link
Member

I need more information to help diagnose this. Please fill out our bug template form with how you're building, where you are running this, and the exact error logs you see.

In general, we have many other dependencies on gtest_main that we haven't seen any issues with.

@deannagarcia deannagarcia removed the untriaged auto added to all issues by default when created. label Dec 27, 2022
@monkeynova
Copy link
Author

I'm happy to fill out the template if that helps you, but I believe that any library that depends on :gtest_main is a bug (even if it happens to work in some circumstances) since it would include multiple definitions of main during linking.

What version of protobuf and what language are you using?
Version: main/v3.6.0/v3.5.0 etc. (NOTE: please try updating to the latest version of protoc/runtime possible beforehand to attempt to resolve your problem)
Language: C++

What operating system (Linux, Windows, ...) and version?
OSX (10.15.7), Linux (5.15.74-v8+)

What runtime / compiler are you using (e.g., python version or gcc version)
llvm (OSX), gcc (Linux)

What did you do?
Steps to reproduce the behavior:
Test ://github.com/monkeynova/logic-solver
bazelisk test //sudoku:single_line_test
Works - as in all tests pass.
Update WORKSPACE to point commit including the new dependency (32bea52)
perl -spi -e 's/66ed6dd75b0b5f0d62a9bf90509638f380cbcd7f/15dff733cf40d6ecdac8b66d5202bb23dd125d43/g' WORKSPACE
Test ://github.com/monkeynova/logic-solver.git
bazelisk test //sudoku:single_line_test

  • Fails* - (tests use gtest_main rather than the main I've intended to link which behaves similarly, see details below...)

What did you expect to see
I expect when I link a library to not have an implementation of main included

What did you see instead?
A main other than the one I authored was called by the system

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Failure test log (head)

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //sudoku:single_line_test
-----------------------------------------------------------------------------
Running main() from gmock_main.cc
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from Puzzle
[ RUN      ] Puzzle.RightAnswer

Success test log (head)

darwin-opt/testlogs/sudoku/single_line_test/test.log
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //sudoku:single_line_test
-----------------------------------------------------------------------------
InitMain(/private/var/tmp/_bazel_keith/7aeb99f7f348857a60e16b07cad11c5b/sandbox/darwin-sandbox/715/execroot/com_monkeynova_logic_solver/bazel-out/darwin-opt/bin/sudoku/single_line_test.runfiles/com_monkeynova_logic_solver/sudoku/single_line_test)
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from Puzzle

@johanbrandhorst
Copy link
Contributor

In release v3.22.0 (or v4.22.0?) this is causing a build error in the grpc-gateway:

ERROR: /home/vscode/.cache/_grpc_gateway_bazel/external/com_google_protobuf/src/google/protobuf/json/BUILD.bazel:199:11: no such package '@com_google_googletest//': The repository '@com_google_googletest' could not be resolved: Repository '@com_google_googletest' is not defined and referenced by '@com_google_protobuf//src/google/protobuf/json:parser'

Full testlog.

I've worked around it by adding com_google_googletest as a dependency in my WORKSPACE, but it doesn't look to me like this was mentioned in the release notes.

mkruskal-google pushed a commit to mkruskal-google/protobuf that referenced this issue Mar 20, 2023
…_google_googletest//:gtest_main from //src/google/protobuf/json:parser (protocolbuffers#12267)

Downstream bazel projects that depend on protoc would need to provide googletest dependencies when it should not be necessary to do so.

Fixes protocolbuffers#11409

Closes protocolbuffers#12267

COPYBARA_INTEGRATE_REVIEW=protocolbuffers#12267 from prestonvanloon:remove-erroneous-googletest-dep 09fd163
PiperOrigin-RevId: 517974450
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants