Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 1 | # buildifier: disable=module-docstring |
| 2 | load("//rust:defs.bzl", "rust_common") |
| 3 | |
| 4 | def _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 | |
| 18 | wasm_bindgen_transition = transition( |
| 19 | implementation = _wasm_bindgen_transition, |
| 20 | inputs = [], |
| 21 | outputs = ["//command_line_option:platforms"], |
| 22 | ) |
| 23 | |
| 24 | def _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 | |
| 43 | import_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 | |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame^] | 49 | def _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]] |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 52 | |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame^] | 53 | alias_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.", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 56 | attrs = { |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame^] | 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.", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 60 | cfg = import_macro_dep_bootstrap_transition, |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 61 | mandatory = True, |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 62 | ), |
| 63 | "_allowlist_function_transition": attr.label( |
| 64 | default = Label("//tools/allowlists/function_transition_allowlist"), |
| 65 | ), |
| 66 | }, |
| 67 | ) |