Skip to content

Commit 2c0ced9

Browse files
authored
Merge pull request #43 from rabbitmq/internal-erlang-with-platforms
* Introduce support for erlang built in the bazel build * Introduce erlang constraints and platforms * `xrefr` used in the `xref` rule is compiled from source for better compatibility * Rename rule `erlc` -> `erlang_bytecode` * Remove the `first_srcs` attribute from `erlang_app` (as it is mostly unnecessary) * Deduplicate ct.bzl and ct_sharded.bzl * Move tests into a test module that better demonstrates consumption of the library from an external repository * Various other minor changes
2 parents 371d4ad + 11bc47e commit 2c0ced9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2033
-1311
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

.bazelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build --experimental_enable_bzlmod
2+
build --incompatible_strict_action_env
3+
4+
build --platforms=//platforms:erlang_external_platform
5+
build --extra_execution_platforms=//platforms:erlang_external_platform
6+
7+
try-import %workspace%/user.bazelrc

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
latest

.github/workflows/test.yaml

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ jobs:
1717
with:
1818
otp-version: ${{ matrix.otp }}
1919
- name: CONFIGURE BAZEL
20+
working-directory: test
2021
run: |
2122
ERLANG_HOME="$(dirname $(dirname $(which erl)))"
22-
cat << EOF >> .bazelrc
23-
build --//:erlang_version=${{ matrix.otp }}
24-
build --//:erlang_home=${ERLANG_HOME}
25-
26-
build --incompatible_strict_action_env
23+
cat << EOF >> user.bazelrc
24+
build --@rules_erlang//:erlang_version=${{ matrix.otp }}
25+
build --@rules_erlang//:erlang_home=${ERLANG_HOME}
2726
EOF
2827
- name: TEST
28+
working-directory: test
2929
run: |
30-
bazelisk test //...
30+
bazelisk test //... \
31+
--noexperimental_enable_bzlmod \
32+
--config=local
3133
- name: RESOVLE TEST LOGS PATH
34+
working-directory: test
3235
run: |
3336
echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)"
3437
id: resolve-test-logs-path
@@ -53,22 +56,22 @@ jobs:
5356
with:
5457
otp-version: ${{ matrix.otp }}
5558
- name: CONFIGURE BAZEL
59+
working-directory: test
5660
shell: bash
5761
run: |
5862
ERL_PATH="$(which erl)"
59-
cat << EOF >> .bazelrc
63+
cat << EOF >> user.bazelrc
6064
startup --windows_enable_symlinks
6165
build --enable_runfiles
6266
63-
build --//:erlang_version=${{ matrix.otp }}
64-
build --//:erlang_home="${ERL_PATH/\/bin\/erl/}"
65-
66-
build --incompatible_strict_action_env
67+
build --@rules_erlang//:erlang_version=${{ matrix.otp }}
68+
build --@rules_erlang//:erlang_home="${ERL_PATH/\/bin\/erl/}"
6769
EOF
6870
cat .bazelrc
6971
- name: TEST
72+
working-directory: test
7073
run: |
71-
bazelisk test //...
74+
bazelisk test //... --noexperimental_enable_bzlmod --config=local
7275
#! https://github.com/actions/upload-artifact/issues/240
7376
#! - name: RESOVLE TEST LOGS PATH
7477
#! run: |
@@ -96,18 +99,47 @@ jobs:
9699
with:
97100
otp-version: ${{ matrix.otp }}
98101
- name: CONFIGURE BAZEL
102+
working-directory: test
99103
run: |
100104
ERLANG_HOME="$(dirname $(dirname $(which erl)))"
101-
cat << EOF >> .bazelrc
102-
build --//:erlang_version=${{ matrix.otp }}
103-
build --//:erlang_home=${ERLANG_HOME}
104-
105-
build --incompatible_strict_action_env
105+
cat << EOF >> user.bazelrc
106+
build --@rules_erlang//:erlang_version=${{ matrix.otp }}
107+
build --@rules_erlang//:erlang_home=${ERLANG_HOME}
106108
EOF
107109
- name: TEST
110+
working-directory: test
111+
run: |
112+
bazelisk test //... \
113+
--config=local
114+
- name: RESOVLE TEST LOGS PATH
115+
working-directory: test
116+
run: |
117+
echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)"
118+
id: resolve-test-logs-path
119+
- name: CAPTURE TEST LOGS
120+
uses: actions/upload-artifact@v2
121+
with:
122+
name: bazel-testlogs-bzlmod-${{matrix.otp}}
123+
path: ${{ steps.resolve-test-logs-path.outputs.LOGS_PATH }}/*
124+
test-bzlmod-internal-erlang:
125+
runs-on: ubuntu-latest
126+
steps:
127+
- name: CHECKOUT
128+
uses: actions/checkout@v2
129+
#! - name: CONFIGURE BAZEL
130+
#! working-directory: test
131+
#! run: |
132+
#! cat << EOF >> user.bazelrc
133+
#! build:rbe --host_cpu=k8
134+
#! build:rbe --cpu=k8
135+
#! EOF
136+
- name: TEST
137+
working-directory: test
108138
run: |
109-
bazelisk test //... --experimental_enable_bzlmod
139+
bazelisk test //... \
140+
--config=rbe
110141
- name: RESOVLE TEST LOGS PATH
142+
working-directory: test
111143
run: |
112144
echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)"
113145
id: resolve-test-logs-path

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/.bazelrc
21
/bazel-*
2+
/user.bazelrc

BUILD.bazel

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
load("erlang_home.bzl", "erlang_home", "erlang_version")
1+
load(
2+
"@bazel_skylib//rules:common_settings.bzl",
3+
"string_flag",
4+
)
25

3-
# This allows us to
4-
# `bazel build //my/target \
5-
# --@bazel-erlang//:erlang_home=/path/to/erlang/installation`
6-
erlang_home(
6+
string_flag(
77
name = "erlang_home",
8-
build_setting_default = "~/kerl/23.1",
8+
build_setting_default = "",
99
visibility = ["//visibility:public"],
1010
)
1111

12-
# This allows us to
13-
# `bazel build //my/target \
14-
# --@bazel-erlang//:erlang_version=23.1`
15-
erlang_version(
12+
string_flag(
1613
name = "erlang_version",
17-
build_setting_default = "23.1",
14+
build_setting_default = "",
1815
visibility = ["//visibility:public"],
1916
)
17+
18+
load(
19+
"//tools:erlang.bzl",
20+
"erlang_toolchain_external",
21+
)
22+
23+
erlang_toolchain_external()

MODULE.bazel

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
module(
22
name = "rules_erlang",
3-
version = "2.5.2",
4-
compatibility_level = 2,
3+
version = "3.0.0",
4+
compatibility_level = 3,
55
)
66

7-
download_xrefr = use_extension(
7+
bazel_dep(
8+
name = "bazel_skylib",
9+
version = "1.2.0",
10+
)
11+
12+
erlang_package = use_extension(
813
"//bzlmod:extensions.bzl",
9-
"download_xrefr",
14+
"erlang_package",
1015
)
1116

1217
use_repo(
13-
download_xrefr,
14-
"xrefr",
18+
erlang_package,
19+
"getopt_src",
20+
"xref_runner_src",
1521
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rules_erlang_dependencies()
2525
load("@rules_erlang//:erlang_app.bzl", "erlang_app", "test_erlang_app")
2626
load("@rules_erlang//:xref.bzl", "xref")
2727
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
28-
load("@rules_erlang//:ct_sharded.bzl", "ct_suite", "assert_suites")
28+
load("@rules_erlang//:ct.bzl", "ct_suite", "assert_suites")
2929

3030
APP_NAME = "my_cool_app"
3131
APP_VERSION = "0.1.0

WORKSPACE.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
http_archive(
4+
name = "bazel_skylib",
5+
sha256 = "af87959afe497dc8dfd4c6cb66e1279cb98ccc84284619ebfec27d9c09a903de",
6+
urls = [
7+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.0/bazel-skylib-1.2.0.tar.gz",
8+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.0/bazel-skylib-1.2.0.tar.gz",
9+
],
10+
)
11+
12+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
13+
14+
bazel_skylib_workspace()
15+
116
load(":rules_erlang.bzl", "rules_erlang_dependencies")
217

318
rules_erlang_dependencies()
19+
20+
register_toolchains(
21+
":erlang_toolchain_external",
22+
)

app_file.bzl

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
load("//private:app_file.bzl", "app_file_private")
1+
load(
2+
"//private:app_file.bzl",
3+
_app_file = "app_file",
4+
)
25

3-
_stamp_condition = Label("//private:private_stamp_detect")
4-
5-
def app_file(
6-
app_extra_keys = [],
7-
app_extra = "",
8-
**kwargs):
9-
if len(app_extra_keys) > 0 and app_extra != "":
10-
all_app_extra = ",".join(app_extra_keys + [app_extra])
11-
elif len(app_extra_keys) > 0:
12-
all_app_extra = ",".join(app_extra_keys)
13-
else:
14-
all_app_extra = app_extra
15-
16-
app_file_private(
6+
def app_file(**kwargs):
7+
_app_file(
8+
app_file_tool = Label("//tools/app_file_tool:app_file_tool"),
179
private_stamp_detect = select({
18-
_stamp_condition: True,
10+
Label("//private:private_stamp_detect"): True,
1911
"//conditions:default": False,
2012
}),
21-
app_extra_keys = all_app_extra,
2213
**kwargs
2314
)

0 commit comments

Comments
 (0)