Skip to content

Commit

Permalink
Apply the @erlang_config pattern for elixir via the WORKSPACE
Browse files Browse the repository at this point in the history
and use rules_erlang 3.7.0
  • Loading branch information
HoloRin committed Sep 28, 2022
1 parent 6d35adc commit 502730b
Show file tree
Hide file tree
Showing 15 changed files with 556 additions and 99 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,25 @@ jobs:
otp-version: ${{ steps.load-info.outputs.otp }}
elixir-version: ${{ steps.load-info.outputs.elixir }}

- name: Further Configure Bazel
run: |
ELIXIR_HOME="$(dirname $(dirname $(which iex)))"
cat << EOF >> user.bazelrc
build --elixir_home=${ELIXIR_HOME}
EOF
- name: Build
run: |
export ERLANG_HOME="$(dirname $(dirname $(which erl)))"
export ELIXIR_HOME="$(dirname $(dirname $(which iex)))"
bazelisk build //packaging/docker-image:rabbitmq \
--config=buildbuddy
- name: Test
run: |
export ERLANG_HOME="$(dirname $(dirname $(which erl)))"
export ELIXIR_HOME="$(dirname $(dirname $(which iex)))"
OCI_TESTS=$(bazel query 'tests(//packaging/docker-image/...)')
bazelisk test ${OCI_TESTS} \
--config=buildbuddy
- name: Load
run: |
export ERLANG_HOME="$(dirname $(dirname $(which erl)))"
export ELIXIR_HOME="$(dirname $(dirname $(which iex)))"
bazelisk run //packaging/docker-image:rabbitmq \
--config=buildbuddy
Expand Down
27 changes: 15 additions & 12 deletions .github/workflows/update-elixir-patches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
matrix:
include:
- elixir_version: "1.10"
name_suffix: '_1_10'
name: '1_10'
- elixir_version: "1.12"
name_suffix: '_1_12'
name: '1_12'
- elixir_version: "1.13"
name_suffix: '_1_13'
name: '1_13'
- elixir_version: "1.14"
name_suffix: '_1_14'
name: '1_14'
timeout-minutes: 10
steps:
- name: CHECKOUT REPOSITORY
Expand All @@ -30,7 +30,7 @@ jobs:
set +e
git ls-remote --exit-code --heads origin bump-elixir-${{ matrix.elixir_version }}
echo "::set-output name=c::$?"
- name: DETERMINE LATEST PATCH
- name: DETERMINE LATEST PATCH & SHA
if: steps.check-for-branch.outputs.c != 0
id: fetch-version
run: |
Expand All @@ -42,7 +42,8 @@ jobs:
exit 1
fi
wget --continue --quiet --output-document="/tmp/elixir.tar.gz" "https://github.com/elixir-lang/elixir/archive/${TAG_NAME}.tar.gz" && \
ARCHIVE_URL="https://github.com/elixir-lang/elixir/archive/${TAG_NAME}.tar.gz"
wget --continue --quiet --output-document="/tmp/elixir.tar.gz" "${ARCHIVE_URL}" && \
SHA="$(shasum -a 256 "/tmp/elixir.tar.gz" | awk '{print $1}')"
if [[ -z "${SHA}" ]]; then
Expand All @@ -57,13 +58,15 @@ jobs:
run: |
sudo npm install --global --silent @bazel/buildozer
LINE=$(grep -n 'name_suffix = "${{ matrix.name_suffix }}",' bazel/toolchains/BUILD.bazel | awk -F ":" '{print $1}')
LINE=$(($LINE-1))
OLD_SHA="$(cat MODULE.bazel | buildozer 'print sha256' -:${{ matrix.name }})"
OLD_VERSION="$(cat MODULE.bazel | buildozer 'print version' -:${{ matrix.name }})"
buildozer 'set sha256 "${{ steps.fetch-version.outputs.SHA }}"' \
//bazel/toolchains:%${LINE} || test $? -eq 3
buildozer 'set version "${{ steps.fetch-version.outputs.VERSION }}"' \
//bazel/toolchains:%${LINE} || test $? -eq 3
echo "$(cat MODULE.bazel | buildozer 'set sha256 "${{ steps.fetch-version.outputs.SHA }}"' -:${{ matrix.name }})" > MODULE.bazel
echo "$(cat MODULE.bazel | buildozer 'set version "${{ steps.fetch-version.outputs.VERSION }}"' -:${{ matrix.name }})" > MODULE.bazel
sed -i"_orig" "s/${OLD_SHA}/${{ steps.fetch-version.outputs.SHA }}/" WORKSPACE
sed -i"_orig" "s/${OLD_VERSION}/${{ steps.fetch-version.outputs.VERSION }}/" WORKSPACE
rm *_orig
set -x
git diff
Expand Down
43 changes: 38 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bazel_dep(

bazel_dep(
name = "rules_erlang",
version = "3.6.3",
version = "3.7.0",
)

erlang_config = use_extension(
Expand Down Expand Up @@ -63,16 +63,48 @@ use_repo(
"erlang_config",
)

elixir_config = use_extension(
"//bazel/bzlmod:extensions.bzl",
"elixir_config",
)

elixir_config.internal_elixir_from_github_release(
name = "1_10",
sha256 = "8518c78f43fe36315dbe0d623823c2c1b7a025c114f3f4adbb48e04ef63f1d9f",
version = "1.10.4",
)
elixir_config.internal_elixir_from_github_release(
name = "1_12",
sha256 = "c5affa97defafa1fd89c81656464d61da8f76ccfec2ea80c8a528decd5cb04ad",
version = "1.12.3",
)
elixir_config.internal_elixir_from_github_release(
name = "1_13",
sha256 = "95daf2dd3052e6ca7d4d849457eaaba09de52d65ca38d6933c65bc1cdf6b8579",
version = "1.13.4",
)
elixir_config.internal_elixir_from_github_release(
name = "1_14",
sha256 = "ac129e266a1e04cdc389551843ec3dbdf36086bb2174d3d7e7936e820735003b",
version = "1.14.0",
)

use_repo(
elixir_config,
"elixir_config",
)

register_toolchains(
"@erlang_config//external:toolchain",
"@erlang_config//23:toolchain",
"@erlang_config//24:toolchain",
"@erlang_config//25:toolchain",
"@erlang_config//git_master:toolchain",
"//bazel/toolchains:elixir_toolchain_external",
"//bazel/toolchains:elixir_toolchain_1_10",
"//bazel/toolchains:elixir_toolchain_1_12",
"//bazel/toolchains:elixir_toolchain_1_13",
"@elixir_config//external:toolchain",
"@elixir_config//1_10:toolchain",
"@elixir_config//1_12:toolchain",
"@elixir_config//1_13:toolchain",
"@elixir_config//1_14:toolchain",
)

erlang_package = use_extension(
Expand Down Expand Up @@ -378,6 +410,7 @@ use_repo(
secondary_umbrella = use_extension(
"//bazel/bzlmod:extensions.bzl",
"secondary_umbrella",
dev_dependency = True,
)

use_repo(
Expand Down
45 changes: 38 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ git_repository(
git_repository(
name = "rules_erlang",
remote = "https://github.com/rabbitmq/rules_erlang.git",
tag = "3.6.3",
tag = "3.7.0",
)

load(
Expand Down Expand Up @@ -155,14 +155,45 @@ load("@erlang_config//:defaults.bzl", "register_defaults")

register_defaults()

register_toolchains(
"//bazel/toolchains:elixir_toolchain_external",
"//bazel/toolchains:elixir_toolchain_1_10",
"//bazel/toolchains:elixir_toolchain_1_12",
"//bazel/toolchains:elixir_toolchain_1_13",
"//bazel/toolchains:elixir_toolchain_1_14",
load(
"//bazel/elixir:elixir.bzl",
"elixir_config",
"internal_elixir_from_github_release",
)

elixir_config(
internal_elixir_configs = [
internal_elixir_from_github_release(
name = "1_10",
sha256 = "8518c78f43fe36315dbe0d623823c2c1b7a025c114f3f4adbb48e04ef63f1d9f",
version = "1.10.4",
),
internal_elixir_from_github_release(
name = "1_12",
sha256 = "c5affa97defafa1fd89c81656464d61da8f76ccfec2ea80c8a528decd5cb04ad",
version = "1.12.3",
),
internal_elixir_from_github_release(
name = "1_13",
sha256 = "95daf2dd3052e6ca7d4d849457eaaba09de52d65ca38d6933c65bc1cdf6b8579",
version = "1.13.4",
),
internal_elixir_from_github_release(
name = "1_14",
sha256 = "ac129e266a1e04cdc389551843ec3dbdf36086bb2174d3d7e7936e820735003b",
version = "1.14.0",
),
],
rabbitmq_server_workspace = "@",
)

load(
"@elixir_config//:defaults.bzl",
register_elixir_defaults = "register_defaults",
)

register_elixir_defaults()

load("//:workspace_helpers.bzl", "rabbitmq_external_deps")

rabbitmq_external_deps(rabbitmq_workspace = "@")
Expand Down
90 changes: 90 additions & 0 deletions bazel/bzlmod/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,96 @@ load(
":secondary_umbrella.bzl",
fetch_secondary_umbrella = "secondary_umbrella",
)
load(
"//bazel/repositories:elixir_config.bzl",
"INSTALLATION_TYPE_EXTERNAL",
"INSTALLATION_TYPE_INTERNAL",
_elixir_config_rule = "elixir_config",
)
load(
"//bazel/elixir:elixir.bzl",
"DEFAULT_ELIXIR_SHA256",
"DEFAULT_ELIXIR_VERSION",
)

def _elixir_config(ctx):
types = {}
versions = {}
urls = {}
strip_prefixs = {}
sha256s = {}
elixir_homes = {}

for mod in ctx.modules:
for elixir in mod.tags.external_elixir_from_path:
types[elixir.name] = INSTALLATION_TYPE_EXTERNAL
versions[elixir.name] = elixir.version
elixir_homes[elixir.name] = elixir.elixir_home

for elixir in mod.tags.internal_elixir_from_http_archive:
types[elixir.name] = INSTALLATION_TYPE_INTERNAL
versions[elixir.name] = elixir.version
urls[elixir.name] = elixir.url
strip_prefixs[elixir.name] = elixir.strip_prefix
sha256s[elixir.name] = elixir.sha256

for elixir in mod.tags.internal_elixir_from_github_release:
url = "https://github.com/elixir-lang/elixir/archive/refs/tags/v{}.tar.gz".format(
elixir.version,
)
strip_prefix = "elixir-{}".format(elixir.version)

types[elixir.name] = INSTALLATION_TYPE_INTERNAL
versions[elixir.name] = elixir.version
urls[elixir.name] = url
strip_prefixs[elixir.name] = strip_prefix
sha256s[elixir.name] = elixir.sha256

_elixir_config_rule(
name = "elixir_config",
rabbitmq_server_workspace = "@rabbitmq-server",
types = types,
versions = versions,
urls = urls,
strip_prefixs = strip_prefixs,
sha256s = sha256s,
elixir_homes = elixir_homes,
)

external_elixir_from_path = tag_class(attrs = {
"name": attr.string(),
"version": attr.string(),
"elixir_home": attr.string(),
})

internal_elixir_from_http_archive = tag_class(attrs = {
"name": attr.string(),
"version": attr.string(),
"url": attr.string(),
"strip_prefix": attr.string(),
"sha256": attr.string(),
})

internal_elixir_from_github_release = tag_class(attrs = {
"name": attr.string(
default = "internal",
),
"version": attr.string(
default = DEFAULT_ELIXIR_VERSION,
),
"sha256": attr.string(
default = DEFAULT_ELIXIR_SHA256,
),
})

elixir_config = module_extension(
implementation = _elixir_config,
tag_classes = {
"external_elixir_from_path": external_elixir_from_path,
"internal_elixir_from_http_archive": internal_elixir_from_http_archive,
"internal_elixir_from_github_release": internal_elixir_from_github_release,
},
)

def _rbe(ctx):
rbe_repo_props = []
Expand Down
Loading

0 comments on commit 502730b

Please sign in to comment.