Giter Club home page Giter Club logo

Comments (6)

linzhp avatar linzhp commented on May 29, 2024 1

but I was hoping to make it work in more bazel-native way...
With standard go toolchain, and go.env file, it is easy to set all the env vars in one place.

I found these two requirements contradicting. Bazel doesn't use the go command from Go toolchain to compile and link. So even with what @fmeum did in #3879, the envs only affects the go command, not the compilation and linking.

In fact, I am worried that go_sdk.config(go_env = {...}) gives users a false impression that they can control compilation and linking by setting things likeCGO_CFLAGS or GOOS there.

So I think the "bazel-native way" is to set the envs in different ways than Go:

  • GOPROXY can potentially be set with gazelle_dependencies(go_env = ...) like @fmeum in #3879, but we found it working well to set it in Bazel wrapper (e.g. tools/bazel)
  • GOOS is set with --platforms
  • CXX, CC should be the C toolchain resolved by Bazel
  • GOFLAGS should be set from --@io_bazel_rules_go//go/config:gc_goopts
  • This goes on and on...

What I am trying to say is Bazel and Go are two fundamentally different build systems. The behavior of Go build is controlled by env vars, but Bazel prefers configuration files and command line flags.

from rules_go.

alexbozhenko avatar alexbozhenko commented on May 29, 2024

Another thought after looking at golang/go@7aa85e0

Should go_register_toolchains just allow to specify go.env file?
https://github.com/bazelbuild/rules_go/blob/master/go/toolchains.rst#go-register-toolchains
Maybe #3401 should be further generalized to all go env vars?

from rules_go.

fmeum avatar fmeum commented on May 29, 2024

Should go_register_toolchains just allow to specify go.env file?

This was actually my first thought as well, but I now see undesirable side effects: The env variables one typically wants to set affect the fetches of dependencies, but not the compilation of .go code itself. If we add these variables to the go.env of the Go SDK, they will be an input to compilation actions and thus affect cache hits.

Instead, we can forward the variables to only the two places related to dependency fetching: @rules_go//go and go_repository.

from rules_go.

alexbozhenko avatar alexbozhenko commented on May 29, 2024

@fmeum:
https://pkg.go.dev/cmd/go#hdr-Environment_variables
lists all possible variables, and it seems like is not just about fetches of dependencies.
With standard go toolchain, and go.env file, it is easy to set all the env vars in one place.

But with Bazel some of them can be set by these settings:
https://github.com/bazelbuild/rules_go/blob/master/go/modes.rst#build-settings

Some are chosen for you by rules_go for you:
https://github.com/bazelbuild/rules_go/blame/55ea579a70958d66f24a907433978b21edd36b29/go/private/sdk.bzl#L491

So maybe allowing to specify all env vars in a single place will ease the mental load of users?

from rules_go.

fmeum avatar fmeum commented on May 29, 2024

@linzhp makes a very good point. I will change the name of the go_env attribute to something like go_fetch_env to make it clear that build-related env vars won't be read.

from rules_go.

fmeum avatar fmeum commented on May 29, 2024

I submitted bazelbuild/bazel-gazelle#1748 instead, which moves the new go_env field to go_deps, hopefully making it more clear that this is only targetted at fetching of Go deps. What do you think?

from rules_go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.