Skip to content

Commit

Permalink
Merge pull request #216 from rabbitmq/extra-internal-erlang-opts
Browse files Browse the repository at this point in the history
Expose additional erlang_build opts through the erlang_config repo
  • Loading branch information
pjk25 committed Jun 27, 2023
2 parents 2d8f46e + de7a51c commit 287e45c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
18 changes: 18 additions & 0 deletions bzlmod/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def _erlang_config(ctx):
strip_prefixs = {}
sha256s = {}
erlang_homes = {}
pre_configure_cmdss = {}
extra_configure_optss = {}
post_configure_cmdss = {}
owners_by_name = {}

for mod in ctx.modules:
Expand Down Expand Up @@ -66,6 +69,9 @@ def _erlang_config(ctx):
urls[erlang.name] = erlang.url
strip_prefixs[erlang.name] = erlang.strip_prefix
sha256s[erlang.name] = erlang.sha256
pre_configure_cmdss[erlang.name] = erlang.pre_configure_cmds
extra_configure_optss[erlang.name] = erlang.extra_configure_opts
post_configure_cmdss[erlang.name] = erlang.post_configure_cmds
owners_by_name[erlang.name] = mod

for erlang in mod.tags.internal_erlang_from_github_release:
Expand All @@ -90,6 +96,9 @@ def _erlang_config(ctx):
urls[erlang.name] = url
strip_prefixs[erlang.name] = strip_prefix
sha256s[erlang.name] = sha256
pre_configure_cmdss[erlang.name] = erlang.pre_configure_cmds
extra_configure_optss[erlang.name] = erlang.extra_configure_opts
post_configure_cmdss[erlang.name] = erlang.post_configure_cmds
owners_by_name[erlang.name] = mod

_erlang_config_rule(
Expand All @@ -101,6 +110,9 @@ def _erlang_config(ctx):
strip_prefixs = strip_prefixs,
sha256s = sha256s,
erlang_homes = erlang_homes,
pre_configure_cmdss = pre_configure_cmdss,
extra_configure_optss = extra_configure_optss,
post_configure_cmdss = post_configure_cmdss,
)

