Skip to content

Commit

Permalink
go: add environment field to go_binary (pantsbuild#18113)
Browse files Browse the repository at this point in the history
Add an `environment` field to `go_binary` so that Go binaries can users can at least attempt to build binaries in a non-local environment.

Fixes pantsbuild#18115

Note: There is still [a bug with dependencies for the Go SDK](pantsbuild#18114) differing between the local and non-local environments due to condition compilation changing imports. (For example, the `runtime` package in the Go SDK only imports `runtime/internal/syscall` on Linux but not macOS.) This PR does not attempt to fix the bug, which will be fixed in a subsequent PR.
  • Loading branch information
tdyas authored Jan 29, 2023
1 parent 5580f80 commit ddf3543
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/python/pants/backend/go/goals/package_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PackageFieldSet,
)
from pants.core.goals.run import RunFieldSet, RunInSandboxBehavior
from pants.core.util_rules.environments import EnvironmentField
from pants.engine.fs import AddPrefix, Digest
from pants.engine.internals.selectors import Get, MultiGet
from pants.engine.rules import collect_rules, rule
Expand All @@ -38,6 +39,7 @@ class GoBinaryFieldSet(PackageFieldSet, RunFieldSet):

main: GoBinaryMainPackageField
output_path: OutputPathField
environment: EnvironmentField


@rule(desc="Package Go binary", level=LogLevel.DEBUG)
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/backend/go/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pants.core.goals.package import OutputPathField
from pants.core.goals.run import RestartableField
from pants.core.goals.test import TestExtraEnvVarsField, TestTimeoutField
from pants.core.util_rules.environments import EnvironmentField
from pants.engine.addresses import Address
from pants.engine.target import (
COMMON_TARGET_FIELDS,
Expand Down Expand Up @@ -452,6 +453,7 @@ class GoBinaryTarget(Target):
GoCompilerFlagsField,
GoLinkerFlagsField,
RestartableField,
EnvironmentField,
)
help = "A Go binary."

Expand Down

0 comments on commit ddf3543

Please sign in to comment.