fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

William Smith[crate_universe] add an annotation to disable pipelining (#1733)ad01d1b0

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