Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the major version of golang at package time #21523

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/notes/2.24.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Added a new `cache_scope` field to `adhoc_tool` and `shell_command` targets to a

Fix a bug where Pants raised an internal exception which occurred when compiling a Go package with coverage support when the package also had an external test which imported the base package.

Fix a bug where Pants sent a minor Go version instead of the major one to the Go toolchain during packaging.

Recognize `-fullpath` as a test binary flag.

Add support for the `all:` prefix to patterns used with the `go:embed` directive. The `all:` prefix includes files which start with `_` or `.` which are ordinarilly excluded .
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/go/util_rules/build_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ async def build_go_package(

# See https://github.com/golang/go/blob/f229e7031a6efb2f23241b5da000c3b3203081d6/src/cmd/go/internal/work/gc.go#L79-L100
# for where this logic comes from.
go_version = request.minimum_go_version or "1.16"
go_version = go_root.major_version(request.minimum_go_version or "1.16")
if go_root.is_compatible_version(go_version):
compile_args.extend(["-lang", f"go{go_version}"])

Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/go/util_rules/build_pkg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_build_pkg(rule_runner: RuleRunner) -> None:
).digest,
s_files=(),
direct_dependencies=(),
minimum_go_version=None,
minimum_go_version="1.21.2",
)
direct_dep = BuildGoPackageRequest(
import_path="example.com/foo/dep",
Expand Down
5 changes: 5 additions & 0 deletions src/python/pants/backend/go/util_rules/goroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def is_compatible_version(self, version: str) -> bool:
"""Can this Go compiler handle the target version?"""
return compatible_go_version(compiler_version=self.version, target_version=version)

def major_version(self, version: str) -> str:
_version_components = version.split(".") # e.g. [1, 17] or [1, 17, 1]
major_version = ".".join(_version_components[:2])
return major_version

@property
def full_version(self) -> str:
return self._raw_metadata["GOVERSION"]
Expand Down
Loading