2022-11-30 20:02:39 +00:00
# Copyright (c) 2022 Status Research & Development GmbH. Licensed under
2020-04-30 15:51:30 +00:00
# either of:
# - Apache License, version 2.0
# - MIT license
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
BUILD_SYSTEM_DIR := vendor/nimbus-build-system
2022-01-24 11:48:06 +00:00
EXCLUDED_NIM_PACKAGES := vendor/nim-dnsdisc/vendor
2021-06-15 07:51:09 +00:00
LINK_PCRE := 0
2023-05-23 08:44:57 +00:00
LOG_LEVEL := TRACE
2021-06-15 07:51:09 +00:00
2020-04-30 15:51:30 +00:00
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
- i n c l u d e $( BUILD_SYSTEM_DIR ) / m a k e f i l e s / v a r i a b l e s . m k
2020-04-29 04:49:27 +00:00
2020-04-29 05:54:03 +00:00
2020-04-30 15:51:30 +00:00
i f e q ( $( NIM_PARAMS ) , )
# "variables.mk" was not included, so we update the submodules.
GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
.DEFAULT :
+@ echo -e " Git submodules not found. Running ' $( GIT_SUBMODULE_UPDATE) '.\n " ; \
$( GIT_SUBMODULE_UPDATE) ; \
echo
# Now that the included *.mk files appeared, and are newer than this file, Make will restart itself:
# https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles
#
# After restarting, it will execute its original goal, so we don't have to start a child Make here
# with "$(MAKE) $(MAKECMDGOALS)". Isn't hidden control flow great?
2020-05-01 05:00:00 +00:00
2020-04-30 15:51:30 +00:00
e l s e # "variables.mk" was included. Business as usual until the end of this file.
2024-05-22 01:00:22 +00:00
i f e q ( $( OS ) , W i n d o w s _ N T ) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
e l s e
detected_OS := $( strip $( shell uname) )
e n d i f
2022-11-30 20:02:39 +00:00
##########
## Main ##
##########
2023-08-09 17:11:50 +00:00
.PHONY : all test update clean
2022-11-30 20:02:39 +00:00
2020-04-30 15:51:30 +00:00
# default target, because it's the first one that doesn't start with '.'
2023-09-25 06:15:43 +00:00
all : | wakunode 2 example 2 chat 2 chat 2bridge libwaku
2021-06-23 17:14:37 +00:00
2023-08-09 17:11:50 +00:00
test : | testcommon testwaku
2022-11-07 08:14:21 +00:00
2022-11-30 20:02:39 +00:00
waku.nims :
ln -s waku.nimble $@
update : | update -common
rm -rf waku.nims && \
$( MAKE) waku.nims $( HANDLE_OUTPUT)
2022-11-07 08:14:21 +00:00
2022-11-30 20:02:39 +00:00
clean :
rm -rf build
2020-04-30 15:51:30 +00:00
# must be included after the default target
- i n c l u d e $( BUILD_SYSTEM_DIR ) / m a k e f i l e s / t a r g e t s . m k
2023-04-25 15:54:28 +00:00
## Possible values: prod; debug
TARGET ?= prod
2022-11-07 08:14:21 +00:00
2022-11-30 20:02:39 +00:00
## Git version
GIT_VERSION ?= $( shell git describe --abbrev= 6 --always --tags)
2024-02-23 14:25:13 +00:00
## Compilation parameters. If defined in the CLI the assignments won't be executed
2022-11-30 20:02:39 +00:00
NIM_PARAMS := $( NIM_PARAMS) -d:git_version= \" $( GIT_VERSION) \"
2023-04-25 15:54:28 +00:00
## Heaptracker options
HEAPTRACKER ?= 0
HEAPTRACKER_INJECT ?= 0
i f e q ( $( HEAPTRACKER ) , 1 )
# Needed to make nimbus-build-system use the Nim's 'heaptrack_support' branch
DOCKER_NIM_COMMIT := NIM_COMMIT = heaptrack_support
TARGET := debug
i f e q ( $( HEAPTRACKER_INJECT ) , 1 )
# the Nim compiler will load 'libheaptrack_inject.so'
HEAPTRACK_PARAMS := -d:heaptracker -d:heaptracker_inject
e l s e
# the Nim compiler will load 'libheaptrack_preload.so'
HEAPTRACK_PARAMS := -d:heaptracker
e n d i f
e n d i f
## end of Heaptracker options
2022-11-30 20:02:39 +00:00
##################
## Dependencies ##
##################
.PHONY : deps libbacktrace
2024-02-22 11:29:13 +00:00
rustup :
i f e q ( , $( shell which cargo ) )
# Install Rustup if it's not installed
# -y: Assume "yes" for all prompts
# --default-toolchain stable: Install the stable toolchain
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
e n d i f
anvil : rustup
i f e q ( , $( shell which anvil ) )
# Install Anvil if it's not installed
./scripts/install_anvil.sh
e n d i f
2022-11-30 20:02:39 +00:00
deps : | deps -common nat -libs waku .nims
### nim-libbacktrace
2022-11-07 08:14:21 +00:00
2020-04-30 15:51:30 +00:00
# "-d:release" implies "--stacktrace:off" and it cannot be added to config.nims
i f e q ( $( USE_LIBBACKTRACE ) , 0 )
NIM_PARAMS := $( NIM_PARAMS) -d:debug -d:disable_libbacktrace
e l s e
NIM_PARAMS := $( NIM_PARAMS) -d:release
e n d i f
2022-11-07 08:14:21 +00:00
libbacktrace :
+ $( MAKE) -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB = 0
2022-10-18 23:03:43 +00:00
2022-11-30 20:02:39 +00:00
clean-libbacktrace :
+ $( MAKE) -C vendor/nim-libbacktrace clean $( HANDLE_OUTPUT)
2022-03-30 15:17:21 +00:00
2022-11-30 20:02:39 +00:00
# Extend deps and clean targets
2020-04-30 15:51:30 +00:00
i f n e q ( $( USE_LIBBACKTRACE ) , 0 )
deps : | libbacktrace
e n d i f
2023-09-13 10:45:55 +00:00
i f e q ( $( POSTGRES ) , 1 )
NIM_PARAMS := $( NIM_PARAMS) -d:postgres -d:nimDebugDlOpen
e n d i f
2022-11-30 20:02:39 +00:00
clean : | clean -libbacktrace
2022-11-07 08:14:21 +00:00
2022-11-30 20:02:39 +00:00
##################
2023-09-11 06:32:31 +00:00
## RLN ##
2022-11-30 20:02:39 +00:00
##################
2024-06-20 09:35:21 +00:00
.PHONY : librln
2020-04-30 15:51:30 +00:00
2023-09-01 11:20:55 +00:00
LIBRLN_BUILDDIR := $( CURDIR) /vendor/zerokit
2024-06-20 09:35:21 +00:00
LIBRLN_VERSION := v0.5.1
2022-11-07 08:14:21 +00:00
2022-11-30 20:02:39 +00:00
i f e q ( $( OS ) , W i n d o w s _ N T )
2022-12-05 23:33:03 +00:00
LIBRLN_FILE := rln.lib
2022-11-30 20:02:39 +00:00
e l s e
2023-09-18 05:26:58 +00:00
LIBRLN_FILE := librln_$( LIBRLN_VERSION) .a
2022-11-30 20:02:39 +00:00
e n d i f
2022-11-07 08:14:21 +00:00
2023-08-29 18:52:22 +00:00
$(LIBRLN_FILE) :
2022-11-30 20:02:39 +00:00
echo -e $( BUILD_MSG) " $@ " && \
2023-09-18 05:26:58 +00:00
./scripts/build_rln.sh $( LIBRLN_BUILDDIR) $( LIBRLN_VERSION) $( LIBRLN_FILE)
2022-11-07 08:14:21 +00:00
2024-06-20 09:35:21 +00:00
librln : | $( LIBRLN_FILE )
2024-05-22 01:00:22 +00:00
$( eval NIM_PARAMS += --passL:$( LIBRLN_FILE) --passL:-lm)
2020-04-30 15:51:30 +00:00
2022-11-30 20:02:39 +00:00
clean-librln :
cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml
2023-08-29 18:52:22 +00:00
rm -f $( LIBRLN_FILE)
2022-11-07 08:14:21 +00:00
2022-11-30 20:02:39 +00:00
# Extend clean target
clean : | clean -librln
2020-04-30 15:51:30 +00:00
2020-10-03 05:26:49 +00:00
2023-03-31 13:24:04 +00:00
#################
## Waku Common ##
#################
.PHONY : testcommon
testcommon : | build deps
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) nim testcommon $( NIM_PARAMS) waku.nims
2023-08-09 17:11:50 +00:00
##########
## Waku ##
##########
.PHONY : testwaku wakunode 2 testwakunode 2 example 2 chat 2 chat 2bridge
2020-08-26 12:20:04 +00:00
2024-02-22 11:29:13 +00:00
# install anvil only for the testwaku target
testwaku : | build deps anvil librln
2020-12-21 11:32:02 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
2023-09-11 06:32:31 +00:00
$( ENV_SCRIPT) nim test -d:os= $( shell uname) $( NIM_PARAMS) waku.nims
2020-12-21 11:32:02 +00:00
2022-11-30 20:02:39 +00:00
wakunode2 : | build deps librln
2020-04-30 15:51:30 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
2023-09-11 06:32:31 +00:00
$( ENV_SCRIPT) nim wakunode2 $( NIM_PARAMS) waku.nims
2020-04-30 15:51:30 +00:00
2024-02-09 16:06:25 +00:00
benchmarks : | build deps librln
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) nim benchmarks $( NIM_PARAMS) waku.nims
2023-04-25 13:34:57 +00:00
testwakunode2 : | build deps librln
echo -e $( BUILD_MSG) " build/ $@ " && \
2023-09-11 06:32:31 +00:00
$( ENV_SCRIPT) nim testwakunode2 $( NIM_PARAMS) waku.nims
2023-04-25 13:34:57 +00:00
2023-09-11 06:32:31 +00:00
example2 : | build deps librln
2022-11-07 08:14:21 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) nim example2 $( NIM_PARAMS) waku.nims
2022-11-30 20:02:39 +00:00
chat2 : | build deps librln
2022-11-07 08:14:21 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
2023-09-11 06:32:31 +00:00
$( ENV_SCRIPT) nim chat2 $( NIM_PARAMS) waku.nims
2022-11-07 08:14:21 +00:00
2023-09-11 06:32:31 +00:00
rln-db-inspector : | build deps librln
2023-09-07 12:45:25 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
2023-09-11 06:32:31 +00:00
$( ENV_SCRIPT) nim rln_db_inspector $( NIM_PARAMS) waku.nims
2023-09-07 12:45:25 +00:00
2023-09-11 06:32:31 +00:00
chat2bridge : | build deps librln
2022-11-07 08:14:21 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) nim chat2bridge $( NIM_PARAMS) waku.nims
2024-05-21 21:03:33 +00:00
liteprotocoltester : | build deps librln
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) nim liteprotocoltester $( NIM_PARAMS) waku.nims
2022-11-30 20:02:39 +00:00
2023-08-09 17:11:50 +00:00
################
## Waku tools ##
################
2023-04-12 08:22:45 +00:00
.PHONY : tools wakucanary networkmonitor
tools : networkmonitor wakucanary
2020-04-30 15:51:30 +00:00
2023-09-11 06:32:31 +00:00
wakucanary : | build deps librln
2022-10-11 03:58:44 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) nim wakucanary $( NIM_PARAMS) waku.nims
2023-09-11 06:32:31 +00:00
networkmonitor : | build deps librln
2022-11-10 09:29:34 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) nim networkmonitor $( NIM_PARAMS) waku.nims
2021-02-04 19:30:00 +00:00
2022-11-07 08:14:21 +00:00
2022-11-30 20:02:39 +00:00
###################
## Documentation ##
###################
2024-01-30 11:55:26 +00:00
.PHONY : docs coverage
2020-10-08 09:10:45 +00:00
2022-11-30 20:02:39 +00:00
# TODO: Remove unused target
docs : | build deps
echo -e $( BUILD_MSG) " build/ $@ " && \
2022-12-12 11:22:46 +00:00
$( ENV_SCRIPT) nim doc --run --index:on --project --out:.gh-pages waku/waku.nim waku.nims
2020-04-30 15:51:30 +00:00
2024-01-30 11:55:26 +00:00
coverage :
echo -e $( BUILD_MSG) " build/ $@ " && \
$( ENV_SCRIPT) ./scripts/run_cov.sh -y
2022-11-30 20:02:39 +00:00
#####################
## Container image ##
#####################
# -d:insecure - Necessary to enable Prometheus HTTP endpoint for metrics
# -d:chronicles_colors:none - Necessary to disable colors in logs for Docker
2023-09-13 10:45:55 +00:00
DOCKER_IMAGE_NIMFLAGS ?= -d:chronicles_colors:none -d:insecure -d:postgres
2023-04-25 15:54:28 +00:00
DOCKER_IMAGE_NIMFLAGS := $( DOCKER_IMAGE_NIMFLAGS) $( HEAPTRACK_PARAMS)
2020-04-30 15:51:30 +00:00
2020-05-26 12:04:40 +00:00
# build a docker image for the fleet
2022-11-30 20:02:39 +00:00
docker-image : MAKE_TARGET ?= wakunode 2
2023-03-17 14:04:26 +00:00
docker-image : DOCKER_IMAGE_TAG ?= $( MAKE_TARGET ) -$( GIT_VERSION )
2023-09-26 10:09:20 +00:00
docker-image : DOCKER_IMAGE_NAME ?= wakuorg /nwaku :$( DOCKER_IMAGE_TAG )
2020-05-26 12:04:40 +00:00
docker-image :
docker build \
2020-09-09 18:14:07 +00:00
--build-arg= " MAKE_TARGET= $( MAKE_TARGET) " \
2022-05-17 19:11:07 +00:00
--build-arg= " NIMFLAGS= $( DOCKER_IMAGE_NIMFLAGS) " \
2023-04-25 15:54:28 +00:00
--build-arg= " NIM_COMMIT= $( DOCKER_NIM_COMMIT) " \
2023-05-23 08:44:57 +00:00
--build-arg= " LOG_LEVEL= $( LOG_LEVEL) " \
2024-02-27 13:13:52 +00:00
--label= " commit= $( shell git rev-parse HEAD) " \
--label= " version= $( GIT_VERSION) " \
2023-04-25 15:54:28 +00:00
--target $( TARGET) \
2020-05-26 12:04:40 +00:00
--tag $( DOCKER_IMAGE_NAME) .
docker-push :
docker push $( DOCKER_IMAGE_NAME)
2022-11-07 08:14:21 +00:00
2023-05-12 16:08:41 +00:00
################
## C Bindings ##
################
2023-05-19 06:20:12 +00:00
.PHONY : cbindings cwaku_example libwaku
2023-05-12 16:08:41 +00:00
2023-05-19 06:20:12 +00:00
STATIC ?= false
2021-06-13 12:50:10 +00:00
2023-09-19 15:01:32 +00:00
libwaku : | build deps librln
2023-05-19 06:20:12 +00:00
rm -f build/libwaku*
i f e q ( $( STATIC ) , t r u e )
echo -e $( BUILD_MSG) " build/ $@ .a " && \
2023-09-11 06:32:31 +00:00
$( ENV_SCRIPT) nim libwakuStatic $( NIM_PARAMS) waku.nims
2023-05-19 06:20:12 +00:00
e l s e
echo -e $( BUILD_MSG) " build/ $@ .so " && \
2023-09-11 06:32:31 +00:00
$( ENV_SCRIPT) nim libwakuDynamic $( NIM_PARAMS) waku.nims
2023-05-19 06:20:12 +00:00
e n d i f
2022-11-30 20:02:39 +00:00
2024-05-22 01:00:22 +00:00
#####################
## Mobile Bindings ##
#####################
.PHONY : libwaku -android \
libwaku-android-precheck \
libwaku-android-arm64 \
libwaku-android-amd64 \
libwaku-android-x86 \
libwaku-android-arm \
rebuild-nat-libs \
build-libwaku-for-android-arch
ANDROID_TARGET ?= 30
i f e q ( $( detected_OS ) , D a r w i n )
ANDROID_TOOLCHAIN_DIR := $( ANDROID_NDK_HOME) /toolchains/llvm/prebuilt/darwin-x86_64
e l s e
ANDROID_TOOLCHAIN_DIR := $( ANDROID_NDK_HOME) /toolchains/llvm/prebuilt/linux-x86_64
e n d i f
rebuild-nat-libs : | clean -cross nat -libs
2024-06-20 09:35:21 +00:00
libwaku-android-precheck :
2024-05-22 01:00:22 +00:00
i f n d e f A N D R O I D _ N D K _ H O M E
$( error ANDROID_NDK_HOME is not set )
e n d i f
build-libwaku-for-android-arch :
$( MAKE) rebuild-nat-libs CC = $( ANDROID_TOOLCHAIN_DIR) /bin/$( ANDROID_COMPILER) && \
./scripts/build_rln_android.sh $( CURDIR) /build $( LIBRLN_BUILDDIR) $( LIBRLN_VERSION) $( CROSS_TARGET) $( ABIDIR) && \
CPU = $( CPU) ABIDIR = $( ABIDIR) ANDROID_ARCH = $( ANDROID_ARCH) ANDROID_COMPILER = $( ANDROID_COMPILER) ANDROID_TOOLCHAIN_DIR = $( ANDROID_TOOLCHAIN_DIR) $( ENV_SCRIPT) nim libWakuAndroid $( NIM_PARAMS) waku.nims
libwaku-android-arm64 : ANDROID_ARCH =aarch 64-linux -android
libwaku-android-arm64 : CPU =arm 64
libwaku-android-arm64 : ABIDIR =arm 64-v 8a
libwaku-android-arm64 : | libwaku -android -precheck build deps
$( MAKE) build-libwaku-for-android-arch ANDROID_ARCH = $( ANDROID_ARCH) CROSS_TARGET = $( ANDROID_ARCH) CPU = $( CPU) ABIDIR = $( ABIDIR) ANDROID_COMPILER = $( ANDROID_ARCH) $( ANDROID_TARGET) -clang
libwaku-android-amd64 : ANDROID_ARCH =x 86_ 64-linux -android
libwaku-android-amd64 : CPU =amd 64
libwaku-android-amd64 : ABIDIR =x 86_ 64
libwaku-android-amd64 : | libwaku -android -precheck build deps
$( MAKE) build-libwaku-for-android-arch ANDROID_ARCH = $( ANDROID_ARCH) CROSS_TARGET = $( ANDROID_ARCH) CPU = $( CPU) ABIDIR = $( ABIDIR) ANDROID_COMPILER = $( ANDROID_ARCH) $( ANDROID_TARGET) -clang
libwaku-android-x86 : ANDROID_ARCH =i 686-linux -android
libwaku-android-x86 : CPU =i 386
libwaku-android-x86 : ABIDIR =x 86
libwaku-android-x86 : | libwaku -android -precheck build deps
$( MAKE) build-libwaku-for-android-arch ANDROID_ARCH = $( ANDROID_ARCH) CROSS_TARGET = $( ANDROID_ARCH) CPU = $( CPU) ABIDIR = $( ABIDIR) ANDROID_COMPILER = $( ANDROID_ARCH) $( ANDROID_TARGET) -clang
libwaku-android-arm : ANDROID_ARCH =armv 7a -linux -androideabi
libwaku-android-arm : CPU =arm
libwaku-android-arm : ABIDIR =armeabi -v 7a
libwaku-android-arm : | libwaku -android -precheck build deps
# cross-rs target architecture name does not match the one used in android
$( MAKE) build-libwaku-for-android-arch ANDROID_ARCH = $( ANDROID_ARCH) CROSS_TARGET = armv7-linux-androideabi CPU = $( CPU) ABIDIR = $( ABIDIR) ANDROID_COMPILER = $( ANDROID_ARCH) $( ANDROID_TARGET) -clang
libwaku-android :
$( MAKE) libwaku-android-amd64
$( MAKE) libwaku-android-arm64
$( MAKE) libwaku-android-x86
# This target is disabled because on recent versions of cross-rs complain with the following error
# relocation R_ARM_THM_ALU_PREL_11_0 cannot be used against symbol 'stack_init_trampoline_return'; recompile with -fPIC
# It's likely this architecture is not used so we might just not support it.
# $(MAKE) libwaku-android-arm
2023-05-19 06:20:12 +00:00
cwaku_example : | build libwaku
2023-05-12 16:08:41 +00:00
echo -e $( BUILD_MSG) " build/ $@ " && \
cc -o " build/ $@ " \
./examples/cbindings/waku_example.c \
2023-07-07 08:53:00 +00:00
./examples/cbindings/base64.c \
2023-05-19 06:20:12 +00:00
-lwaku -Lbuild/ \
-pthread -ldl -lm \
2023-05-12 16:08:41 +00:00
-lminiupnpc -Lvendor/nim-nat-traversal/vendor/miniupnp/miniupnpc/build/ \
-lnatpmp -Lvendor/nim-nat-traversal/vendor/libnatpmp-upstream/ \
vendor/nim-libbacktrace/libbacktrace_wrapper.o \
vendor/nim-libbacktrace/install/usr/lib/libbacktrace.a
2022-11-30 20:02:39 +00:00
2023-09-28 09:10:42 +00:00
cppwaku_example : | build libwaku
echo -e $( BUILD_MSG) " build/ $@ " && \
g++ -o " build/ $@ " \
./examples/cpp/waku.cpp \
./examples/cpp/base64.cpp \
-lwaku -Lbuild/ \
-pthread -ldl -lm \
-lminiupnpc -Lvendor/nim-nat-traversal/vendor/miniupnp/miniupnpc/build/ \
-lnatpmp -Lvendor/nim-nat-traversal/vendor/libnatpmp-upstream/ \
vendor/nim-libbacktrace/libbacktrace_wrapper.o \
vendor/nim-libbacktrace/install/usr/lib/libbacktrace.a
2023-08-02 08:45:15 +00:00
nodejswaku : | build deps
echo -e $( BUILD_MSG) " build/ $@ " && \
node-gyp build --directory= examples/nodejs/
2022-11-30 20:02:39 +00:00
e n d i f # "variables.mk" was not included
2023-05-18 12:45:45 +00:00
###################
# Release Targets #
###################
release-notes :
docker run \
-it \
--rm \
-v $$ { PWD} :/opt/sv4git/repo:z \
-u $( shell id -u) \
docker.io/wakuorg/sv4git:latest \
release-notes | \
sed -E 's@#([0-9]+)@[#\1](https://github.com/waku-org/nwaku/issues/\1)@g'
# I could not get the tool to replace issue ids with links, so using sed for now,
# asked here: https://github.com/bvieira/sv4git/discussions/101