Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 1 | """Internal transition implementations for core Rust rules""" |
| 2 | |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 3 | load("//rust:defs.bzl", "rust_common") |
| 4 | |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 5 | def _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 | |
| 24 | import_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 Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 30 | def _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 Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 33 | |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 34 | alias_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 Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 37 | attrs = { |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 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.", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 41 | cfg = import_macro_dep_bootstrap_transition, |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 42 | mandatory = True, |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 43 | ), |
| 44 | "_allowlist_function_transition": attr.label( |
| 45 | default = Label("//tools/allowlists/function_transition_allowlist"), |
| 46 | ), |
| 47 | }, |
| 48 | ) |