@@ -18,6 +18,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
1818load ("@bazel_skylib//lib:structs.bzl" , "structs" )
1919load ("@bazel_skylib//rules:common_settings.bzl" , "BuildSettingInfo" )
2020load ("@rules_cc//cc/common:cc_common.bzl" , "cc_common" )
21+ load ("@rules_python_internal//:rules_python_config.bzl" , rp_config = "config" )
2122load (":attr_builders.bzl" , "attrb" )
2223load (
2324 ":attributes.bzl" ,
@@ -69,6 +70,7 @@ load(":venv_runfiles.bzl", "create_venv_app_files")
6970_py_builtins = py_internal
7071_EXTERNAL_PATH_PREFIX = "external"
7172_ZIP_RUNFILES_DIRECTORY_NAME = "runfiles"
73+ _LAUNCHER_MAKER_TOOLCHAIN_TYPE = "@bazel_tools//tools/launcher:launcher_maker_toolchain_type"
7274
7375# Non-Google-specific attributes for executables
7476# These attributes are for rules that accept Python sources.
@@ -228,17 +230,19 @@ accepting arbitrary Python versions.
228230 "@platforms//os:windows" ,
229231 ],
230232 ),
231- "_windows_launcher_maker" : lambda : attrb .Label (
232- default = "@bazel_tools//tools/launcher:launcher_maker" ,
233- cfg = "exec" ,
234- executable = True ,
235- ),
236233 "_zipper" : lambda : attrb .Label (
237234 cfg = "exec" ,
238235 executable = True ,
239236 default = "@bazel_tools//tools/zip:zipper" ,
240237 ),
241238 },
239+ {
240+ "_windows_launcher_maker" : lambda : attrb .Label (
241+ default = "@bazel_tools//tools/launcher:launcher_maker" ,
242+ cfg = "exec" ,
243+ executable = True ,
244+ ),
245+ } if not rp_config .bazel_9_or_later else {},
242246)
243247
244248def convert_legacy_create_init_to_int (kwargs ):
@@ -777,6 +781,11 @@ def _create_stage1_bootstrap(
777781 is_executable = True ,
778782 )
779783
784+ def _find_launcher_maker (ctx ):
785+ if rp_config .bazel_9_or_later :
786+ return (ctx .toolchains [_LAUNCHER_MAKER_TOOLCHAIN_TYPE ].binary , _LAUNCHER_MAKER_TOOLCHAIN_TYPE )
787+ return (ctx .executable ._windows_launcher_maker , None )
788+
780789def _create_windows_exe_launcher (
781790 ctx ,
782791 * ,
@@ -796,15 +805,17 @@ def _create_windows_exe_launcher(
796805 launch_info .add ("1" if use_zip_file else "0" , format = "use_zip_file=%s" )
797806
798807 launcher = ctx .attr ._launcher [DefaultInfo ].files_to_run .executable
808+ executable , toolchain = _find_launcher_maker (ctx )
799809 ctx .actions .run (
800- executable = ctx . executable . _windows_launcher_maker ,
810+ executable = executable ,
801811 arguments = [launcher .path , launch_info , output .path ],
802812 inputs = [launcher ],
803813 outputs = [output ],
804814 mnemonic = "PyBuildLauncher" ,
805815 progress_message = "Creating launcher for %{label}" ,
806816 # Needed to inherit PATH when using non-MSVC compilers like MinGW
807817 use_default_shell_env = True ,
818+ toolchain = toolchain ,
808819 )
809820
810821def _create_zip_file (ctx , * , output , zip_main , runfiles ):
@@ -1838,7 +1849,7 @@ def create_executable_rule_builder(implementation, **kwargs):
18381849 ruleb .ToolchainType (TOOLCHAIN_TYPE ),
18391850 ruleb .ToolchainType (EXEC_TOOLS_TOOLCHAIN_TYPE , mandatory = False ),
18401851 ruleb .ToolchainType ("@bazel_tools//tools/cpp:toolchain_type" , mandatory = False ),
1841- ],
1852+ ] + ([ ruleb . ToolchainType ( _LAUNCHER_MAKER_TOOLCHAIN_TYPE )] if rp_config . bazel_9_or_later else []) ,
18421853 cfg = dict (
18431854 implementation = _transition_executable_impl ,
18441855 inputs = TRANSITION_LABELS + [labels .PYTHON_VERSION ],
0 commit comments