Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ END_UNRELEASED_TEMPLATE
{#v0-0-0-changed}
### Changed
* (binaries/tests) The `PYTHONBREAKPOINT` environment variable is automatically inherited
* (binaries/tests) The {obj}`stamp` attribute now transitions the Bazel builtin
{obj}`--stamp` flag.

{#v0-0-0-fixed}
### Fixed
Expand All @@ -69,6 +71,9 @@ END_UNRELEASED_TEMPLATE
### Added
* (binaries/tests) {obj}`--debugger`: allows specifying an extra dependency
to add to binaries/tests for custom debuggers.
* (binaries/tests) Build information is now included in binaries and tests.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also tell, that if users want, the could, for example set the __version__ or other standard Python metadata from the bazel_binary_info module. What do you think?

Use the `bazel_binary_info` module to access it. The {flag}`--stamp` flag will
add {flag}`--workspace_status` information.

{#v1-8-0}
## [1.8.0] - 2025-12-19
Expand Down
13 changes: 13 additions & 0 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ load(":print_toolchain_checksums.bzl", "print_toolchains_checksums")
load(":py_exec_tools_toolchain.bzl", "current_interpreter_executable")
load(":sentinel.bzl", "sentinel")
load(":stamp.bzl", "stamp_build_setting")
load(":uncachable_version_file.bzl", "define_uncachable_version_file")

package(
default_visibility = ["//:__subpackages__"],
Expand Down Expand Up @@ -99,6 +100,14 @@ bzl_library(
],
)

alias(
name = "build_data_writer",
actual = select({
"@platforms//os:windows": ":build_data_writer.ps1",
"//conditions:default": ":build_data_writer.sh",
}),
)

bzl_library(
name = "builders_bzl",
srcs = ["builders.bzl"],
Expand Down Expand Up @@ -683,6 +692,10 @@ bzl_library(
],
)

define_uncachable_version_file(
name = "uncachable_version_file",
)

bzl_library(
name = "version_bzl",
srcs = ["version.bzl"],
Expand Down
14 changes: 13 additions & 1 deletion python/private/attributes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,20 @@ Whether to encode build information into the binary. Possible values:
Stamped binaries are not rebuilt unless their dependencies change.
WARNING: Stamping can harm build performance by reducing cache hits and should
Stamped build information can accessed using the `bazel_binary_info` module.
See the [Accessing build information docs] for more information.
:::{warning}
Stamping can harm build performance by reducing cache hits and should
be avoided if possible.
In addition, this transitions the {obj}`--stamp` flag, which can additional
config state overhead.
:::
:::{note}
Stamping of build data output is always disabled for the exec config.
:::
""",
default = -1,
),
Expand Down
18 changes: 18 additions & 0 deletions python/private/build_data_writer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$OutputPath = $env:OUTPUT

Add-Content -Path $OutputPath -Value "TARGET $env:TARGET"
Add-Content -Path $OutputPath -Value "CONFIG_ID $env:CONFIG_ID"
Add-Content -Path $OutputPath -Value "CONFIG_MODE $env:CONFIG_MODE"
Add-Content -Path $OutputPath -Value "STAMPED $env:STAMPED"

$VersionFilePath = $env:VERSION_FILE
if (-not [string]::IsNullOrEmpty($VersionFilePath)) {
Get-Content -Path $VersionFilePath | Add-Content -Path $OutputPath
}

$InfoFilePath = $env:INFO_FILE
if (-not [string]::IsNullOrEmpty($InfoFilePath)) {
Get-Content -Path $InfoFilePath | Add-Content -Path $OutputPath
}

exit 0
12 changes: 12 additions & 0 deletions python/private/build_data_writer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

echo "TARGET $TARGET" >> $OUTPUT
echo "CONFIG_MODE $CONFIG_MODE" >> $OUTPUT
echo "STAMPED $STAMPED" >> $OUTPUT
if [ -n "$VERSION_FILE" ]; then
cat "$VERSION_FILE" >> "$OUTPUT"
fi
if [ -n "$INFO_FILE" ]; then
cat "$INFO_FILE" >> "$OUTPUT"
fi
exit 0
11 changes: 1 addition & 10 deletions python/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,25 @@ PYTHON_FILE_EXTENSIONS = [

def create_binary_semantics_struct(
*,
get_central_uncachable_version_file,
get_native_deps_dso_name,
should_build_native_deps_dso,
should_include_build_data):
should_build_native_deps_dso):
"""Helper to ensure a semantics struct has all necessary fields.

Call this instead of a raw call to `struct(...)`; it'll help ensure all
the necessary functions are being correctly provided.

Args:
get_central_uncachable_version_file: Callable that returns an optional
Artifact; this artifact is special: it is never cached and is a copy
of `ctx.version_file`; see py_builtins.copy_without_caching
get_native_deps_dso_name: Callable that returns a string, which is the
basename (with extension) of the native deps DSO library.
should_build_native_deps_dso: Callable that returns bool; True if
building a native deps DSO is supported, False if not.
should_include_build_data: Callable that returns bool; True if
build data should be generated, False if not.
Returns:
A "BinarySemantics" struct.
"""
return struct(
# keep-sorted
get_central_uncachable_version_file = get_central_uncachable_version_file,
get_native_deps_dso_name = get_native_deps_dso_name,
should_build_native_deps_dso = should_build_native_deps_dso,
should_include_build_data = should_include_build_data,
)

def create_cc_details_struct(
Expand Down
Loading