cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.11k stars 3.81k forks source link

Unable to work on local repository version of gogo-protobuf #108592

Open salemmohammed opened 1 year ago

salemmohammed commented 1 year ago

Describe the problem

I would like to create a local repository for gogo-protobuf instead of working with the remote version available at https://github.com/gogo/protobuf.

To Reproduce

What did you do? Describe in your own words.

If possible, provide steps to reproduce the behavior:

1- After forking the Cockroach GitHub repository, I successfully built and ran it on my local MacBook Pro. 2- I also forked the repository at https://github.com/gogo/protobuf. 3- echo 'build --override_repository=com_github_gogo_protobuf=/Users/salemalqahtani/Desktop/src/Juicer/salemdis/protobuf' >> .bazelrc.user 4- Inside the /Users/salemalqahtani/Desktop/src/Juicer/salemdis/protobuf, I completed the following tasks: 1- Create an empty WORKSPACE file. 2- gazelle -go_prefix=github.com/salemmohammed/protobuf -repo_root=. (This resulted in a BUILD.bazel file being generated in every directory.) 3- bazel clean --expunge 4- bazel run //:gazelle 5- ./dev build

The error after step five:

ERROR: /private/var/tmp/_bazel_salemalqahtani/076832ea6f24c2ac9a2f0c64b3726f59/external/com_github_gogo_protobuf/jsonpb/BUILD.bazel:3:11: no such target '@com_github_gogo_protobuf//types:go_default_library': target 'go_default_library' not declared in package 'types' defined by /private/var/tmp/_bazel_salemalqahtani/076832ea6f24c2ac9a2f0c64b3726f59/external/com_github_gogo_protobuf/types/BUILD.bazel and referenced by '@com_github_gogo_protobuf//jsonpb:jsonpb'

Can you please help me? Thanks all!

Jira issue: CRDB-30536

blathers-crl[bot] commented 1 year ago

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I was unable to automatically find someone to ping.

If we have not gotten back to your issue within a few business days, you can try the following:

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

salemmohammed commented 7 months ago

I am still looking for help.

rickystewart commented 7 months ago

The easiest way to do this by far is to follow the advice from the comment at the top of DEPS.bzl. The downside of doing it this way is that you need to do a commit and update DEPS.bzl every time you want to test your code. However, doing it this way means you don't have to perform all the following steps. If you must do it manually, then this works for me:

  1. bazel build gazelle
  2. echo build --override_repository=com_github_gogo_protobuf=$PATH_TO_REPO' >> .bazelrc.user
  3. In the gogo/protobuf fork, touch WORKSPACE
  4. Populate top-level BUILD.bazel appropriately:
    echo '# gazelle:prefix github.com/gogo/protobuf
    # gazelle:go_naming_convention import
    # gazelle:proto disable_global
    # gazelle:exclude test/**
    # gazelle:exclude protoc-gen-gogo/testdata/**' > BUILD.bazel
  5. Run gazelle: BUILD_WORKSPACE_DIRECTORY=$PWD ../../cockroachdb/cockroach/_bazel/bin/gazelle (Here I use the gazelle from step 1)
  6. Apply the patch from build/patches/com_github_gogo_protobuf.patch
  7. Finally, run dev build
salemmohammed commented 7 months ago

@rickystewart Thank you so much for your reply.

I am in a step five and I typed gazelle: BUILD_WORKSPACE_DIRECTORY=$PWD ../juicer-crdb/_bazel/bin/gazelle and it gave an error. -bash: gazelle:: command not found Then, I tried bazel build BUILD_WORKSPACE_DIRECTORY=$PWD ../juicer-crdb/_bazel/bin/gazelle and I got INFO: Invocation ID: cf43d84b-e1ef-489e-8abd-f5fda808a3aa ERROR: Skipping '../juicer-crdb/_bazel/bin/gazelle': invalid target name '../juicer-crdb/_bazel/bin/gazelle': target names may not contain up-level references '..' ERROR: invalid target name '../juicer-crdb/_bazel/bin/gazelle': target names may not contain up-level references '..' INFO: Elapsed time: 0.335s INFO: 0 processes. ERROR: Build did NOT complete successfully Can you please elaborate on step 5? Thanks.

salemmohammed commented 7 months ago

Hi Ricky, I left you a comment if possible to help me.

https://github.com/cockroachdb/cockroach/issues/108592

Thank you so much for your help!

Sincerely Salem

Message ID: @.***>

rickystewart commented 7 months ago

I am in a step five and I typed gazelle: BUILD_WORKSPACE_DIRECTORY=$PWD ../juicer-crdb/_bazel/bin/gazelle and it gave an error. -bash: gazelle:: command not found

Sorry for the confusion. This is not the command I recommended you run. I did:

BUILD_WORKSPACE_DIRECTORY=$PWD ../../cockroachdb/cockroach/_bazel/bin/gazelle

The gazelle: part was not part of the command. It was part of the prose of my comment. Of course you need to choose the right path depending on where your cockroach checkout is.

salemmohammed commented 7 months ago

@rickystewart

I got the following after running BUILD_WORKSPACE_DIRECTORY=$PWD ../juicer-crdb/_bazel/bin/gazelle

grep: MANIFEST: No such file or directory ../juicer-crdb/_bazel/bin/gazelle: warning: could not locate GOROOT used by rules_go grep: MANIFEST: No such file or directory error: could not locate gazelle binary

Can you please help me with this? Thank you so much.

rickystewart commented 7 months ago

I don't know what that error message means. But it seems like you have gazelle installed globally, so you can just use that instead of that using the one from cockroach. If you don't have it installed globally, you can do go install github.com/bazelbuild/bazel-gazelle/cmd/gazelle@latest

salemmohammed commented 7 months ago

Thank you @rickystewart, Local did not work with me. I chose to go with the remote repo.

I followed the instructions in the CRDB repository's DEPS.bzl file to specify a custom fork of the github.com/gogo/protobuf dependency in my Bazel build configuration:

go_repository(
    name = "com_github_gogo_protobuf",
    build_file_proto_mode = "disable_global",
    importpath = "github.com/gogo/protobuf",
    vcs = "git",
    remote = "https://github.com/CPI-NS/juicer-gogo-protobuf",  # Custom fork.
    commit = "1cc3248b0ac80d88fac99b869e4dc67f58d730b7",  # Custom commit.
)

After adding this configuration and cleaning the Bazel cache with bazel clean --expunge, I attempted to build the project using ./dev build short.

However, I encountered the following error:

ERROR: /Users/salemalqahtani/Desktop/src/Juicer/vchanges/juicer-crdb/pkg/build/BUILD.bazel:32:14: no such target '@com_github_gogo_protobuf//gogoproto:gogo_proto': target 'gogo_proto' not declared in package 'gogoproto' (did you mean 'gogoproto'?) defined by /private/var/tmp/_bazel_salemalqahtani/b0a221594e1d0d20dc9e1fe05bb54935/external/com_github_gogo_protobuf/gogoproto/BUILD.bazel and referenced by '//pkg/build:build_proto'

Could you please help me understand what I might be doing wrong?

Thank you.

rickystewart commented 7 months ago

It looks like you removed these two arguments to go_repository:

        patch_args = ["-p1"],
        patches = [
            "@com_github_cockroachdb_cockroach//build/patches:com_github_gogo_protobuf.patch",
        ],

You can't remove them; add them back and it should work.

salemmohammed commented 7 months ago

@rickystewart Thank you so much!

It works.