blob: 23336f49e192810499779b1b84db92c63263277a [file] [log] [blame]
Brian Silvermancc09f182022-03-09 15:40:20 -08001# 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
Brian Silverman5f6f2762022-08-13 19:30:05 -070049def _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 Silvermancc09f182022-03-09 15:40:20 -080052
Brian Silverman5f6f2762022-08-13 19:30:05 -070053alias_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 Silvermancc09f182022-03-09 15:40:20 -080056 attrs = {
Brian Silverman5f6f2762022-08-13 19:30:05 -070057 # 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 Silvermancc09f182022-03-09 15:40:20 -080060 cfg = import_macro_dep_bootstrap_transition,
Brian Silvermancc09f182022-03-09 15:40:20 -080061 mandatory = True,
Brian Silvermancc09f182022-03-09 15:40:20 -080062 ),
63 "_allowlist_function_transition": attr.label(
64 default = Label("//tools/allowlists/function_transition_allowlist"),
65 ),
66 },
67)