-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Feature request: Provide full path to go binary via an environment variable #4138
Comments
Since this appears to be a very special case, how about adding a Go SDK to the runfiles of your tests and then passing its That's something you can do without requiring a rules_go change. Even if we wanted to, we couldn't just ship a full Go SDK with every test without regressing performance for everyone. |
@fmeum thanks but apologize in advance that I'm not sure how to achieve what you suggested.
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
name = "go_sdk",
sdks = {
"darwin_amd64": (
"go%s.darwin-amd64.tar.gz" % GO_VERSION,
GO_DARWIN_AMD64_SHA256,
),
"darwin_arm64": (
"go%s.darwin-arm64.tar.gz" % GO_VERSION,
GO_DARWIN_ARM64_SHA256,
),
"linux_amd64": (
"go%s.linux-amd64.tar.gz" % GO_VERSION,
GO_LINUX_AMD64_SHA256,
),
},
urls = [
"https://go.dev/dl/{}",
"https://dl.google.com/go/{}",
# TODO: Add an internal mirror here
],
version = GO_VERSION,
) |
@fishy Yes, adding the SDK target to
You can check available targets with Also potentially relevant for you:
|
@dzbarsky thanks for the help. I think I got the files from (files under
so my attempt of using |
I do see the go sdk files under
also I'm wondering if there's an arg to |
Instead of just the label, set the environment variable to |
You can also use the --sandbox_debug flag to keep the rest sandbox around after the run |
Thanks @fmeum & @dzbarsky , that worked (at least for local worker, it might have issues with remote workers since all the files under runfiles from |
Excellent! If you're on Linux, you can try to enable the hermetic-sandbox, which will hardlink files instead of symlink. It should be a decent proxy for RBE though the details depend on your exact RBE setup. |
is |
What version of rules_go are you using?
0.50.1
What version of gazelle are you using?
0.39.0
What version of Bazel are you using?
7.3.2
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
linux/amd64
Any other potentially useful information about your toolchain?
What did you do?
For reasons, we have an internal library that heavily depends on go binary (it runs go commands via
os/exec
, etc.). In its provided test lib, when setting up a test it also depends on the go binary to do the setup.Without bazel, it could just assume
go
is in$PATH
and run it blindly. But with bazel that assumption is broken and it needs to know where to find thego
binary. This isn't a problem when developers run unit tests locally because we can still assume they havego
in$PATH
even if they run bazel to build/test locally, but it's a problem for CI because on CI we use a bazel based docker image withoutgo
in$PATH
.Thus why it would be great if rules_go can inject that info via some environment variable, so it can gets that info via env var (only needed in tests if we don't want to inject it everywhere).
I tried to check whether go toolchain itself does this, with test code to print everything from
os.Environ
, and found out that$_
would be pointing to the go binary when runninggo test
.e.g. With this test code:
via
go test
it prints out:but via
bazel test :test_test
it prints out something else:What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: