blob: cbc6a06e30beeabfc040b19537e797d1ec92dad7 [file] [log] [blame]
Adam Snaider1c095c92023-07-08 02:09:58 -04001"""Internal transition implementations for core Rust rules"""
2
Brian Silvermancc09f182022-03-09 15:40:20 -08003load("//rust:defs.bzl", "rust_common")
4
Brian Silvermancc09f182022-03-09 15:40:20 -08005def _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
Brian Silverman5f6f2762022-08-13 19:30:05 -070030def _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]]
Brian Silvermancc09f182022-03-09 15:40:20 -080033
Brian Silverman5f6f2762022-08-13 19:30:05 -070034alias_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.",
Brian Silvermancc09f182022-03-09 15:40:20 -080037 attrs = {
Brian Silverman5f6f2762022-08-13 19:30:05 -070038 # Using `actual` so tooling such as rust analyzer aspect traverses the target.
39 "actual": attr.label(
40 doc = "The target this alias refers to.",
Brian Silvermancc09f182022-03-09 15:40:20 -080041 cfg = import_macro_dep_bootstrap_transition,
Brian Silvermancc09f182022-03-09 15:40:20 -080042 mandatory = True,
Brian Silvermancc09f182022-03-09 15:40:20 -080043 ),
44 "_allowlist_function_transition": attr.label(
45 default = Label("//tools/allowlists/function_transition_allowlist"),
46 ),
47 },
48)