fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
97de47df
0.10.0
1"""Utility functions for the cargo rules""" 2 3load ( "//rust/platform:triple_mappings.bzl" , "system_to_binary_ext" ) 4 5def _resolve_repository_template ( 6template , 7abi = None , 8arch = None , 9system = None , 10tool = None , 11triple = None , 12vendor = None , 13version = None ): 14"""Render values into a repository template string 15 16Args: 17template (str): The template to use for rendering 18abi (str, optional): The host ABI 19arch (str, optional): The host CPU architecture 20system (str, optional): The host system name 21tool (str, optional): The tool to expect in the particular repository. 22Eg. `cargo`, `rustc`, `stdlib`. 23triple (str, optional): The host triple 24vendor (str, optional): The host vendor name 25version (str, optional): The Rust version used in the toolchain. 26Returns: 27string: The resolved template string based on the given parameters 28""" 29if abi : 30template = template . replace ( "{abi}" , abi ) 31 32if arch : 33template = template . replace ( "{arch}" , arch ) 34 35if system : 36template = template . replace ( "{system}" , system ) 37 38if tool : 39template = template . replace ( "{tool}" , tool ) 40 41if triple : 42template = template . replace ( "{triple}" , triple ) 43 44if vendor : 45template = template . replace ( "{vendor}" , vendor ) 46 47if version : 48template = template . replace ( "{version}" , version ) 49 50return template 51 52def get_rust_tools ( cargo_template , rustc_template , host_triple , version ): 53"""Retrieve `cargo` and `rustc` labels based on the host triple. 54 55Args: 56cargo_template (str): A template used to identify the label of the host `cargo` binary. 57rustc_template (str): A template used to identify the label of the host `rustc` binary. 58host_triple (struct): The host's triple. See `@rules_rust//rust/platform:triple.bzl`. 59version (str): The version of Cargo+Rustc to use. 60 61Returns: 62struct: A struct containing the labels of expected tools 63""" 64extension = system_to_binary_ext ( host_triple . system ) 65 66cargo_label = Label ( _resolve_repository_template ( 67template = cargo_template , 68version = version , 69triple = host_triple . str , 70arch = host_triple . arch , 71vendor = host_triple . vendor , 72system = host_triple . system , 73abi = host_triple . abi , 74tool = "cargo" + extension , 75)) 76 77rustc_label = Label ( _resolve_repository_template ( 78template = rustc_template , 79version = version , 80triple = host_triple . str , 81arch = host_triple . arch , 82vendor = host_triple . vendor , 83system = host_triple . system , 84abi = host_triple . abi , 85tool = "rustc" + extension , 86)) 87 88return struct ( 89cargo = cargo_label , 90rustc = rustc_label , 91)