From 5f580c9e3d5084a50a010b80c94f06bf74acf31d Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 20 May 2025 22:05:28 +0200 Subject: [PATCH 1/8] Use the `launcher_maker` toolchain if available --- MODULE.bazel | 2 +- internal_dev_deps.bzl | 6 ++--- python/private/py_executable.bzl | 23 +++++++++++----- python/private/py_repositories.bzl | 6 +++++ tests/base_rules/py_executable_base_tests.bzl | 26 +++++++++++++++++++ tests/support/platforms/BUILD.bazel | 8 ++++++ tests/support/platforms/platforms.bzl | 4 +++ 7 files changed, 64 insertions(+), 11 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 6e9b725c53..7933fbf6d0 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module( compatibility_level = 1, ) -bazel_dep(name = "bazel_features", version = "1.21.0") +bazel_dep(name = "bazel_features", version = "1.30.0") bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "rules_cc", version = "0.1.5") bazel_dep(name = "platforms", version = "0.0.11") diff --git a/internal_dev_deps.bzl b/internal_dev_deps.bzl index 811240a06a..e357e204a0 100644 --- a/internal_dev_deps.bzl +++ b/internal_dev_deps.bzl @@ -231,9 +231,9 @@ def rules_python_internal_deps(): http_archive( name = "bazel_features", - sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", - strip_prefix = "bazel_features-1.9.1", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", + sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b", + strip_prefix = "bazel_features-1.30.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz", ) http_archive( diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl index 669951e172..a0394e1603 100644 --- a/python/private/py_executable.bzl +++ b/python/private/py_executable.bzl @@ -13,6 +13,7 @@ # limitations under the License. """Common functionality between test/binary executables.""" +load("@bazel_features//:features.bzl", "bazel_features") load("@bazel_skylib//lib:dicts.bzl", "dicts") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:structs.bzl", "structs") @@ -69,6 +70,7 @@ load(":venv_runfiles.bzl", "create_venv_app_files") _py_builtins = py_internal _EXTERNAL_PATH_PREFIX = "external" _ZIP_RUNFILES_DIRECTORY_NAME = "runfiles" +_LAUNCHER_MAKER_TOOLCHAIN_TYPE = "@bazel_tools//tools/launcher:launcher_maker_toolchain_type" # Non-Google-specific attributes for executables # These attributes are for rules that accept Python sources. @@ -228,17 +230,19 @@ accepting arbitrary Python versions. "@platforms//os:windows", ], ), - "_windows_launcher_maker": lambda: attrb.Label( - default = "@bazel_tools//tools/launcher:launcher_maker", - cfg = "exec", - executable = True, - ), "_zipper": lambda: attrb.Label( cfg = "exec", executable = True, default = "@bazel_tools//tools/zip:zipper", ), }, + { + "_windows_launcher_maker": lambda: attrb.Label( + default = "@bazel_tools//tools/launcher:launcher_maker", + cfg = "exec", + executable = True, + ), + } if not bazel_features.rules._has_launcher_maker_toolchain else {}, ) def convert_legacy_create_init_to_int(kwargs): @@ -777,6 +781,11 @@ def _create_stage1_bootstrap( is_executable = True, ) +def _find_launcher_maker(ctx): + if bazel_features.rules._has_launcher_maker_toolchain: + return ctx.toolchains[_LAUNCHER_MAKER_TOOLCHAIN_TYPE].binary + return ctx.executable._windows_launcher_maker + def _create_windows_exe_launcher( ctx, *, @@ -797,7 +806,7 @@ def _create_windows_exe_launcher( launcher = ctx.attr._launcher[DefaultInfo].files_to_run.executable ctx.actions.run( - executable = ctx.executable._windows_launcher_maker, + executable = _find_launcher_maker(ctx), arguments = [launcher.path, launch_info, output.path], inputs = [launcher], outputs = [output], @@ -1838,7 +1847,7 @@ def create_executable_rule_builder(implementation, **kwargs): ruleb.ToolchainType(TOOLCHAIN_TYPE), ruleb.ToolchainType(EXEC_TOOLS_TOOLCHAIN_TYPE, mandatory = False), ruleb.ToolchainType("@bazel_tools//tools/cpp:toolchain_type", mandatory = False), - ], + ] + ([ruleb.ToolchainType(_LAUNCHER_MAKER_TOOLCHAIN_TYPE)] if bazel_features.rules._has_launcher_maker_toolchain else []), cfg = dict( implementation = _transition_executable_impl, inputs = TRANSITION_LABELS + [labels.PYTHON_VERSION], diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl index e3ab11c561..7817137c9e 100644 --- a/python/private/py_repositories.bzl +++ b/python/private/py_repositories.bzl @@ -72,6 +72,12 @@ def py_repositories(transition_settings = []): strip_prefix = "rules_cc-0.1.5", urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz"], ) + http_archive( + name = "bazel_features", + sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b", + strip_prefix = "bazel_features-1.30.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz", + ) # Needed by rules_cc, triggered by @rules_java_prebuilt in Bazel by using @rules_cc//cc:defs.bzl # NOTE: This name must be com_google_protobuf until Bazel drops WORKSPACE diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index e41bc2c022..87a2683c6c 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -13,6 +13,7 @@ # limitations under the License. """Tests common to py_binary and py_test (executable rules).""" +load("@bazel_features//:features.bzl", "bazel_features") load("@rules_python//python:py_runtime_info.bzl", RulesPythonPyRuntimeInfo = "PyRuntimeInfo") load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_testing//lib:truth.bzl", "matching") @@ -114,6 +115,31 @@ def _test_basic_zip_impl(env, target): _tests.append(_test_basic_zip) +def _test_cross_compile_to_unix(name, config): + if not bazel_features.rules._has_launcher_maker_toolchain or "py_test" in str(config.rule): + # The default test toolchain prevents cross-compiling py_test to + # a non-exec platform. + return + rt_util.helper_target( + config.rule, + name = name + "_subject", + main_module = "dummy", + ) + analysis_test( + name = name, + impl = _test_cross_compile_to_unix_impl, + target = name + "_subject", + config_settings = { + "//command_line_option:platforms": [platform_targets.EXOTIC_UNIX], + }, + expect_failure = True, + ) + +def _test_cross_compile_to_unix_impl(_env, _target): + pass + +_tests.append(_test_cross_compile_to_unix) + def _test_executable_in_runfiles(name, config): rt_util.helper_target( config.rule, diff --git a/tests/support/platforms/BUILD.bazel b/tests/support/platforms/BUILD.bazel index 41d7936394..eeb7ccb597 100644 --- a/tests/support/platforms/BUILD.bazel +++ b/tests/support/platforms/BUILD.bazel @@ -75,3 +75,11 @@ platform( "@platforms//cpu:aarch64", ], ) + +platform( + name = "exotic_unix", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:s390x", + ], +) diff --git a/tests/support/platforms/platforms.bzl b/tests/support/platforms/platforms.bzl index af049f202c..92a1d61844 100644 --- a/tests/support/platforms/platforms.bzl +++ b/tests/support/platforms/platforms.bzl @@ -10,4 +10,8 @@ platform_targets = struct( WINDOWS = Label("//tests/support/platforms:windows"), WINDOWS_AARCH64 = Label("//tests/support/platforms:windows_aarch64"), WINDOWS_X86_64 = Label("//tests/support/platforms:windows_x86_64"), + + # Unspecified Unix platform that is unlikely to be the host platform in CI, + # but still provides a Python toolchain. + EXOTIC_UNIX = Label("//tests/support/platforms:exotic_unix"), ) From 93dff6a6fd2bfc342708547c4bfdf17306a4256c Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 21 Nov 2025 10:36:32 +0100 Subject: [PATCH 2/8] Switch to rp_config --- MODULE.bazel | 2 +- internal_dev_deps.bzl | 6 +++--- python/private/internal_config_repo.bzl | 4 ++++ python/private/py_executable.bzl | 8 ++++---- python/private/py_repositories.bzl | 6 ------ tests/base_rules/py_executable_base_tests.bzl | 4 ++-- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 7933fbf6d0..6e9b725c53 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module( compatibility_level = 1, ) -bazel_dep(name = "bazel_features", version = "1.30.0") +bazel_dep(name = "bazel_features", version = "1.21.0") bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "rules_cc", version = "0.1.5") bazel_dep(name = "platforms", version = "0.0.11") diff --git a/internal_dev_deps.bzl b/internal_dev_deps.bzl index e357e204a0..811240a06a 100644 --- a/internal_dev_deps.bzl +++ b/internal_dev_deps.bzl @@ -231,9 +231,9 @@ def rules_python_internal_deps(): http_archive( name = "bazel_features", - sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b", - strip_prefix = "bazel_features-1.30.0", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz", + sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", + strip_prefix = "bazel_features-1.9.1", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", ) http_archive( diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl index d5192ec44b..1e18e9e230 100644 --- a/python/private/internal_config_repo.bzl +++ b/python/private/internal_config_repo.bzl @@ -32,6 +32,7 @@ config = struct( enable_pystar = True, enable_pipstar = {enable_pipstar}, enable_deprecation_warnings = {enable_deprecation_warnings}, + bazel_9_or_later = {bazel_9_or_later}, BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}), BuiltinPyRuntimeInfo = getattr(getattr(native, "legacy_globals", None), "PyRuntimeInfo", {builtin_py_runtime_info_symbol}), BuiltinPyCcLinkParamsProvider = getattr(getattr(native, "legacy_globals", None), "PyCcLinkParamsProvider", {builtin_py_cc_link_params_provider}), @@ -91,10 +92,12 @@ def _internal_config_repo_impl(rctx): builtin_py_info_symbol = "None" builtin_py_runtime_info_symbol = "None" builtin_py_cc_link_params_provider = "None" + bazel_9_or_later = "True" else: builtin_py_info_symbol = "PyInfo" builtin_py_runtime_info_symbol = "PyRuntimeInfo" builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider" + bazel_9_or_later = "False" rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format( build_python_zip_default = repo_utils.get_platforms_os_name(rctx) == "windows", @@ -103,6 +106,7 @@ def _internal_config_repo_impl(rctx): builtin_py_info_symbol = builtin_py_info_symbol, builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol, builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider, + bazel_9_or_later = bazel_9_or_later, )) shim_content = _PY_INTERNAL_SHIM diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl index a0394e1603..ca05e3a206 100644 --- a/python/private/py_executable.bzl +++ b/python/private/py_executable.bzl @@ -13,12 +13,12 @@ # limitations under the License. """Common functionality between test/binary executables.""" -load("@bazel_features//:features.bzl", "bazel_features") load("@bazel_skylib//lib:dicts.bzl", "dicts") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:structs.bzl", "structs") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") +load("@rules_python_internal//:rules_python_config.bzl", rp_config = "config") load(":attr_builders.bzl", "attrb") load( ":attributes.bzl", @@ -242,7 +242,7 @@ accepting arbitrary Python versions. cfg = "exec", executable = True, ), - } if not bazel_features.rules._has_launcher_maker_toolchain else {}, + } if not rp_config.bazel_9_or_later else {}, ) def convert_legacy_create_init_to_int(kwargs): @@ -782,7 +782,7 @@ def _create_stage1_bootstrap( ) def _find_launcher_maker(ctx): - if bazel_features.rules._has_launcher_maker_toolchain: + if rp_config.bazel_9_or_later: return ctx.toolchains[_LAUNCHER_MAKER_TOOLCHAIN_TYPE].binary return ctx.executable._windows_launcher_maker @@ -1847,7 +1847,7 @@ def create_executable_rule_builder(implementation, **kwargs): ruleb.ToolchainType(TOOLCHAIN_TYPE), ruleb.ToolchainType(EXEC_TOOLS_TOOLCHAIN_TYPE, mandatory = False), ruleb.ToolchainType("@bazel_tools//tools/cpp:toolchain_type", mandatory = False), - ] + ([ruleb.ToolchainType(_LAUNCHER_MAKER_TOOLCHAIN_TYPE)] if bazel_features.rules._has_launcher_maker_toolchain else []), + ] + ([ruleb.ToolchainType(_LAUNCHER_MAKER_TOOLCHAIN_TYPE)] if rp_config.bazel_9_or_later else []), cfg = dict( implementation = _transition_executable_impl, inputs = TRANSITION_LABELS + [labels.PYTHON_VERSION], diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl index 7817137c9e..e3ab11c561 100644 --- a/python/private/py_repositories.bzl +++ b/python/private/py_repositories.bzl @@ -72,12 +72,6 @@ def py_repositories(transition_settings = []): strip_prefix = "rules_cc-0.1.5", urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz"], ) - http_archive( - name = "bazel_features", - sha256 = "a660027f5a87f13224ab54b8dc6e191693c554f2692fcca46e8e29ee7dabc43b", - strip_prefix = "bazel_features-1.30.0", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.30.0/bazel_features-v1.30.0.tar.gz", - ) # Needed by rules_cc, triggered by @rules_java_prebuilt in Bazel by using @rules_cc//cc:defs.bzl # NOTE: This name must be com_google_protobuf until Bazel drops WORKSPACE diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 87a2683c6c..3020fb3de8 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -13,8 +13,8 @@ # limitations under the License. """Tests common to py_binary and py_test (executable rules).""" -load("@bazel_features//:features.bzl", "bazel_features") load("@rules_python//python:py_runtime_info.bzl", RulesPythonPyRuntimeInfo = "PyRuntimeInfo") +load("@rules_python_internal//:rules_python_config.bzl", rp_config = "config") load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", rt_util = "util") @@ -116,7 +116,7 @@ def _test_basic_zip_impl(env, target): _tests.append(_test_basic_zip) def _test_cross_compile_to_unix(name, config): - if not bazel_features.rules._has_launcher_maker_toolchain or "py_test" in str(config.rule): + if not rp_config.bazel_9_or_later or "py_test" in str(config.rule): # The default test toolchain prevents cross-compiling py_test to # a non-exec platform. return From 69e7340f75351675a885386de840fa6494baf088 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 21 Nov 2025 16:08:41 +0100 Subject: [PATCH 3/8] Apply suggestions from code review --- tests/base_rules/py_executable_base_tests.bzl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 3020fb3de8..c5de44f98d 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -138,7 +138,10 @@ def _test_cross_compile_to_unix(name, config): def _test_cross_compile_to_unix_impl(_env, _target): pass -_tests.append(_test_cross_compile_to_unix) +# The default test toolchain prevents cross-compiling py_test to a non-exec +# platform. +if rp_config.bazel_9_or_later and "py_test" not in str(config.rule): + _tests.append(_test_cross_compile_to_unix) def _test_executable_in_runfiles(name, config): rt_util.helper_target( From 515f5f421bef5c818bd5ef53a7e244977e3d0d10 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 21 Nov 2025 16:08:52 +0100 Subject: [PATCH 4/8] Apply suggestion from @fmeum --- tests/base_rules/py_executable_base_tests.bzl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index c5de44f98d..4adb2da9bb 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -116,10 +116,6 @@ def _test_basic_zip_impl(env, target): _tests.append(_test_basic_zip) def _test_cross_compile_to_unix(name, config): - if not rp_config.bazel_9_or_later or "py_test" in str(config.rule): - # The default test toolchain prevents cross-compiling py_test to - # a non-exec platform. - return rt_util.helper_target( config.rule, name = name + "_subject", From e66ef701342004b9ab1b0b0dde1143087b8bac3b Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 21 Nov 2025 16:10:31 +0100 Subject: [PATCH 5/8] Update py_executable_base_tests.bzl --- tests/base_rules/py_executable_base_tests.bzl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 4adb2da9bb..9b2927f032 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -134,9 +134,7 @@ def _test_cross_compile_to_unix(name, config): def _test_cross_compile_to_unix_impl(_env, _target): pass -# The default test toolchain prevents cross-compiling py_test to a non-exec -# platform. -if rp_config.bazel_9_or_later and "py_test" not in str(config.rule): +if rp_config.bazel_9_or_later: _tests.append(_test_cross_compile_to_unix) def _test_executable_in_runfiles(name, config): From ae2dd35bddbe63aedd9cc42c71c700681f4446b3 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 21 Nov 2025 17:22:07 +0100 Subject: [PATCH 6/8] Update py_executable_base_tests.bzl --- tests/base_rules/py_executable_base_tests.bzl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 9b2927f032..6092ef4752 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -134,8 +134,7 @@ def _test_cross_compile_to_unix(name, config): def _test_cross_compile_to_unix_impl(_env, _target): pass -if rp_config.bazel_9_or_later: - _tests.append(_test_cross_compile_to_unix) +_tests.append(_test_cross_compile_to_unix) if rp_config.bazel_9_or_later else None def _test_executable_in_runfiles(name, config): rt_util.helper_target( From cc2fa384784060d3651215d4014b47b6733f73b8 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 21 Nov 2025 19:50:14 +0100 Subject: [PATCH 7/8] Update py_executable.bzl --- python/private/py_executable.bzl | 8 +++++--- tests/base_rules/py_executable_base_tests.bzl | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl index ca05e3a206..99a3dffb49 100644 --- a/python/private/py_executable.bzl +++ b/python/private/py_executable.bzl @@ -783,8 +783,8 @@ def _create_stage1_bootstrap( def _find_launcher_maker(ctx): if rp_config.bazel_9_or_later: - return ctx.toolchains[_LAUNCHER_MAKER_TOOLCHAIN_TYPE].binary - return ctx.executable._windows_launcher_maker + return (ctx.toolchains[_LAUNCHER_MAKER_TOOLCHAIN_TYPE].binary, _LAUNCHER_MAKER_TOOLCHAIN_TYPE) + return (ctx.executable._windows_launcher_maker, None) def _create_windows_exe_launcher( ctx, @@ -805,8 +805,9 @@ def _create_windows_exe_launcher( launch_info.add("1" if use_zip_file else "0", format = "use_zip_file=%s") launcher = ctx.attr._launcher[DefaultInfo].files_to_run.executable + executable, toolchain = _find_launcher_maker(ctx) ctx.actions.run( - executable = _find_launcher_maker(ctx), + executable = executable, arguments = [launcher.path, launch_info, output.path], inputs = [launcher], outputs = [output], @@ -814,6 +815,7 @@ def _create_windows_exe_launcher( progress_message = "Creating launcher for %{label}", # Needed to inherit PATH when using non-MSVC compilers like MinGW use_default_shell_env = True, + toolchain = toolchain, ) def _create_zip_file(ctx, *, output, zip_main, runfiles): diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 6092ef4752..ed1a55021d 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -125,16 +125,18 @@ def _test_cross_compile_to_unix(name, config): name = name, impl = _test_cross_compile_to_unix_impl, target = name + "_subject", + # Cross-compilation of py_test fails since the default test toolchain + # requires an execution platform that matches the target platform. config_settings = { "//command_line_option:platforms": [platform_targets.EXOTIC_UNIX], - }, + } if rp_config.bazel_9_or_later and not "py_test" in str(config.rule) else {}, expect_failure = True, ) def _test_cross_compile_to_unix_impl(_env, _target): pass -_tests.append(_test_cross_compile_to_unix) if rp_config.bazel_9_or_later else None +_tests.append(_test_cross_compile_to_unix) def _test_executable_in_runfiles(name, config): rt_util.helper_target( From 0353e77bbcb5fcef0309eb0c0ae927d654f97a47 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 21 Nov 2025 20:43:59 +0100 Subject: [PATCH 8/8] Fix Bazel 8 --- python/private/internal_config_repo.bzl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl index 1e18e9e230..b208037c13 100644 --- a/python/private/internal_config_repo.bzl +++ b/python/private/internal_config_repo.bzl @@ -88,16 +88,17 @@ _TRANSITION_SETTINGS_DEBUG_TEMPLATE = """ """ def _internal_config_repo_impl(rctx): - if not native.bazel_version or int(native.bazel_version.split(".")[0]) >= 8: + # An empty version signifies a development build, which is treated as + # the latest version. + bazel_major_version = int(native.bazel_version.split(".")[0]) if native.bazel_version else 99999 + if bazel_major_version >= 8: builtin_py_info_symbol = "None" builtin_py_runtime_info_symbol = "None" builtin_py_cc_link_params_provider = "None" - bazel_9_or_later = "True" else: builtin_py_info_symbol = "PyInfo" builtin_py_runtime_info_symbol = "PyRuntimeInfo" builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider" - bazel_9_or_later = "False" rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format( build_python_zip_default = repo_utils.get_platforms_os_name(rctx) == "windows", @@ -106,7 +107,7 @@ def _internal_config_repo_impl(rctx): builtin_py_info_symbol = builtin_py_info_symbol, builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol, builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider, - bazel_9_or_later = bazel_9_or_later, + bazel_9_or_later = str(bazel_major_version >= 9), )) shim_content = _PY_INTERNAL_SHIM