fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
e48bec94
0.6.0
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_build_script = None , 82patch_args = None , 83patch_tool = None , 84patches = None , 85proc_macro_deps = None , 86rustc_env = None , 87rustc_env_files = None , 88rustc_flags = None , 89shallow_since = None ): 90"""A collection of extra attributes and settings for a particular crate 91 92Args: 93version (str, optional): The version or semver-conditions to match with a crate. 94additive_build_file_content (str, optional): Extra contents to write to the bottom of generated BUILD files. 95additive_build_file (str, optional): A file containing extra contents to write to the bottom of 96generated BUILD files. 97build_script_data (list, optional): A list of labels to add to a crate's `cargo_build_script::data` attribute. 98build_script_tools (list, optional): A list of labels to add to a crate's `cargo_build_script::tools` attribute. 99build_script_data_glob (list, optional): A list of glob patterns to add to a crate's `cargo_build_script::data` 100attribute. 101build_script_deps (list, optional): A list of labels to add to a crate's `cargo_build_script::deps` attribute. 102build_script_env (dict, optional): Additional environment variables to set on a crate's 103`cargo_build_script::env` attribute. 104build_script_proc_macro_deps (list, optional): A list of labels to add to a crate's 105`cargo_build_script::proc_macro_deps` attribute. 106build_script_rustc_env (dict, optional): Additional environment variables to set on a crate's 107`cargo_build_script::env` attribute. 108build_script_toolchains (list, optional): A list of labels to set on a crates's `cargo_build_script::toolchains` attribute. 109compile_data (list, optional): A list of labels to add to a crate's `rust_library::compile_data` attribute. 110compile_data_glob (list, optional): A list of glob patterns to add to a crate's `rust_library::compile_data` 111attribute. 112crate_features (list, optional): A list of strings to add to a crate's `rust_library::crate_features` 113attribute. 114data (list, optional): A list of labels to add to a crate's `rust_library::data` attribute. 115data_glob (list, optional): A list of glob patterns to add to a crate's `rust_library::data` attribute. 116deps (list, optional): A list of labels to add to a crate's `rust_library::deps` attribute. 117gen_build_script (bool, optional): An authorative flag to determine whether or not to produce 118`cargo_build_script` targets for the current crate. 119patch_args (list, optional): The `patch_args` attribute of a Bazel repository rule. See 120[http_archive.patch_args](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args) 121patch_tool (list, optional): The `patch_tool` attribute of a Bazel repository rule. See 122[http_archive.patch_tool](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool) 123patches (list, optional): The `patches` attribute of a Bazel repository rule. See 124[http_archive.patches](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches) 125proc_macro_deps (list, optional): A list of labels to add to a crate's `rust_library::proc_macro_deps` 126attribute. 127rustc_env (dict, optional): Additional variables to set on a crate's `rust_library::rustc_env` attribute. 128rustc_env_files (list, optional): A list of labels to set on a crate's `rust_library::rustc_env_files` 129attribute. 130rustc_flags (list, optional): A list of strings to set on a crate's `rust_library::rustc_flags` attribute. 131shallow_since (str, optional): An optional timestamp used for crates originating from a git repository 132instead of a crate registry. This flag optimizes fetching the source code. 133 134Returns: 135string: A json encoded string containing the specified version and separately all other inputs. 136""" 137if additive_build_file : 138_assert_absolute ( additive_build_file ) 139if patches : 140for patch in patches : 141_assert_absolute ( patch ) 142 143return json . encode (( 144version , 145struct ( 146additive_build_file = additive_build_file , 147additive_build_file_content = additive_build_file_content , 148build_script_data = build_script_data , 149build_script_tools = build_script_tools , 150build_script_data_glob = build_script_data_glob , 151build_script_deps = build_script_deps , 152build_script_env = build_script_env , 153build_script_proc_macro_deps = build_script_proc_macro_deps , 154build_script_rustc_env = build_script_rustc_env , 155build_script_toolchains = build_script_toolchains , 156compile_data = compile_data , 157compile_data_glob = compile_data_glob , 158crate_features = crate_features , 159data = data , 160data_glob = data_glob , 161deps = deps , 162gen_build_script = gen_build_script , 163patch_args = patch_args , 164patch_tool = patch_tool , 165patches = patches , 166proc_macro_deps = proc_macro_deps , 167rustc_env = rustc_env , 168rustc_env_files = rustc_env_files , 169rustc_flags = rustc_flags , 170shallow_since = shallow_since , 171), 172)) 173 174crate = struct ( 175spec = _spec , 176annotation = _annotation , 177workspace_member = _workspace_member , 178)