Skip to content

Commit

Permalink
bazel-erlang becomes rules_erlang at version 2
Browse files Browse the repository at this point in the history
Primary changes:
- Add Windows support (when using symlinks
https://docs.bazel.build/versions/main/windows.html#enable-symlink-support)
- Rework a lot of names based on a year of bazel knowledge

Note that the github actions workflow does not upload logs artifact in
windows due to a bug:
actions/upload-artifact#240
  • Loading branch information
HoloRin committed Jan 18, 2022
1 parent d62a135 commit b61cd18
Show file tree
Hide file tree
Showing 34 changed files with 1,738 additions and 1,407 deletions.
47 changes: 45 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: CHECKOUT
uses: actions/checkout@v2
- name: CONFIGURE ERLANG
uses: gleam-lang/setup-erlang@v1.1.2
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
- name: CONFIGURE BAZEL
Expand All @@ -33,7 +33,50 @@ jobs:
echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)"
id: resolve-test-logs-path
- name: CAPTURE TEST LOGS
uses: actions/upload-artifact@v2-preview
uses: actions/upload-artifact@v2
with:
name: bazel-testlogs-${{matrix.otp}}
path: ${{ steps.resolve-test-logs-path.outputs.LOGS_PATH }}/*
test-windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
otp:
- "23.2"
- "24.0"
steps:
- name: CHECKOUT
uses: actions/checkout@v2
- name: CONFIGURE ERLANG
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
- name: CONFIGURE BAZEL
shell: bash
run: |
ERL_PATH="$(which erl)"
cat << EOF >> .bazelrc
startup --windows_enable_symlinks
build --enable_runfiles
build --//:erlang_version=${{ matrix.otp }}
build --//:erlang_home="${ERL_PATH/\/bin\/erl/}"
build --incompatible_strict_action_env
EOF
cat .bazelrc
- name: TEST
run: |
bazelisk test //...
#! https://github.com/actions/upload-artifact/issues/240
#! - name: RESOVLE TEST LOGS PATH
#! run: |
#! Set-Variable -Name logs_path -Value (Get-Item bazel-testlogs).Target
#! Write-Output "::set-output name=LOGS_PATH::$logs_path"
#! id: resolve-test-logs-path
#! - name: CAPTURE TEST LOGS
#! uses: actions/upload-artifact@v2
#! with:
#! name: bazel-testlogs-${{matrix.otp}}
#! path: ${{ steps.resolve-test-logs-path.outputs.LOGS_PATH }}
5 changes: 0 additions & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
load("erlang_home.bzl", "erlang_home", "erlang_version")

exports_files([
"app_file.template",
"app_with_mod_file.template",
])

# This allows us to
# `bazel build //my/target \
# --@bazel-erlang//:erlang_home=/path/to/erlang/installation`
Expand Down
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# bazel_erlang
# rules_erlang

Bazel rules for Erlang sources

## Assumptions

`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:
`erlang_app` 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`, `erlang_app_info` & `ct_test` rules which those macros utilize). For an erlang application named `my_erlang_app` this means:

```
my_erlang_app
Expand Down Expand Up @@ -35,34 +35,33 @@ The example below follows this convention.

```starlark
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"],
name = "rules_erlang",
strip_prefix = "rules_erlang-v2",
urls = ["https://github.com/rabbitmq/rules_erlang/archive/refs/heads/v2.zip"],
)

load("@bazel-erlang//:bazel_erlang.bzl", "bazel_erlang_deps")
load("@rules_erlang//:rules_erlang.bzl", "rules_erlang_dependencies")

bazel_erlang_deps()
rules_erlang_dependencies()
```

### `BUILD` file

```starlark
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")
load("@rules_erlang//:erlang_app.bzl", "erlang_app", "test_erlang_app")
load("@rules_erlang//:xref.bzl", "xref")
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
load("@rules_erlang//:ct_sharded.bzl", "ct_suite", "assert_suites")

APP_NAME = "my_cool_app"
APP_VERSION = "0.1.0

erlang_lib(
erlang_app(
app_name = APP_NAME,
app_version = APP_VERSION,
)

test_erlang_lib(
test_erlang_app(
app_name = APP_NAME,
app_version = APP_VERSION,
)
Expand All @@ -82,24 +81,24 @@ assert_suites([

```shell
bazel test //... \
--@bazel-erlang//:erlang_home=/path/to/erlang \
--@bazel-erlang//:erlang_version=23.2
--@rules_erlang//:erlang_home=/path/to/erlang \
--@rules_erlang//:erlang_version=23.2
```

## Run the unit suite only

```shell
bazel test //:unit_SUITE \
--@bazel-erlang//:erlang_home=/path/to/erlang \
--@bazel-erlang//:erlang_version=23.2
--@rules_erlang//:erlang_home=/path/to/erlang \
--@rules_erlang//:erlang_version=23.2
```

## Run a single test case

```shell
bazel test //:unit_SUITE \
--@bazel-erlang//:erlang_home=/path/to/erlang \
--@bazel-erlang//:erlang_version=23.2 \
--@rules_erlang//:erlang_home=/path/to/erlang \
--@rules_erlang//:erlang_version=23.2 \
--test_env FOCUS="-group my_group -case my_case"
```

Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
load(":bazel_erlang.bzl", "bazel_erlang_deps")
load(":rules_erlang.bzl", "rules_erlang_dependencies")

bazel_erlang_deps()
rules_erlang_dependencies()
4 changes: 4 additions & 0 deletions app_file.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load("//private:app_file.bzl", "app_file_private")

def app_file(**kwargs):
app_file_private(**kwargs)
Loading

0 comments on commit b61cd18

Please sign in to comment.