Skip to content

Commit b4b0370

Browse files
committed
Express the multi-arch nature of .beam files via a transition
This allows beam files to cache across architectures
1 parent 25b7814 commit b4b0370

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

erlang_app_info.bzl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("//private:beam_transition.bzl", "beam_transition")
2+
13
ErlangAppInfo = provider(
24
doc = "Compiled Erlang Application",
35
fields = {
@@ -62,10 +64,16 @@ erlang_app_info = rule(
6264
"extra_apps": attr.string_list(),
6365
"hdrs": attr.label_list(allow_files = True),
6466
"app": attr.label(allow_files = [".app"]),
65-
"beam": attr.label_list(allow_files = [".beam", ".appup"]),
67+
"beam": attr.label_list(
68+
allow_files = [".beam", ".appup"],
69+
cfg = beam_transition,
70+
),
6671
"priv": attr.label_list(allow_files = True),
6772
"license_files": attr.label_list(allow_files = True),
6873
"srcs": attr.label_list(allow_files = True),
6974
"deps": attr.label_list(providers = [ErlangAppInfo]),
75+
"_allowlist_function_transition": attr.label(
76+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
77+
),
7078
},
7179
)

private/beam_transition.bzl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def _impl(settings, attr):
2+
_ignore = (settings, attr)
3+
4+
# print("_impl")
5+
# print("settings", settings)
6+
# print("attr", attr)
7+
return {
8+
"arm": {"//command_line_option:cpu": "arm"},
9+
"x86": {"//command_line_option:cpu": "x86"},
10+
"k8": {"//command_line_option:cpu": "k8"},
11+
}
12+
13+
beam_transition = transition(
14+
implementation = _impl,
15+
inputs = [],
16+
outputs = ["//command_line_option:cpu"],
17+
)

private/erlang_bytecode2.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("//:erlang_app_info.bzl", "ErlangAppInfo")
22
load("//:util.bzl", "path_join")
3+
load(":beam_transition.bzl", "beam_transition")
34
load(":erlang_bytecode.bzl", "unique_dirnames")
45
load(":util.bzl", "erl_libs_contents")
56
load(
@@ -132,6 +133,7 @@ erlang_bytecode = rule(
132133
),
133134
"beam": attr.label_list(
134135
allow_files = [".beam"],
136+
cfg = beam_transition,
135137
),
136138
"deps": attr.label_list(
137139
providers = [ErlangAppInfo],
@@ -142,6 +144,9 @@ erlang_bytecode = rule(
142144
"outs": attr.output_list(
143145
mandatory = True,
144146
),
147+
"_allowlist_function_transition": attr.label(
148+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
149+
),
145150
},
146151
toolchains = ["//tools:toolchain_type"],
147152
)

private/escript_archive.bzl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ load(
1212
"//:util.bzl",
1313
"path_join",
1414
)
15+
load(
16+
":beam_transition.bzl",
17+
"beam_transition",
18+
)
1519
load(
1620
":util.bzl",
1721
"additional_file_dest_relative_path",
@@ -117,8 +121,14 @@ escript_archive = rule(
117121
default = DEFAULT_HEADERS,
118122
),
119123
"srcs": attr.label_list(allow_files = [".erl"]),
120-
"beam": attr.label_list(allow_files = [".beam"]),
124+
"beam": attr.label_list(
125+
allow_files = [".beam"],
126+
cfg = beam_transition,
127+
),
121128
"app": attr.label(providers = [ErlangAppInfo]),
129+
"_allowlist_function_transition": attr.label(
130+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
131+
),
122132
},
123133
toolchains = ["//tools:toolchain_type"],
124134
executable = True,

private/escript_flat.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ load(
33
"erlang_dirs",
44
"maybe_install_erlang",
55
)
6+
load(
7+
":beam_transition.bzl",
8+
"beam_transition",
9+
)
610

711
def _impl(ctx):
812
out = ctx.actions.declare_file(ctx.attr.out if ctx.attr.out != "" else ctx.label.name)
@@ -63,8 +67,12 @@ escript_flat = rule(
6367
),
6468
"beam": attr.label(
6569
allow_single_file = [".beam"],
70+
cfg = beam_transition,
6671
),
6772
"out": attr.string(),
73+
"_allowlist_function_transition": attr.label(
74+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
75+
),
6876
},
6977
toolchains = ["//tools:toolchain_type"],
7078
)

private/eunit.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load(
44
"path_join",
55
"windows_path",
66
)
7+
load(":beam_transition.bzl", "beam_transition")
78
load(":util.bzl", "erl_libs_contents2")
89
load(
910
"//tools:erlang_toolchain.bzl",
@@ -178,6 +179,7 @@ eunit_test = rule(
178179
"is_windows": attr.bool(mandatory = True),
179180
"compiled_suites": attr.label_list(
180181
allow_files = [".beam"],
182+
cfg = beam_transition,
181183
),
182184
"eunit_mods": attr.string_list(),
183185
"target": attr.label(providers = [ErlangAppInfo]),
@@ -187,6 +189,9 @@ eunit_test = rule(
187189
"deps": attr.label_list(providers = [ErlangAppInfo]),
188190
"tools": attr.label_list(),
189191
"test_env": attr.string_dict(),
192+
"_allowlist_function_transition": attr.label(
193+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
194+
),
190195
},
191196
toolchains = ["//tools:toolchain_type"],
192197
test = True,

0 commit comments

Comments
 (0)