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

Gazelle fails to build with 'no such package' after some dependencies got upgraded #1289

Closed
flakrimjusufi opened this issue Jun 29, 2022 · 5 comments

Comments

@flakrimjusufi
Copy link

flakrimjusufi commented Jun 29, 2022

What version of gazelle are you using?

v0.25

What version of rules_go are you using?

v0.33.0

What version of Bazel are you using?

v.5.1.1

Does this issue reproduce with the latest releases of all the above?

Yes.

What operating system and processor architecture are you using?

Linux Ubuntu 20.04.4 LTS - amd x86_64

What did you do?

Google related dependencies got upgraded in go.mod file:

cloud.google.com/go/iam v0.3.0 // indirect
cloud.google.com/go/kms v1.4.0 // indirect
cloud.google.com/go/pubsub v1.23.0 // indirect
golang.org/x/net v0.0.0-20220607020251-c690dde0001d
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
google.golang.org/api v0.84.0
google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
gocloud.dev v0.22.0

What did you expect to see?

A successful build.

What did you see instead?

ERROR:: /home/flakrim/.cache/bazel/_bazel_flakrim/4e21cc02f33d087c8327a1f6e4bda3af/external/com_google_cloud_go_pubsub/BUILD.bazel:3:11: no such package '@com_google_cloud_go//internal/pubsub': BUILD file not found in directory 'internal/pubsub' of external repository @com_google_cloud_go. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_google_cloud_go_pubsub//:pubsub'

Things I've tried so far

Researching the problem and going through open-issues from engineers that are experiencing the same issue in desperate to find a solution, I've tried the following:

- Re-structured the dependencies in WORKSPACE file as suggested in their docs so all Golang dependencies can run before gazelle dependencies 

- Moved gazelle_dependencies() in the end of the WORKSPACE file. 

- Added the following tags in google related dependencies as suggested in some open issues: 
  build_file_proto_mode = "disable",
  build_extra_args = ["-exclude=src"],
  
- Updated Bazel version from 4.0.0 to 5.1.1 

- Updated Gazelle version from 0.23.0 to 0.25 

- Updated Bazel rules version from 0.24.13 to 0.33.0 

- Updated bazelisk version from 1.11 to 1.12 

- Updated Go version from 1.16 to 1.18

- Updated grpc & google related dependencies to their latest version  

- Added the following dependencies with go get:
	- cloud.google.com/go/iam 
	- cloud.google.com/go/kms 
	- cloud.google.com/go/pubsub 

All of this in hope to resolve the problem, but I'm still seeing the same output.

What's the command that is causing this failure?

CLUSTER=$1
NAMESPACE=$2

bazelisk test \
    --platform_suffix="bazel-test" \
    --@io_bazel_rules_go//go/config:race \
    --define cluster=$CLUSTER \
    --define namespace=$NAMESPACE \
    --test_tag_filters=fast \
    --build_tag_filters=fast \
    //...

Does the build succeeds with the run commands?

Yes. I'm able to build successfully the dependencies with the following commands:

bazelisk run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:gazelle

bazelisk run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:gazelle -- update;

bazelisk run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:gazelle -- update-repos -from_file=go.mod;

NOTE

I'd also like to emphasize that I've tried everything that was available in the open-issues to get through this issue but after so many wasted hours, I thought this needs to be reported.

Possible related issues:

ASSUMPTION

I may be completely wrong in here, but I think this is happening because gazelle, rules or bazelisk is still using an old version of those google related dependencies and when one of these dependencies gets upgraded, this causes the build to fail.

That's because the upgrade may be silently ignored and Bazel still relies in this older version which doesn’t contain any feature that one of these upgraded dependencies is trying to use.

@achew22
Copy link
Member

achew22 commented Jun 29, 2022

Can you provide a sample repo that demonstrates this issue?

@achew22 achew22 closed this as completed Jun 29, 2022
@flakrimjusufi
Copy link
Author

flakrimjusufi commented Jul 1, 2022

Hey @achew22,

Thank you for the quick reply and sorry about the delay.

I've been working on creating a minimal-reproducible-project to help with the debugging. It was a little bit complicated to extract a small version of a huge project.

Anyways, here's the project I created to reproduce these issues: https://github.com/flakrimjusufi/bazel-minimal-example

While setting-up the project, I've encountered the following:

The first issue:

compilepkg: missing strict dependencies:
        /home/flakrim/.cache/bazel/_bazel_flakrim/d272cafa801fdada5fff90ad72773003/sandbox/linux-sandbox/86/execroot/__main__/external/org_golang_x_mod/module/module.go: import of "golang.org/x/xerrors"
No dependencies were provided.

Was resolved by adding this line in the WORKSPACE file:

# gazelle:repository go_repository name=org_golang_x_xerrors importpath=golang.org/x/xerrors

===============================================================================

The second issue:

Running the following command:

    bazelisk test \
        --platform_suffix="bazel-test" \
        --@io_bazel_rules_go//go/config:race \
        --action_env=TESTING=test \
        --define cluster=$CLUSTER \
        --define namespace=$NAMESPACE \
        --test_tag_filters=fast \
        --build_tag_filters=fast \
        --test_output=errors \
        --nocache_test_results \
        //...

I'm getting this output:

/home/flakrim/.cache/bazel/_bazel_flakrim/d272cafa801fdada5fff90ad72773003/external/io_bazel_rules_go/proto/wkt/BUILD.bazel:88:17: error loading package '@com_google_protobuf//': Unable to find package for @rules_python//python:defs.bzl: The repository '@rules_python' could not be resolved: Repository '@rules_python' is not defined. and referenced by '@io_bazel_rules_go//proto/wkt:field_mask_go_proto'

==============================================================================

Tried to bypass this one so I can reproduce the other issues that I mentioned above, but unfortunately I wasn't able to do so.

Please let me know if I can help you with something else to resolve this issue.

@flakrimjusufi
Copy link
Author

flakrimjusufi commented Jul 5, 2022

Can you provide a sample repo that demonstrates this issue?

Any update on this?

@cristifalcas
Copy link

why was this closed? I'm hitting the same exact issue:

ERROR: /private/var/tmp/_bazel_cfalcas/856dc74a4318774eeb1496e4c7291b94/external/com_google_cloud_go_pubsub/BUILD.bazel:3:11: no such package '@com_google_cloud_go//internal/pubsub': BUILD file not found in directory 'internal/pubsub' of external repository @com_google_cloud_go. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_google_cloud_go_pubsub//:pubsub'

@flakrimjusufi
Copy link
Author

flakrimjusufi commented Dec 7, 2022

Hey @cristifalcas,

If you are still experiencing this issue, I'd recommend you to update the bazel_gazelle to version 0.26.0.

NOTE: Since every project has a different file-structure, this might not fully resolve your issue. What you might still have to do is updating the goolge-related dependencies and potentially some spf13 dependencies but I can show you a list of the dependencies that I've updated and their current version that resolved the issues I was having:

google.golang.org/grpc v1.47.0
google.golang.org/api v0.84.0
google.golang.org/protobuf v1.28.0
github.com/spf13/afero v1.8.1
github.com/spf13/viper v1.10.1

I hope to have helped you a bit.
Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants