-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
deps attribute should not use select #1600
Comments
The reason Your proposal is interesting. That would let us filter dependencies during the analysis phase. So we could avoid building the wrong dependencies (which leads to errors), but we'd still need to fetch and analyze (which just leads to slower builds). This would be compatible with the aspect though (which leads to more correct builds). I'd rather not implement this because I think we should wait for Bazel to support transitions in Skylark. The latest proposal for that is Skylark Build Configuration. The reason we support mode attributes on The proposal above isn't finalized, and I'm sure it's at least a few months away from being implemented. Once it is implemented though, I hope we'll be able to deprecate several of the mode attributes (at least the attributes that would affect dependency selection). |
Thank you Jay for your erudite response. You are right in saying when such a thing will be useful, and also right in saying that this should wait for the proposed features in bazel. Our multiplatform build use case is to build and push docker images of our binaries such that the tag of the image derived from a status variable, is stamped into another binary through a x_def attribute. If the other binary is being built for anything other than Linux, we have to set goos as linux for the binaries being packaged into docker images. We manage right now by forcefully (#keep in gazelle) repeating the dependencies such that they are the same for all platforms. Having some filtering in skylark instead would have saved us from building the deps unnecessarily, and also kept gazelle happier. It's not a terrible hack and I am happy that at least it's possible because you have the mode attributes. Can certainly wait for a proper support from bazel. Thank you again. |
Just a quick question on this topic. We are trying to move from govendor to Go modules, and that means manually editing gazelle generated BUILD files is not so simple anymore. Is there a way to tell gazelle to not use these select statements and simply include all dependencies in a build? I tried giving -build_tags=linux but that had no effect on the BUILD files. |
@siddharthab There's no way to do this in Gazelle right now. Doing so would likely lead to broken builds, since you'd be unconditionally depending on targets that may be unbuildable for your target platform. I do have a bit of good news though: most (possibly all?) of the functionality we need from Starlark Build Configuration is now has merged in Bazel. I need to confirm a design with the Bazel folks and check when all this is released, but we're closer to having working |
Thank you! |
Closing in favor of #2219 |
bazel's traditional use of command line flags for host and target cpu as global configuration values is not something that go has to limit itself to. As such, the select statement is not a good way of filtering out deps.
go_binary already has a way of specifying goos and goarch, which is then percolated all the way down to stdlib. Instead of specifying deps as a flat list, go_library should use a map of build constraints to deps, and then do the filtering in skylark based on the active build constraints.
A rollout plan could be to allow both types of deps specification, preferring the map over the list, and then slowly phase out the list. gazelle can start output a map by default once rules_go is ready.
The text was updated successfully, but these errors were encountered: