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

Unable to use golang.org/x/exp/slog with bzlmod #3578

Closed
Sovietaced opened this issue Jun 2, 2023 · 2 comments
Closed

Unable to use golang.org/x/exp/slog with bzlmod #3578

Sovietaced opened this issue Jun 2, 2023 · 2 comments

Comments

@Sovietaced
Copy link
Contributor

Sovietaced commented Jun 2, 2023

What version of rules_go are you using?

0.39.1

What version of gazelle are you using?

0.30.0

What version of Bazel are you using?

6.2

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

Yes

What operating system and processor architecture are you using?

x86 Ubuntu

What did you do?

I tried to use slog which is an experimental package.

package main

import "golang.org/x/exp/slog"

func main() {
	slog.Info("Go is best language!")
}

What did you expect to see?

I would expect slog to work just like any other part of the standard library.

What did you see instead?

I am not able to use slog a project is configured using bzlmod. Sample project: https://github.com/Sovietaced/rules_go_issue

jparraga@U-1DJORH1PD9VGC:~/code/rules_go_issue$ bazel build ...
ERROR: /home/jparraga/code/rules_go_issue/BUILD.bazel:12:11: no such package '@[unknown repo 'org_golang_x_exp' requested from @]//slog': The repository '@[unknown repo 'org_golang_x_exp' requested from @]' could not be resolved: No repository visible as '@org_golang_x_exp' from main repository and referenced by '//:rules_go_issue_lib'
ERROR: Analysis of target '//:rules_go_issue_lib' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.138s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (2 packages loaded, 2 targets configured)

This error message implies that the repository has not been added, so once I do add the repository I get this error.

jparraga@U-1DJORH1PD9VGC:~/code/rules_go_issue$ bazel build ...
ERROR: Analysis of target '//:rules_go_issue_lib' failed; build aborted: module extension "go_deps" from "@gazelle~0.30.0//:extensions.bzl" does not generate repository "org_golang_x_exp", yet it is imported as "org_golang_x_exp" in the usage at <root>/MODULE.bazel:11:24 (did you mean 'org_golang_x_text'?)
INFO: Elapsed time: 1.318s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (63 packages loaded, 353 targets configured)

In a separate project with a lot more dependencies I get the following error:

ERROR: <redacted>/BUILD.bazel:3:11: no such package '@org_golang_x_exp//slog': BUILD file not found in directory 'slog' of external repository @org_golang_x_exp. Add a BUILD file to a directory to mark it as a package. and referenced by '<redacted>'

This error seems to be similar to bazel-contrib/bazel-gazelle#1468 but I'm unsure how to solve it since I'm using bzlmod instead.

@fmeum
Copy link
Member

fmeum commented Jun 2, 2023

Your go.mod doesn't list any dependencies, in particular not on golang.org/x/exp. After adding "org_golang_x_exp" to use_repo and running bazel run @rules_go//go -- get golang.org/x/exp, the build passes.

Hope that helped, please reopen if the issue persists.

@fmeum fmeum closed this as completed Jun 2, 2023
@Sovietaced
Copy link
Contributor Author

Hope that helped, please reopen if the issue persists.

Thanks that worked. On the example project I did later get a prompt to modify my go.mod but for some reason never got that prompt on the larger project I'm working on. I thought maybe it didn't have to be imported since it could have been part of the standard library. Regardless, it works in both cases so thank you.

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

2 participants