Bazel rules for Erlang sources
erlang_lib
and ct_suite
macros require the standard otp layout, relative to the bazel package (to some degree abitrary layout can be handled with with the erlc
, app_file
, bazel_erlang_lib
& ct_test
rules which those macros utilize). For an erlang application named my_erlang_app
this means:
my_erlang_app
├── BUILD.bazel
├── include
│ ├── ...
│ └── my_header.hrl
├── priv
│ └── schema
├── src
│ ├── ...
│ └── my_erlang_app.erl
└── test
├── ...
└── unit_SUITE.erl
And that the convention is followed where, using the dest
attribute of the erlc
rule:
- Compiled production bytecode is placed in
ebin
- Compiled test bytecode is placed in
src
- Compiled test suite and test helper bytecode is placed in
test
The example below follows this convention.
http_archive(
name = "bazel-erlang",
sha256 = "f37c339711ce05b748688938ad9b1c00a78f0b2ef67d6baa734f5a34e33ad8a3",
strip_prefix = "bazel-erlang-1.4.0",
urls = ["https://github.com/rabbitmq/bazel-erlang/archive/refs/tags/1.4.0.zip"],
)
load("@bazel-erlang//:bazel_erlang.bzl", "bazel_erlang_deps")
bazel_erlang_deps()
load("@bazel-erlang//:bazel_erlang_lib.bzl", "erlang_lib", "test_erlang_lib")
load("@bazel-erlang//:xref.bzl", "xref")
load("@bazel-erlang//:dialyze.bzl", "dialyze", "plt")
load("@bazel-erlang//:ct_sharded.bzl", "ct_suite", "assert_suites")
APP_NAME = "my_cool_app"
APP_VERSION = "0.1.0
erlang_lib(
app_name = APP_NAME,
app_version = APP_VERSION,
)
test_erlang_lib(
app_name = APP_NAME,
app_version = APP_VERSION,
)
xref()
dialyze()
assert_suites([
ct_suite(
name = "unit_SUITE",
),
])
bazel test //... \
--@bazel-erlang//:erlang_home=/path/to/erlang \
--@bazel-erlang//:erlang_version=23.2
bazel test //:unit_SUITE \
--@bazel-erlang//:erlang_home=/path/to/erlang \
--@bazel-erlang//:erlang_version=23.2
bazel test //:unit_SUITE \
--@bazel-erlang//:erlang_home=/path/to/erlang \
--@bazel-erlang//:erlang_version=23.2 \
--test_env FOCUS="-group my_group -case my_case"
(c) 2020-2021, VMware Inc or its affiliates.
Dual licensed under the Apache License Version 2.0 and Mozilla Public License Version 2.0.
This means that the user can consider the library to be licensed under any of the licenses from the list above. For example, you may choose the Apache Public License 2.0 and include this library into a commercial product.
See LICENSE for details.