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" )
@@ -70,6 +71,7 @@ _py_builtins = py_internal
7071_EXTERNAL_PATH_PREFIX = "external"
7172_ZIP_RUNFILES_DIRECTORY_NAME = "runfiles"
7273_PYTHON_VERSION_FLAG = str (Label ("//python/config_settings:python_version" ))
74+ _LAUNCHER_MAKER_TOOLCHAIN_TYPE = "@bazel_tools//tools/launcher:launcher_maker_toolchain_type"
7375
7476# Non-Google-specific attributes for executables
7577# 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 ):
@@ -842,6 +846,11 @@ def _create_stage1_bootstrap(
842846 substitutions = subs ,
843847 )
844848
849+ def _find_launcher_maker (ctx ):
850+ if bazel_features .rules ._has_launcher_maker_toolchain :
851+ return ctx .toolchains [_LAUNCHER_MAKER_TOOLCHAIN_TYPE ].binary
852+ return ctx .executable ._windows_launcher_maker
853+
845854def _create_windows_exe_launcher (
846855 ctx ,
847856 * ,
@@ -862,7 +871,7 @@ def _create_windows_exe_launcher(
862871
863872 launcher = ctx .attr ._launcher [DefaultInfo ].files_to_run .executable
864873 ctx .actions .run (
865- executable = ctx . executable . _windows_launcher_maker ,
874+ executable = _find_launcher_maker ( ctx ) ,
866875 arguments = [launcher .path , launch_info , output .path ],
867876 inputs = [launcher ],
868877 outputs = [output ],
@@ -1910,7 +1919,7 @@ def create_executable_rule_builder(implementation, **kwargs):
19101919 ruleb .ToolchainType (TOOLCHAIN_TYPE ),
19111920 ruleb .ToolchainType (EXEC_TOOLS_TOOLCHAIN_TYPE , mandatory = False ),
19121921 ruleb .ToolchainType ("@bazel_tools//tools/cpp:toolchain_type" , mandatory = False ),
1913- ],
1922+ ] + ([ ruleb . ToolchainType ( _LAUNCHER_MAKER_TOOLCHAIN_TYPE )] if bazel_features . rules . _has_launcher_maker_toolchain else []) ,
19141923 cfg = dict (
19151924 implementation = _transition_executable_impl ,
19161925 inputs = [_PYTHON_VERSION_FLAG ],
0 commit comments