Skip to content

Commit 1f06797

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

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", "flat_deps")
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(
@@ -133,6 +134,7 @@ erlang_bytecode = rule(
133134
),
134135
"beam": attr.label_list(
135136
allow_files = [".beam"],
137+
cfg = beam_transition,
136138
),
137139
"deps": attr.label_list(
138140
providers = [ErlangAppInfo],
@@ -146,6 +148,9 @@ erlang_bytecode = rule(
146148
"outs": attr.output_list(
147149
mandatory = True,
148150
),
151+
"_allowlist_function_transition": attr.label(
152+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
153+
),
149154
},
150155
toolchains = ["//tools:toolchain_type"],
151156
)

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_contents")
89
load(
910
"//tools:erlang_toolchain.bzl",
@@ -179,6 +180,7 @@ eunit_test = rule(
179180
"is_windows": attr.bool(mandatory = True),
180181
"compiled_suites": attr.label_list(
181182
allow_files = [".beam"],
183+
cfg = beam_transition,
182184
),
183185
"eunit_mods": attr.string_list(),
184186
"target": attr.label(providers = [ErlangAppInfo]),
@@ -191,6 +193,9 @@ eunit_test = rule(
191193
),
192194
"tools": attr.label_list(),
193195
"test_env": attr.string_dict(),
196+
"_allowlist_function_transition": attr.label(
197+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
198+
),
194199
},
195200
toolchains = ["//tools:toolchain_type"],
196201
test = True,

0 commit comments

Comments
 (0)