fork/rules_rust

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

Marcel HlopkoTweak import macro bootstrap to trick rust analyzer aspect (#1179)86d47a1b

0.7.0
2.6 KiB67 linesraw
1# buildifier: disable=module-docstring
2load("//rust:defs.bzl", "rust_common")
3
4def _wasm_bindgen_transition(_settings, _attr):
5    """The implementation of the `wasm_bindgen_transition` transition
6
7    Args:
8        _settings (dict): A dict {String:Object} of all settings declared
9            in the inputs parameter to `transition()`
10        _attr (dict): A dict of attributes and values of the rule to which
11            the transition is attached
12
13    Returns:
14        dict: A dict of new build settings values to apply
15    """
16    return {"//command_line_option:platforms": str(Label("//rust/platform:wasm"))}
17
18wasm_bindgen_transition = transition(
19    implementation = _wasm_bindgen_transition,
20    inputs = [],
21    outputs = ["//command_line_option:platforms"],
22)
23
24def _import_macro_dep_bootstrap_transition(_settings, _attr):
25    """The implementation of the `import_macro_dep_bootstrap_transition` transition.
26
27    This transition modifies the config to start using the fake macro
28    implementation, so that the macro itself can be bootstrapped without
29    creating a dependency cycle, even while every Rust target has an implicit
30    dependency on the "import" macro (either real or fake).
31
32    Args:
33        _settings (dict): a dict {String:Object} of all settings declared in the
34            inputs parameter to `transition()`.
35        _attr (dict): A dict of attributes and values of the rule to which the
36            transition is attached.
37
38    Returns:
39        dict: A dict of new build settings values to apply.
40    """
41    return {"@rules_rust//rust/settings:use_real_import_macro": False}
42
43import_macro_dep_bootstrap_transition = transition(
44    implementation = _import_macro_dep_bootstrap_transition,
45    inputs = [],
46    outputs = ["@rules_rust//rust/settings:use_real_import_macro"],
47)
48
49def _alias_with_import_macro_bootstrapping_mode_impl(ctx):
50    actual = ctx.attr.actual[0]
51    return [actual[rust_common.crate_info], actual[rust_common.dep_info]]
52
53alias_with_import_macro_bootstrapping_mode = rule(
54    implementation = _alias_with_import_macro_bootstrapping_mode_impl,
55    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.",
56    attrs = {
57        # Using `actual` so tooling such as rust analyzer aspect traverses the target.
58        "actual": attr.label(
59            doc = "The target this alias refers to.",
60            cfg = import_macro_dep_bootstrap_transition,
61            mandatory = True,
62        ),
63        "_allowlist_function_transition": attr.label(
64            default = Label("//tools/allowlists/function_transition_allowlist"),
65        ),
66    },
67)