Skip to content

Commit 39903a0

Browse files
committed
Adjust erlang_headers rule to not be platform specific
This simplifies depending on the headers in other rules
1 parent 95a181c commit 39903a0

File tree

4 files changed

+64
-62
lines changed

4 files changed

+64
-62
lines changed

private/erlang_build.bzl

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -246,59 +246,3 @@ erlang_external = rule(
246246
"_erlang_version": attr.label(default = Label("//:erlang_version")),
247247
},
248248
)
249-
250-
def _erlang_headers_impl(ctx):
251-
commands = ["set -euo pipefail", ""]
252-
253-
otpinfo = ctx.attr.otp[OtpInfo]
254-
255-
if otpinfo.release_dir != None:
256-
otp_root = otpinfo.release_dir.path
257-
inputs = [otpinfo.release_dir]
258-
else:
259-
otp_root = otpinfo.erlang_home
260-
inputs = []
261-
inputs.append(otpinfo.version_file)
262-
263-
outs = []
264-
for f in ctx.attr.filenames:
265-
dest = ctx.actions.declare_file(path_join(ctx.label.name, f))
266-
commands.append("cp {otp}/lib/erlang/usr/include/{f} {dest}".format(
267-
otp = otp_root,
268-
f = f,
269-
dest = dest.path,
270-
))
271-
outs.append(dest)
272-
273-
ctx.actions.run_shell(
274-
inputs = inputs,
275-
outputs = outs,
276-
command = "\n".join(commands),
277-
)
278-
279-
return [DefaultInfo(files = depset(outs))]
280-
281-
erlang_headers = rule(
282-
implementation = _erlang_headers_impl,
283-
attrs = {
284-
"otp": attr.label(
285-
mandatory = True,
286-
providers = [OtpInfo],
287-
),
288-
"filenames": attr.string_list(
289-
default = [
290-
"driver_int.h",
291-
"ei.h",
292-
"ei_connect.h",
293-
"eicode.h",
294-
"erl_driver.h",
295-
"erl_drv_nif.h",
296-
"erl_fixed_size_int_types.h",
297-
"erl_int_sizes_config.h",
298-
"erl_memory_trace_parser.h",
299-
"erl_nif.h",
300-
"erl_nif_api_funcs.h",
301-
],
302-
),
303-
},
304-
)

tools/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
load("//tools:erlang_headers.bzl", "erlang_headers")
2+
13
toolchain_type(
24
name = "toolchain_type",
35
visibility = ["//visibility:public"],
46
)
7+
8+
erlang_headers(
9+
name = "erlang_headers",
10+
visibility = ["//visibility:public"],
11+
)

tools/erlang.bzl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ load(
22
"//private:erlang_build.bzl",
33
"erlang_build",
44
"erlang_external",
5+
)
6+
load(
7+
":erlang_headers.bzl",
58
"erlang_headers",
69
)
710
load(
@@ -60,12 +63,6 @@ def erlang_toolchain_from_http_archive(
6063
],
6164
)
6265

63-
erlang_headers(
64-
name = "otp_headers{}".format(name_suffix),
65-
otp = ":otp{}".format(name_suffix),
66-
visibility = ["//visibility:public"],
67-
)
68-
6966
erlang_toolchain(
7067
name = "erlang{}".format(name_suffix),
7168
otp = ":otp{}".format(name_suffix),

tools/erlang_headers.bzl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
load("//:util.bzl", "path_join")
2+
3+
def _erlang_headers_impl(ctx):
4+
commands = ["set -euo pipefail", ""]
5+
6+
otpinfo = ctx.toolchains["//tools:toolchain_type"].otpinfo
7+
8+
if otpinfo.release_dir != None:
9+
otp_root = otpinfo.release_dir.path
10+
inputs = [otpinfo.release_dir]
11+
else:
12+
otp_root = otpinfo.erlang_home
13+
inputs = []
14+
inputs.append(otpinfo.version_file)
15+
16+
outs = []
17+
for f in ctx.attr.filenames:
18+
dest = ctx.actions.declare_file(path_join(ctx.label.name, f))
19+
commands.append("cp {otp}/lib/erlang/usr/include/{f} {dest}".format(
20+
otp = otp_root,
21+
f = f,
22+
dest = dest.path,
23+
))
24+
outs.append(dest)
25+
26+
ctx.actions.run_shell(
27+
inputs = inputs,
28+
outputs = outs,
29+
command = "\n".join(commands),
30+
)
31+
32+
return [DefaultInfo(files = depset(outs))]
33+
34+
erlang_headers = rule(
35+
implementation = _erlang_headers_impl,
36+
attrs = {
37+
"filenames": attr.string_list(
38+
default = [
39+
"driver_int.h",
40+
"ei.h",
41+
"ei_connect.h",
42+
"eicode.h",
43+
"erl_driver.h",
44+
"erl_drv_nif.h",
45+
"erl_fixed_size_int_types.h",
46+
"erl_int_sizes_config.h",
47+
"erl_memory_trace_parser.h",
48+
"erl_nif.h",
49+
"erl_nif_api_funcs.h",
50+
],
51+
),
52+
},
53+
toolchains = [":toolchain_type"],
54+
)

0 commit comments

Comments
 (0)