xref: /aosp_15_r20/external/bazelbuild-rules_rust/rust/private/transitions.bzl (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1"""Internal transition implementations for core Rust rules"""
2
3load("//rust:defs.bzl", "rust_common")
4
5def _import_macro_dep_bootstrap_transition(_settings, _attr):
6    """The implementation of the `import_macro_dep_bootstrap_transition` transition.
7
8    This transition modifies the config to start using the fake macro
9    implementation, so that the macro itself can be bootstrapped without
10    creating a dependency cycle, even while every Rust target has an implicit
11    dependency on the "import" macro (either real or fake).
12
13    Args:
14        _settings (dict): a dict {String:Object} of all settings declared in the
15            inputs parameter to `transition()`.
16        _attr (dict): A dict of attributes and values of the rule to which the
17            transition is attached.
18
19    Returns:
20        dict: A dict of new build settings values to apply.
21    """
22    return {"@rules_rust//rust/settings:use_real_import_macro": False}
23
24import_macro_dep_bootstrap_transition = transition(
25    implementation = _import_macro_dep_bootstrap_transition,
26    inputs = [],
27    outputs = ["@rules_rust//rust/settings:use_real_import_macro"],
28)
29
30def _alias_with_import_macro_bootstrapping_mode_impl(ctx):
31    actual = ctx.attr.actual[0]
32    return [actual[rust_common.crate_info], actual[rust_common.dep_info]]
33
34alias_with_import_macro_bootstrapping_mode = rule(
35    implementation = _alias_with_import_macro_bootstrapping_mode_impl,
36    doc = "Alias-like rule to build the `actual` with `use_real_import_macro` setting disabled. Not to be used outside of the import macro bootstrap.",
37    attrs = {
38        # Using `actual` so tooling such as rust analyzer aspect traverses the target.
39        "actual": attr.label(
40            doc = "The target this alias refers to.",
41            cfg = import_macro_dep_bootstrap_transition,
42            mandatory = True,
43        ),
44        "_allowlist_function_transition": attr.label(
45            default = Label("//tools/allowlists/function_transition_allowlist"),
46        ),
47    },
48)
49