fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
e7c8a97d
rust-analyzer
1"""Function for preserving `select` entries for Cargo cfg expressions which did 2not match any enabled target triple / Bazel platform. 3 4For example we might generate: 5 6rust_library( 7... 8deps = [ 9"//common:unconditional_dep", 10] + selects.with_unmapped({ 11"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ 12"//third-party/rust:windows-sys", # cfg(windows) 13], 14"@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [ 15"//third-party/rust:libc", # cfg(any(unix, target_os = "wasi")) 16], 17"//conditions:default": [], 18selects.NO_MATCHING_PLATFORM_TRIPLES: [ 19"//third-party/rust:hermit-abi", # cfg(target_os = "hermit") 20], 21}) 22) 23""" 24 25_SENTINEL = struct () 26 27def _with_unmapped ( configurations ): 28configurations . pop ( _SENTINEL ) 29return select ( configurations ) 30 31selects = struct ( 32with_unmapped = _with_unmapped , 33NO_MATCHING_PLATFORM_TRIPLES = _SENTINEL , 34) 35 36# TODO: No longer used by the serde_starlark-based renderer. Delete after all 37# BUILD files using it have been regenerated. 38# 39# buildifier: disable=function-docstring 40def select_with_or ( input_dict , no_match_error = "" ): 41output_dict = {} 42for ( key , value ) in input_dict . items (): 43if type ( key ) == type (( )): 44for config_setting in key : 45if config_setting in output_dict : 46output_dict [ config_setting ]. extend ( value ) 47else : 48output_dict [ config_setting ] = list ( value ) 49elif key in output_dict : 50output_dict [ key ]. extend ( value ) 51else : 52output_dict [ key ] = list ( value ) 53 54# return a dict with deduped lists 55return select ( 56{ key : depset ( value ). to_list () for key , value in output_dict . items ()}, 57no_match_error = no_match_error , 58)