gorgeous-winter-99296
10/31/2022, 9:40 PMpex_binary
from a dep+name of entrypoint in the dep, but it doesn't seem like I can run a go_third_party_package
. Context: Want to https://github.com/kubernetes-sigs/controller-tools to generate code.hundreds-father-404
10/31/2022, 9:42 PMgo_binary
target. But that requires that you have a go_package
target with the package name set to main
, so you would essentially have first-party code that invokes the third-party code. Would that work?gorgeous-winter-99296
10/31/2022, 9:45 PMmain
package it doesn't really export anything meaningful I can use.hundreds-father-404
10/31/2022, 9:46 PMgo_binary
to point to a go_third_party_package
via the main
field?gorgeous-winter-99296
10/31/2022, 9:47 PMgo_third_party_binary
?hundreds-father-404
10/31/2022, 9:47 PMgorgeous-winter-99296
10/31/2022, 9:48 PMhundreds-father-404
10/31/2022, 9:50 PMgo_binary
is only a target you define in your BUILD file. It doesn't require you to have any specific code present. It only needs the main
field to point to a valid go_package
, which we default to the same directory of the BUILD file
I'm suggesting that we loosen the main
field to either point to a go_package
or go_third_party_package
. So, you woulndn't need to auto-generate anything 🙂 Only add the 1-3 line target to your BUILD filegorgeous-winter-99296
10/31/2022, 9:51 PMgo_binary
hundreds-father-404
10/31/2022, 9:53 PMgo_third_party_package
like <http://github.com/controller-tools/cmd/controller-gen|github.com/controller-tools/cmd/controller-gen>
, and then you set this:
go_binary(
name="controller-tools",
main="src/go#<http://github.com/controller-tools/cmd/controller-gen|github.com/controller-tools/cmd/controller-gen>",
)
gorgeous-winter-99296
10/31/2022, 9:55 PMsrc/go#<http://github.com/controller-tools/cmd/controller-gen|github.com/controller-tools/cmd/controller-gen>
is to make it a go_binary
. package main
cannot be a dependency elsewhere.gorgeous-winter-99296
10/31/2022, 9:56 PMgo_binary
. So why not skip/automate the boilerplate?hundreds-father-404
10/31/2022, 9:58 PMgo_third_party_package
and it's expected to always be generated by go_mod
.
So, automating this would look like allowing you to directly run/package any go_third_party_package
, rather that manually defining some target. We could do that, but then we miss important fields like restartable
and output_path
, and people may try running packages that don't make sensehundreds-father-404
10/31/2022, 9:58 PMgo_binary
pointing to a go_third_party_package
? Boilerplate, or something else too?gorgeous-winter-99296
10/31/2022, 10:00 PMpackage main
and also output a go_binary
. I don't think all packages should be runnable; only those that are named main
. 🙂hundreds-father-404
10/31/2022, 10:03 PMgo_mod
generate a go_binary
target for you? Yeah we could theoretically do that, but it results in some weirdness like
a) what is the address for it, given that the package name is already claimed
b) if you want to set restartable
etc, then you now need to use overrides
, which is a little awkward/less discoverable
Either way though, the first step we'd need to do is improving go_binary
to work with go_third_party_package
. That's still a possible future improvement to auto-generate that go_binary
target from go_mod
gorgeous-winter-99296
10/31/2022, 10:06 PMgo_third_party_binary
solves that since it cannot be passed elsewhere that expects a package - the current way of writing it opens up for writing incorrect dependencies.)
2. Sure. Or manually write a go_binary rule from scratch.hundreds-father-404
10/31/2022, 10:08 PMOr manually write a go_binary rule from scratch.Yeah. Although at that point, I'd bias towards "keep it simple" and "keep it explicit", and have users write the 1-2 lines in a BUILD file. We try (but often fail) to avoid complex edge cases of "do this most the time! but if that fails, do this whole other thing"
hundreds-father-404
10/31/2022, 10:08 PMgorgeous-winter-99296
10/31/2022, 10:10 PMhundreds-father-404
10/31/2022, 10:11 PMgorgeous-winter-99296
10/31/2022, 10:12 PM