external_erlang_from_path = tag_class(attrs = {
Expand All @@ -115,6 +127,9 @@ internal_erlang_from_http_archive = tag_class(attrs = {
"url": attr.string(),
"strip_prefix": attr.string(),
"sha256": attr.string(),
"pre_configure_cmds": attr.string_list(),
"extra_configure_opts": attr.string_list(),
"post_configure_cmds": attr.string_list(),
})

internal_erlang_from_github_release = tag_class(attrs = {
Expand All @@ -125,6 +140,9 @@ internal_erlang_from_github_release = tag_class(attrs = {
default = DEFAULT_ERLANG_VERSION,
),
"sha256": attr.string(),
"pre_configure_cmds": attr.string_list(),
"extra_configure_opts": attr.string_list(),
"post_configure_cmds": attr.string_list(),
})

erlang_config = module_extension(
Expand Down
2 changes: 1 addition & 1 deletion erlang_app.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _erlang_app(
copy_file(
name = "appup",
src = "src/{}.appup".format(app_name),
out = "ebin/{}.appup".format(app_name)
out = "ebin/{}.appup".format(app_name),
)
appup = ":appup"
else:
Expand Down
9 changes: 8 additions & 1 deletion private/erlang_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _erlang_build_impl(ctx):
version_file = ctx.actions.declare_file(ctx.label.name + "_version")

extra_configure_opts = " ".join(ctx.attr.extra_configure_opts)
pre_configure_cmds = "\n".join(ctx.attr.pre_configure_cmds)
post_configure_cmds = "\n".join(ctx.attr.post_configure_cmds)
extra_make_opts = " ".join(ctx.attr.extra_make_opts)

Expand Down Expand Up @@ -109,10 +110,14 @@ tar --extract \\
echo "Building OTP $(cat $ABS_BUILD_DIR/OTP_VERSION) in $ABS_BUILD_DIR"
cd "$ABS_BUILD_DIR"
{pre_configure_cmds}
./configure --prefix={install_path} {extra_configure_opts} >> "$ABS_LOG" 2>&1
{post_configure_cmds}
echo "\tconfigure finished"
make {extra_make_opts} >> "$ABS_LOG" 2>&1
echo "\tmake finished"
make DESTDIR="$ABS_DEST_DIR" install >> "$ABS_LOG" 2>&1
echo "\tmake install finished"
tar --create \\
--file $ABS_BUILD_DIR_TAR \\
Expand All @@ -131,6 +136,7 @@ tar --create \\
install_root = install_root,
build_log = build_log.path,
extra_configure_opts = extra_configure_opts,
pre_configure_cmds = pre_configure_cmds,
post_configure_cmds = post_configure_cmds,
extra_make_opts = extra_make_opts,
),
Expand Down Expand Up @@ -192,8 +198,9 @@ erlang_build = rule(
"strip_prefix": attr.string(),
"sha256": attr.string(),
"install_prefix": attr.string(default = DEFAULT_INSTALL_PREFIX),
"pre_configure_cmds": attr.string_list(),
"extra_configure_opts": attr.string_list(),
"post_configure_cmds": attr.string_list(), # <- hopefully don't need this
"post_configure_cmds": attr.string_list(),
"extra_make_opts": attr.string_list(
default = ["-j 8"],
),
Expand Down
3 changes: 3 additions & 0 deletions repositories/BUILD_internal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ erlang_build(
url = "%{URL}",
strip_prefix = "%{STRIP_PREFIX}",
sha256 = "%{SHA_256}",
pre_configure_cmds = %{PRE_CONFIGURE_CMDS},
extra_configure_opts = %{EXTRA_CONFIGURE_OPTS},
post_configure_cmds = %{POST_CONFIGURE_CMDS},
)

erlang_toolchain(
Expand Down
12 changes: 12 additions & 0 deletions repositories/erlang_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def _parse_maybe_semver(version_string):
else:
return (parts[0], _ERLANG_VERSION_UNKNOWN.lower())

def _to_string_list(strings):
return "[%s]" % ",".join(['"%s"' % s.replace('"', '\\"') for s in strings])

def _impl(repository_ctx):
rules_erlang_workspace = repository_ctx.attr.rules_erlang_workspace

Expand All @@ -39,6 +42,9 @@ def _impl(repository_ctx):
strip_prefix = repository_ctx.attr.strip_prefixs.get(name, None),
sha256 = repository_ctx.attr.sha256s.get(name, None),
erlang_home = repository_ctx.attr.erlang_homes.get(name, None),
pre_configure_cmds = repository_ctx.attr.pre_configure_cmdss.get(name, []),
extra_configure_opts = repository_ctx.attr.extra_configure_optss.get(name, []),
post_configure_cmds = repository_ctx.attr.post_configure_cmdss.get(name, []),
)

for (name, props) in erlang_installations.items():
Expand Down Expand Up @@ -69,6 +75,9 @@ def _impl(repository_ctx):
"%{ERLANG_MAJOR}": props.major,
"%{ERLANG_MINOR}": props.minor,
"%{RULES_ERLANG_WORKSPACE}": rules_erlang_workspace,
"%{PRE_CONFIGURE_CMDS}": _to_string_list(props.pre_configure_cmds),
"%{EXTRA_CONFIGURE_OPTS}": _to_string_list(props.extra_configure_opts),
"%{POST_CONFIGURE_CMDS}": _to_string_list(props.post_configure_cmds),
},
False,
)
Expand Down Expand Up @@ -111,6 +120,9 @@ erlang_config = repository_rule(
"strip_prefixs": attr.string_dict(),
"sha256s": attr.string_dict(),
"erlang_homes": attr.string_dict(),
"pre_configure_cmdss": attr.string_list_dict(),
"extra_configure_optss": attr.string_list_dict(),
"post_configure_cmdss": attr.string_list_dict(),
},
environ = [
ERLANG_HOME_ENV_VAR,
Expand Down
22 changes: 20 additions & 2 deletions rules_erlang.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def erlang_config(
urls = {c.name: c.url for c in internal_erlang_configs}
strip_prefixs = {c.name: c.strip_prefix for c in internal_erlang_configs if c.strip_prefix}
sha256s = {c.name: c.sha256 for c in internal_erlang_configs if c.sha256}
pre_configure_cmdss = {c.name: c.pre_configure_cmds for c in internal_erlang_configs if c.pre_configure_cmds}
extra_configure_optss = {c.name: c.extra_configure_opts for c in internal_erlang_configs if c.extra_configure_opts}
post_configure_cmdss = {c.name: c.post_configure_cmds for c in internal_erlang_configs if c.post_configure_cmds}

_erlang_config(
name = "erlang_config",
Expand All @@ -68,26 +71,38 @@ def erlang_config(
urls = urls,
strip_prefixs = strip_prefixs,
sha256s = sha256s,
pre_configure_cmdss = pre_configure_cmdss,
extra_configure_optss = extra_configure_optss,
post_configure_cmdss = post_configure_cmdss,
)

def internal_erlang_from_http_archive(
name = None,
version = None,
url = None,
strip_prefix = None,
sha256 = None):
sha256 = None,
pre_configure_cmds = None,
extra_configure_opts = None,
post_configure_cmds = None):
return struct(
name = name,
version = version,
url = url,
strip_prefix = strip_prefix,
sha256 = sha256,
pre_configure_cmds = pre_configure_cmds,
extra_configure_opts = extra_configure_opts,
post_configure_cmds = post_configure_cmds,
)

def internal_erlang_from_github_release(
name = "internal",
version = DEFAULT_ERLANG_VERSION,
sha256 = None):
sha256 = None,
pre_configure_cmds = None,
extra_configure_opts = None,
post_configure_cmds = None):
url = "https://github.com/erlang/otp/releases/download/OTP-{v}/otp_src_{v}.tar.gz".format(
v = version,
)
Expand All @@ -101,4 +116,7 @@ def internal_erlang_from_github_release(
url = url,
strip_prefix = "otp_src_{}".format(version),
sha256 = sha256,
pre_configure_cmds = pre_configure_cmds,
extra_configure_opts = extra_configure_opts,
post_configure_cmds = post_configure_cmds,
)

0 comments on commit 287e45c

Please sign in to comment.