fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
0a4c4dfb
patching
1""" 2https://github.com/aspect-build/bazel-lib/blob/main/lib/transitions.bzl 3 4Rules for working with transitions. 5""" 6 7load ( "@bazel_skylib//lib:paths.bzl" , "paths" ) 8 9def _transition_platform_impl ( _ , attr ): 10return { "//command_line_option:platforms" : str ( attr . target_platform )} 11 12# Transition from any input configuration to one that includes the 13# --platforms command-line flag. 14_transition_platform = transition ( 15implementation = _transition_platform_impl , 16inputs = [], 17outputs = [ "//command_line_option:platforms" ], 18) 19 20def _platform_transition_binary_impl ( ctx ): 21# We need to forward the DefaultInfo provider from the underlying rule. 22# Unfortunately, we can't do this directly, because Bazel requires that the executable to run 23# is actually generated by this rule, so we need to symlink to it, and generate a synthetic 24# forwarding DefaultInfo. 25 26result = [] 27binary = ctx . attr . binary [ 0 ] 28 29default_info = binary [ DefaultInfo ] 30files = default_info . files 31new_executable = None 32original_executable = default_info . files_to_run . executable 33runfiles = default_info . default_runfiles 34 35if not original_executable : 36fail ( "Cannot transition a 'binary' that is not executable" ) 37 38new_executable_name = original_executable . basename 39 40# In order for the symlink to have the same basename as the original 41# executable (important in the case of proto plugins), put it in a 42# subdirectory named after the label to prevent collisions. 43new_executable = ctx . actions . declare_file ( paths . join ( ctx . label . name , new_executable_name )) 44ctx . actions . symlink ( 45output = new_executable , 46target_file = original_executable , 47is_executable = True , 48) 49files = depset ( direct = [ new_executable ], transitive = [ files ]) 50runfiles = runfiles . merge ( ctx . runfiles ([ new_executable ])) 51 52result . append ( 53DefaultInfo ( 54files = files , 55runfiles = runfiles , 56executable = new_executable , 57), 58) 59 60return result 61 62platform_transition_binary = rule ( 63doc = "Transitions the binary to use the provided platform." , 64implementation = _platform_transition_binary_impl , 65attrs = { 66"binary" : attr . label ( 67doc = "The target to transition." , 68allow_files = True , 69cfg = _transition_platform , 70mandatory = True , 71), 72"target_platform" : attr . label ( 73doc = "The target platform to transition the binary." , 74mandatory = True , 75), 76"_allowlist_function_transition" : attr . label ( 77default = "@bazel_tools//tools/allowlists/function_transition_allowlist" , 78), 79}, 80executable = True , 81)