Skip to content

Commit

Permalink
build: get different rebar3 based on different OTP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
JimMoen committed May 16, 2024
1 parent 03b5db6 commit e461923
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## The Official Releases using OTP 26 since EMQX v5.5.0
## See also
## https://github.com/emqx/emqx/releases/tag/v5.5.0
# erlang 26.2.1-2
# elixir 1.15.7-otp-26

## Keep using OTP 25.3.2 for docker image
## see also
## https://github.com/emqx/emqx/blob/v5.6.0/build#L400-L401
erlang 25.3.2-2
elixir 1.15.7-otp-25
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
export BUILD_WITHOUT_QUIC ?= true
export BUILD_WITHOUT_ROCKSDB ?= true

## shallow clone for speed
export REBAR_GIT_CLONE_OPTIONS += --depth=1

BUILD_WITHOUT_QUIC ?= true
export BUILD_WITHOUT_QUIC
BUILD_WITHOUT_ROCKSDB ?= true
export BUILD_WITHOUT_ROCKSDB
## Feature Used in rebar plugin emqx_plugrel
## The Feature have not enabled by default on OTP25
export ERL_FLAGS ?= -enable-feature maybe_expr

REBAR ?= $(or $(shell which rebar3 2>/dev/null),$(CURDIR)/rebar3)
REBAR_VERSION ?= 3.19.0-emqx-1
REBAR = $(CURDIR)/rebar3
SCRIPTS = $(CURDIR)/scripts

.PHONY: all
all: compile

.PHONY: get-rebar3
get-rebar3:
@$(CURDIR)/get-rebar3 $(REBAR_VERSION)
.PHONY: ensure-rebar3
ensure-rebar3:
@$(SCRIPTS)/ensure-rebar3.sh

$(REBAR):
$(MAKE) get-rebar3
$(MAKE) ensure-rebar3

.PHONY: compile
compile: $(REBAR)
Expand Down
43 changes: 43 additions & 0 deletions scripts/ensure-rebar3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -euo pipefail

[ "${DEBUG:-0}" -eq 1 ] && set -x

OTP_VSN="${OTP_VSN:-$(./scripts/get-otp-vsn.sh)}"
case ${OTP_VSN} in
25*)
VERSION="3.19.0-emqx-9"
;;
26*)
VERSION="3.20.0-emqx-1"
;;
*)
echo "Unsupported Erlang/OTP version $OTP_VSN"
exit 1
;;
esac

# ensure dir
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."

DOWNLOAD_URL='https://github.com/emqx/rebar3/releases/download'

download() {
echo "downloading rebar3 ${VERSION}"
curl -f -L "${DOWNLOAD_URL}/${VERSION}/rebar3" -o ./rebar3
}

# get the version number from the second line of the escript
# because command `rebar3 -v` tries to load rebar.config
# which is slow and may print some logs
version() {
head -n 2 ./rebar3 | tail -n 1 | tr ' ' '\n' | grep -E '^.+-emqx-.+'
}

if [ -f 'rebar3' ] && [ "$(version)" = "$VERSION" ]; then
exit 0
fi

download
chmod +x ./rebar3
5 changes: 5 additions & 0 deletions scripts/get-otp-vsn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

erl -noshell -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().'

0 comments on commit e461923

Please sign in to comment.