bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 659 forks source link

Config file for gazelle #400

Closed kerinin closed 7 years ago

kerinin commented 7 years ago

We have a large repo we're using gazelle to generate build files for, and we're using multiple flags to configure gazelle. It would beer nice if we could put these arguments in a ".gazelle" file or something similar.

pmbethe09 commented 7 years ago

which flags do you use?
I envision a perfect world where gazelle uses 'bazel query' to discover what deps you have in //vendor to remove the need for the -external flag. And we are moving gazelle to just include all srcs, and have go_library be smart at compile time and determine which srcs to ignore due to arch/os.

kerinin commented 7 years ago

Currently we're using -external vendor and -build_flags linux,darwin,amd64. The former so we can use vendored dependencies and the latter so we can build both locally (on OSX) an in CI (on linux)

jayconrod commented 7 years ago

I'm not opposed to having a .gazelle file that can be checked into a repository, but it would be better if fewer command line options were necessary.

+1 to making Gazelle more aware of the vendor directory. We should default to -external vendored for local repositories if the vendor directory exists. Filed #404 to track this.

Could you tell us a bit more about how you're using build constraints? We would like Gazelle to generate platform-independent BUILD files when possible. The Go rules also apply build constraints at compile time, so you might not need Gazelle to apply them.

kerinin commented 7 years ago

Yeah, defaulting to -external vendored seems like a good idea now that vendor has become the "correct" way to vendor code.

The build constraints are so we don't get different BUILD file dependencies based on where gazelle is run. Some libraries like logrus have architecture-specific implementations, for instance this file is included when running gazelle on OSX because the darwin build flag includes it, but it's not present when running gazelle in linux. We've run into a number of cases like this were dependencies will flip back & fourth as different devs generate buildfiles.

jayconrod commented 7 years ago

Since #396 landed a few days ago, Gazelle doesn't apply build constraints unless the -build_tags is explicitly passed on the command line. It includes all files and lets the rules sort out the tags. So hopefully that flipping behavior won't happen anymore.

ianthehat commented 7 years ago

you can now add the gazelle rule to your top level build file, with all the arguments (if you need any, we are trying hard to get to the point where it just does the right thing with default settings), and it will build and run gazelle for you. This allows you to configure gazelle without adding a new config file, and allows multiple configurations. I think this is probably enough of a solution? I am closing this issue on the assumption that it is, if it does not do what you need, please feel free to reopen with more information!