-
-
Notifications
You must be signed in to change notification settings - Fork 687
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
How do I instruct the go_sdk to use the version specified in go.mod
?
#4292
Comments
The default Go SDK is downloaded hermetically, but it currently defaults to a version specified per rules_go release (see rules_go's MODULE.bazel file). Extending Go SDK with a |
OK so calling
Then it should call the Does that sound correct? |
Yes, except that we should use the version we read from the file for the |
This change copies parts of the `go_mod.bzl` parser from the Gazelle repository: https://github.com/bazel-contrib/bazel-gazelle/blob/master/internal/bzlmod/go_mod.bzl A test based on the `go_download_sdk` test sets up a repo with a `go.mod` and checks that the version specified in it is used to run the test in that repo-under-test. Fixes bazel-contrib#4292
I have gotten most of the way there but I'm having trouble with the last step. Can you please take a look at jaqx0r@3c7ed95 and advise me how I should be overriding the default sdk? In my test, the version reported is not the one I am expecting.
and the
|
@fmeum Could you take a look at the commit above please, when you get a moment, and point me in the right direction? |
Now that I think about it, you probably don't need to actually replace But I would recommend to move the logic above the handling of the |
Thanks @fmeum. I'm still missing something though, because now it looks like I correctly set the I've uploaded a new commit, with some extra debug statements printing out state. master...jaqx0r:rules_go:from-go-mod-file with the test output:
and the content of the inner test's log:
So you can see in extensions.bzl:176 we've correctly read the toolchain 1.24.1 from the go.mod in test. The full set of toolchains then printed out has our But when the inner test executes, it's runtime is reported as |
Curiously, this is working correctly when I use in
at the top of
then
looks promising
and changing the
which is pretty conclusive to me. So I've definitely messed up the test. I suspect it's because I've set it up as a bzlmod workspace, and the
which really looks like the Go SDK from the |
Some more spelunking in the innards of the test sandbox with
I copied what |
This change copies parts of the `go_mod.bzl` parser from the Gazelle repository: https://github.com/bazel-contrib/bazel-gazelle/blob/master/internal/bzlmod/go_mod.bzl A test based on the `go_download_sdk` test sets up a repo with a `go.mod` and checks that the version specified in it is used to run the test in that repo-under-test. Fixes bazel-contrib#4292
I have a new dependency in a project, which has a toolchain dependency higher than the local toolchain.
When I run
bazel run //rules_go:go -- mod tidy
I get:The go.mod file contains this at the top:
The hint is
GOTOOLCHAIN=local
in the error.I haven't set an explicit toolchain in
MODULE.bazel
because I assumed it would figure it out fromgo.mod
:I expected the default behaviour to be hermetic, that is I would not be using the system Go SDK. BUt even that doesn't make sense:
so wherever this
running go 1.22.7; GOTOOLCHAIN=local
is coming from, I don't know.The go version is supposed to be defined in
go.mod
so how can I make thego_sdk.download
call inMODULE.bazel
read this fromgo.mod
so I don't have to repeat myself?The text was updated successfully, but these errors were encountered: