pants icon indicating copy to clipboard operation
pants copied to clipboard

[WIP] go: add "pure" field to go_binary to disable cgo when set

Open tdyas opened this issue 1 year ago • 1 comments

Add a pure field to go_binary which disables cgo when set. I.e., the binary is built "purely" with Go sources.

Introduces GoBuildContext to carry build-related options like whether to permit cgo or not (and eventually compiler flags to use etc.)

[ci skip-rust]

[ci skip-build-wheels]

tdyas avatar Sep 13 '22 01:09 tdyas

Rule graph error: foo.log

@stuhood: I'm trying to use the multi-parameter selector syntax. Am I using it correctly? Is there a preferred way to have a build context like I do in this PR?

tdyas avatar Sep 13 '22 01:09 tdyas

Why didn't the engine make use of the rule providing GoBuildContext then?

@rule
async def go_global_context(golang_subsystem: GolangSubsystem) -> GoBuildContext:
    return GoBuildContext(cgo_allowed=golang_subsystem.cgo_allowed)

tdyas avatar Oct 05 '22 15:10 tdyas

Why didn't the engine make use of the rule providing GoBuildContext then?

@rule
async def go_global_context(golang_subsystem: GolangSubsystem) -> GoBuildContext:
    return GoBuildContext(cgo_allowed=golang_subsystem.cgo_allowed)

Hm... maybe it would: sorry, I missed that. Try with only the second edit?

But I will say: having a singleton like that as well as a parameter that you're expecting to be propagated seems pretty error prone: it seems fairly likely to forget to pass the override and get a default instead. I'd suggest removing the singleton, explicitly initializing (without a rule) and passing it down instead.

stuhood avatar Oct 05 '22 16:10 stuhood

Closing in favor of https://github.com/pantsbuild/pants/pull/17475.

tdyas avatar Nov 08 '22 23:11 tdyas