Skip to content
Open
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.30.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ The version of [Pex](https://github.com/pex-tool/pex) used by the Python backend

Performance has been improved for dependency download and analysis.

Go now compiles with trimpath to strip sandbox paths from output, allowing for reproducible builds.

### Plugin API changes

The plugin API's `Get()` construct has been deprecated in favor of the call-by-name idiom. See [here](https://www.pantsbuild.org/2.30/docs/writing-plugins/the-rules-api/migrating-gets) for how to update your plugins.
Expand Down
3 changes: 3 additions & 0 deletions src/python/pants/backend/go/util_rules/build_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ async def build_go_package(
request.import_path,
"-importcfg",
import_config.CONFIG_PATH,
"-trimpath",
"__PANTS_SANDBOX_ROOT__",
]

# See https://github.com/golang/go/blob/f229e7031a6efb2f23241b5da000c3b3203081d6/src/cmd/go/internal/work/gc.go#L79-L100
Expand Down Expand Up @@ -892,6 +894,7 @@ async def build_go_package(
description=f"Compile Go package: {request.import_path}",
output_files=("__pkg__.a", *([asm_header_path] if asm_header_path else [])),
env={"__PANTS_GO_COMPILE_ACTION_ID": action_id_result.action_id},
replace_sandbox_root_in_args=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious to see how this works, and it's pretty straight forward:

if request.replace_sandbox_root_in_args:
env[GoSdkRunSetup.SANDBOX_ROOT_ENV] = "1"

if [ -n "${GoSdkRunSetup.SANDBOX_ROOT_ENV}" ]; then
export __PANTS_SANDBOX_ROOT__="$sandbox_root"
args=("${{@//__PANTS_SANDBOX_ROOT__/$sandbox_root}}")
set -- "${{args[@]}}"
fi
exec "{goroot.path}/bin/go" "$@"

)
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/go/util_rules/cgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ async def cgo_compile_request(
"-importpath",
request.import_path,
*maybe_disable_imports_flags,
# TODO(#16835): Add -trimpath option to remove sandbox paths from source paths embedded in files.
# This means using `__PANTS_SANDBOX_ROOT__` support of `GoSdkProcess`.
"-trimpath",
"__PANTS_SANDBOX_ROOT__",
Comment on lines +816 to +817
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the other GoSdkProcess in this file need -trimpath as well? (The GoSdkProcess that calls go tool cgo -dynimport in _dynimport(...))

"--",
*flags.cppflags,
*flags.cflags,
Expand Down
Loading