fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
ad01d1b0
rust-analyzer
1"""Macros used for represeting crates or annotations for existing crates""" 2 3def _workspace_member ( version , sha256 = None ): 4"""Define information for extra workspace members 5 6Args: 7version (str): The semver of the crate to download. Must be an exact version. 8sha256 (str, optional): The sha256 checksum of the `.crate` file. 9 10Returns: 11string: A json encoded string of all inputs 12""" 13return json . encode ( struct ( 14version = version , 15sha256 = sha256 , 16)) 17 18def _spec ( 19package = None , 20version = None , 21default_features = True , 22features = [], 23git = None , 24rev = None ): 25"""A constructor for a crate dependency. 26 27See [specifying dependencies][sd] in the Cargo book for more details. 28 29[sd]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html 30 31Args: 32package (str, optional): The explicit name of the package (used when attempting to alias a crate). 33version (str, optional): The exact version of the crate. Cannot be used with `git`. 34default_features (bool, optional): Maps to the `default-features` flag. 35features (list, optional): A list of features to use for the crate 36git (str, optional): The Git url to use for the crate. Cannot be used with `version`. 37rev (str, optional): The git revision of the remote crate. Tied with the `git` param. 38 39Returns: 40string: A json encoded string of all inputs 41""" 42return json . encode ( struct ( 43package = package , 44default_features = default_features , 45features = features , 46version = version , 47git = git , 48rev = rev , 49)) 50 51def _assert_absolute ( label ): 52"""Ensure a given label is an absolute label 53 54Args: 55label (Label): The label to check 56""" 57label_str = str ( label ) 58if not label . startswith ( "@" ): 59fail ( "The labels must be absolute. Please update '{}'" . format ( 60label_str , 61)) 62 63def _annotation ( 64version = "*" , 65additive_build_file = None , 66additive_build_file_content = None , 67build_script_data = None , 68build_script_tools = None , 69build_script_data_glob = None , 70build_script_deps = None , 71build_script_env = None , 72build_script_proc_macro_deps = None , 73build_script_rustc_env = None , 74build_script_toolchains = None , 75compile_data = None , 76compile_data_glob = None , 77crate_features = None , 78data = None , 79data_glob = None , 80deps = None , 81gen_binaries = [], 82disable_pipelining = False , 83gen_build_script = None , 84patch_args = None , 85patch_tool = None , 86patches = None , 87proc_macro_deps = None , 88rustc_env = None , 89rustc_env_files = None , 90rustc_flags = None , 91shallow_since = None ): 92"""A collection of extra attributes and settings for a particular crate 93 94Args: 95version (str, optional): The version or semver-conditions to match with a crate. The wildcard `*` 96matches any version, including prerelease versions. 97additive_build_file_content (str, optional): Extra contents to write to the bottom of generated BUILD files. 98additive_build_file (str, optional): A file containing extra contents to write to the bottom of 99generated BUILD files. 100build_script_data (list, optional): A list of labels to add to a crate's `cargo_build_script::data` attribute. 101build_script_tools (list, optional): A list of labels to add to a crate's `cargo_build_script::tools` attribute. 102build_script_data_glob (list, optional): A list of glob patterns to add to a crate's `cargo_build_script::data` 103attribute. 104build_script_deps (list, optional): A list of labels to add to a crate's `cargo_build_script::deps` attribute. 105build_script_env (dict, optional): Additional environment variables to set on a crate's 106`cargo_build_script::env` attribute. 107build_script_proc_macro_deps (list, optional): A list of labels to add to a crate's 108`cargo_build_script::proc_macro_deps` attribute. 109build_script_rustc_env (dict, optional): Additional environment variables to set on a crate's 110`cargo_build_script::env` attribute. 111build_script_toolchains (list, optional): A list of labels to set on a crates's `cargo_build_script::toolchains` attribute. 112compile_data (list, optional): A list of labels to add to a crate's `rust_library::compile_data` attribute. 113compile_data_glob (list, optional): A list of glob patterns to add to a crate's `rust_library::compile_data` 114attribute. 115crate_features (list, optional): A list of strings to add to a crate's `rust_library::crate_features` 116attribute. 117data (list, optional): A list of labels to add to a crate's `rust_library::data` attribute. 118data_glob (list, optional): A list of glob patterns to add to a crate's `rust_library::data` attribute. 119deps (list, optional): A list of labels to add to a crate's `rust_library::deps` attribute. 120gen_binaries (list or bool, optional): As a list, the subset of the crate's bins that should get `rust_binary` 121targets produced. Or `True` to generate all, `False` to generate none. 122disable_pipelining (bool, optional): If True, disables pipelining for library targets for this crate. 123gen_build_script (bool, optional): An authorative flag to determine whether or not to produce 124`cargo_build_script` targets for the current crate. 125patch_args (list, optional): The `patch_args` attribute of a Bazel repository rule. See 126[http_archive.patch_args](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args) 127patch_tool (list, optional): The `patch_tool` attribute of a Bazel repository rule. See 128[http_archive.patch_tool](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool) 129patches (list, optional): The `patches` attribute of a Bazel repository rule. See 130[http_archive.patches](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches) 131proc_macro_deps (list, optional): A list of labels to add to a crate's `rust_library::proc_macro_deps` 132attribute. 133rustc_env (dict, optional): Additional variables to set on a crate's `rust_library::rustc_env` attribute. 134rustc_env_files (list, optional): A list of labels to set on a crate's `rust_library::rustc_env_files` 135attribute. 136rustc_flags (list, optional): A list of strings to set on a crate's `rust_library::rustc_flags` attribute. 137shallow_since (str, optional): An optional timestamp used for crates originating from a git repository 138instead of a crate registry. This flag optimizes fetching the source code. 139 140Returns: 141string: A json encoded string containing the specified version and separately all other inputs. 142""" 143if additive_build_file : 144_assert_absolute ( additive_build_file ) 145if patches : 146for patch in patches : 147_assert_absolute ( patch ) 148 149return json . encode (( 150version , 151struct ( 152additive_build_file = additive_build_file , 153additive_build_file_content = additive_build_file_content , 154build_script_data = build_script_data , 155build_script_tools = build_script_tools , 156build_script_data_glob = build_script_data_glob , 157build_script_deps = build_script_deps , 158build_script_env = build_script_env , 159build_script_proc_macro_deps = build_script_proc_macro_deps , 160build_script_rustc_env = build_script_rustc_env , 161build_script_toolchains = build_script_toolchains , 162compile_data = compile_data , 163compile_data_glob = compile_data_glob , 164crate_features = crate_features , 165data = data , 166data_glob = data_glob , 167deps = deps , 168gen_binaries = gen_binaries , 169disable_pipelining = disable_pipelining , 170gen_build_script = gen_build_script , 171patch_args = patch_args , 172patch_tool = patch_tool , 173patches = patches , 174proc_macro_deps = proc_macro_deps , 175rustc_env = rustc_env , 176rustc_env_files = rustc_env_files , 177rustc_flags = rustc_flags , 178shallow_since = shallow_since , 179), 180)) 181 182crate = struct ( 183spec = _spec , 184annotation = _annotation , 185workspace_member = _workspace_member , 186)