Hi, I am trying to evaluate if Pants is a good fit...
# general
h
Hi, I am trying to evaluate if Pants is a good fit for a new go monorepo I am building. One of the go binaries (not all) in my monorepo needs to be built with
GOOS=linux GOARCH=arm64 go build ...
I am unable to find a way to do this using the existing
go_binary()
target. Is this not supported? I am using Pants v2.23
g
Have you tried compiler_flags?
h
They are env vars, not compiler flags
an alternate way to do this is to run it as a
shell_command()
but I can't figure out how to make it execute the command when I call
pants package ::
g
You could try defining an environment and set go env vars for it: https://www.pantsbuild.org/dev/reference/targets/local_environment#golang_subprocess_env_vars Then set this environment on target
h
yeah, that looked promising, this is the BUILD file I attempted:
Copy code
go_package()

local_environment(
    name="lambda_arch",
    golang_subprocess_env_vars = [
        "GOOS=linux",
        "GOARCH=arm64",
    ],
)

go_binary(
    name="bootstrap",
    environment="::lambda_arch",
)
... but
pants -ldebug package ::
failed with:
Copy code
00:56:48.81 [DEBUG] Completed: Link Go binary: ./package_analyzer
00:56:48.81 [DEBUG] Completed: Scheduling: Link Go binary: ./package_analyzer
00:56:48.81 [DEBUG] Completed: Download and analyze all third-party Go packages - environment:lambda_arch
00:56:48.81 [DEBUG] Completed: Generate `go_third_party_package` targets from `go_mod` target - environment:lambda_arch
00:56:48.81 [DEBUG] Completed: Find targets from input specs
00:56:48.81 [DEBUG] Completed: `package` goal
00:56:48.81 [DEBUG] computed 1 nodes in 0.269227 seconds. there are 2086 total nodes.
00:56:48.81 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

ProcessExecutionFailure: Process 'Link Go binary: ./package_analyzer' failed with exit code 1.
stdout:

stderr:
runtime.rt0_go: relocation target runtime.tlsinit not defined
BTW - building directly with `GOOS=linux GOARCH=arm64 go build ..`works fine
g
Yeah, maybe go_binary doesn't play nice yet with environments. Could you make a minimal example that replicates this error?
h
sure - here it is
👍 1
b
Spent a little bit of time looking into this, findings: https://github.com/pantsbuild/pants/issues/21113#issuecomment-2740570833