1313# limitations under the License.
1414"""Common functionality between test/binary executables."""
1515
16+ load ("@bazel_features//:features.bzl" , "bazel_features" )
1617load ("@bazel_skylib//lib:dicts.bzl" , "dicts" )
1718load ("@bazel_skylib//lib:paths.bzl" , "paths" )
1819load ("@bazel_skylib//lib:structs.bzl" , "structs" )
@@ -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 bazel_features .rules ._has_launcher_maker_toolchain 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 bazel_features .rules ._has_launcher_maker_toolchain :
786+ return ctx .toolchains [_LAUNCHER_MAKER_TOOLCHAIN_TYPE ].binary
787+ return ctx .executable ._windows_launcher_maker
788+
780789def _create_windows_exe_launcher (
781790 ctx ,
782791 * ,
@@ -797,7 +806,7 @@ def _create_windows_exe_launcher(
797806
798807 launcher = ctx .attr ._launcher [DefaultInfo ].files_to_run .executable
799808 ctx .actions .run (
800- executable = ctx . executable . _windows_launcher_maker ,
809+ executable = _find_launcher_maker ( ctx ) ,
801810 arguments = [launcher .path , launch_info , output .path ],
802811 inputs = [launcher ],
803812 outputs = [output ],
@@ -1838,7 +1847,7 @@ def create_executable_rule_builder(implementation, **kwargs):
18381847 ruleb .ToolchainType (TOOLCHAIN_TYPE ),
18391848 ruleb .ToolchainType (EXEC_TOOLS_TOOLCHAIN_TYPE , mandatory = False ),
18401849 ruleb .ToolchainType ("@bazel_tools//tools/cpp:toolchain_type" , mandatory = False ),
1841- ],
1850+ ] + ([ ruleb . ToolchainType ( _LAUNCHER_MAKER_TOOLCHAIN_TYPE )] if bazel_features . rules . _has_launcher_maker_toolchain else []) ,
18421851 cfg = dict (
18431852 implementation = _transition_executable_impl ,
18441853 inputs = TRANSITION_LABELS + [labels .PYTHON_VERSION ],
0 commit comments