bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 659 forks source link

go_repository fails to generate BUILD files for certain Go dependencies #3259

Open Nickersoft opened 2 years ago

Nickersoft commented 2 years ago

What version of rules_go are you using?

0.34.0

What version of gazelle are you using?

0.26.0

What version of Bazel are you using?

5.2.0

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

Yes

What operating system and processor architecture are you using?

OS Version: macOS System Version: 12.3.1 Build Version: 21E258 Architecture: ARM (M1)

What did you do?

  1. Ran bazel run gazelle and bazel run update-repos
  2. Attempted to build a Go target
  3. Received BUILD file not found in directory '' of external repository @com_github_rivo_uniseg. Add a BUILD file to a directory to mark it as a package.

This error is reproducible if you check out my open source repo, switch over to the nickersoft/final branch, and run bazel build go. You'll notice that the generated Go repository it is mentioning does not contain a BUILD file, which is causing the error. The only similar issue I have found to this is this one, though the fixes over there don't seem to work for me.

Additional Info

The full error is:

ERROR: /private/var/tmp/_bazel_tjnickerson/6f441a2e0b83f1b25dbd79b8c892f6eb/external/com_github_mattn_go_runewidth/BUILD.bazel:3:11: no such package '@com_github_rivo_uniseg//': BUILD file not found in directory '' of external repository @com_github_rivo_uniseg. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_github_mattn_go_runewidth//:go-runewidth'
ERROR: Analysis of target '//bridge:bridge' failed; build aborted: no such package '@com_github_rivo_uniseg//': BUILD file not found in directory '' of external repository @com_github_rivo_uniseg. Add a BUILD file to a directory to mark it as a package.

The referencing target:

image

The com_github_rivo_uniseg directory, that contains a WORKSPACE but no BUILD files:

image

What did you expect to see?

I expected everything generated by Gazelle to work out-of-the-box, without having to create my own BUILD files.

What did you see instead?

The above error lol

hawkingrei commented 2 years ago

I meet it too.

connerqyang commented 2 years ago

Also running into this issue as well (for a project using carvel tools that imports this library), so an indirect dependency is causing this on my end.

ERROR: /root/.cache/bazel/_bazel_root/2e020ad50777956f5c6b506427fe5ab3/external/com_github_mattn_go_runewidth/BUILD.bazel:3:11: no such package '@com_github_rivo_uniseg//': BUILD file not found in directory '' of external repository @com_github_rivo_uniseg. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_github_mattn_go_runewidth//:go-runewidth' ERROR: Analysis of target '//scripts/tcxctl:tcxctl' failed; build aborted: Analysis failed INFO: Elapsed time: 25.115s INFO: 0 processes. FAILED: Build did NOT complete successfully (768 packages loaded, 5363 targets configured) Fetching @io_k8s_helm; fetching 17s Fetching @com_github_docker_cli; fetching 10s Fetching @com_github_docker_docker; fetching 10s Fetching @com_github_azure_azure_sdk_for_go; fetching 8s Fetching @com_github_gregjones_httpcache; fetching Fetching @com_github_masterminds_goutils; fetching Fetching @com_github_lann_ps; fetching

hawkingrei commented 2 years ago

We add a patch to this dependency. It can work.

connerqyang commented 2 years ago

We add a patch to this dependency. It can work.

I encountered this issue earlier today, do you mean there's been a fix since then? That commit/patch looks to be from 8 days ago.

hawkingrei commented 2 years ago

We add a patch to this dependency. It can work.

I encountered this issue earlier today, do you mean there's been a fix since then? That commit/patch looks to be from 8 days ago.

It just changed the bazel build file for com_github_rivo_uniseg which generated by gazelle. The best fix method is to fix the behavior of the gazelle.

connerqyang commented 2 years ago

patch

Sorry I'm a bit confused. I'm still getting the same error that I pasted above that the BUILD file was not found in directory '' of external repository @com_github_rivo_uniseg. However, the patch you linked implies that BUILD file exists.

Could you help clear up my confusion? Thanks

archit-bedrock commented 1 year ago

Was this issue ever resolved? I'm still seeing this error on my end -

ERROR: /home/ubuntu/.cache/bazel/_bazel_ubuntu/3bfad932a61b6ec3a65186104844629d/external/com_github_mattn_go_runewidth/BUILD.bazel:3:11: no such package '@com_github_rivo_uniseg//': BUILD file not found in directory '' of external repository @com_github_rivo_uniseg. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_github_mattn_go_runewidth//:go-runewidth'

Any help would be greatly appreciated!

jayakasadev commented 10 months ago

@archit-bedrock did you manage to fix your issue?

archit-bedrock commented 10 months ago

@archit-bedrock did you manage to fix your issue?

No I don't think I was able to fix it.

jayakasadev commented 10 months ago

@archit-bedrock was there a workaround for you or did you have to use something else?

jayakasadev commented 10 months ago

in case someone circles back: using gazelle 0.33.0 fixed this for me

the newer versions require golang.org/x/tools > 0.10.0 which for some reason breaks update-repos