11.PHONY : statusgo all test clean help
22.PHONY : statusgo-ios-library statusgo-android-library
33.PHONY : build-libwaku test-libwaku clean-libwaku rebuild-libwaku
4+ .PHONY : build-libsds clean-libsds rebuild-libsds
45
56# Clear any GOROOT set outside of the Nix shell
67export GOROOT =
@@ -75,14 +76,14 @@ endif
7576
7677ifeq ($(detected_OS ) ,Darwin)
7778 GOBIN_SHARED_LIB_EXT := dylib
78- LIBWAKU_EXT := so
79+ LIB_EXT := dylib
7980 GOBIN_SHARED_LIB_CFLAGS := CGO_ENABLED=1 GOOS=darwin
8081else ifeq ($(detected_OS),Windows)
8182 GOBIN_SHARED_LIB_EXT := dll
82- LIBWAKU_EXT := dll
83+ LIB_EXT := dll
8384else ifeq ($(detected_OS),Linux)
8485 GOBIN_SHARED_LIB_EXT := so
85- LIBWAKU_EXT := so
86+ LIB_EXT := so
8687 CGO_LDFLAGS += "-Wl,-soname,libstatus.so.0"
8788endif
8889
@@ -95,15 +96,46 @@ GIT_AUTHOR ?= $(shell git config user.email || echo $$USER)
9596
9697BUILD_TAGS ?= gowaku_no_rln
9798
99+ # `nwaku` variables
100+
98101ifeq ($(USE_NWAKU ) , true)
99102 BUILD_TAGS += use_nwaku
100103 NWAKU_VERSION ?= v0.37.0-rc.3
101104 NWAKU_SOURCE_DIR ?= $(GIT_ROOT ) /../nwaku
102- LIBWAKU := $(NWAKU_SOURCE_DIR ) /build/libwaku.$(LIBWAKU_EXT )
105+ LIBWAKU := $(NWAKU_SOURCE_DIR ) /build/libwaku.$(LIB_EXT )
103106 CGO_CFLAGS+ =-I$(NWAKU_SOURCE_DIR ) /library
104107 CGO_LDFLAGS+=-L$(NWAKU_SOURCE_DIR)/build -lwaku -Wl,-rpath,$(NWAKU_SOURCE_DIR)/build
105108endif
106109
110+
111+ # `nim-sds` variables
112+
113+ # Option 1: Provide NIM_SDS_SOURCE_DIR
114+ NIM_SDS_SOURCE_DIR ?= $(GIT_ROOT ) /../nim-sds
115+
116+ # Option 2: Provide NIM_SDS_LIB_DIR and NIM_SDS_INC_DIR
117+
118+ # Determine which approach to use
119+ ifdef NIM_SDS_LIB_DIR
120+ ifdef NIM_SDS_INC_DIR
121+ # External lib/include approach (e.g. used in Nix)
122+ NIM_SDS_BUILD_FROM_SOURCE := false
123+ else
124+ $(error NIM_SDS_INC_DIR must be provided when NIM_SDS_LIB_DIR is set)
125+ endif
126+ else
127+ # Source directory approach
128+ NIM_SDS_LIB_DIR := $(NIM_SDS_SOURCE_DIR ) /build
129+ NIM_SDS_INC_DIR := $(NIM_SDS_SOURCE_DIR ) /library
130+ NIM_SDS_BUILD_FROM_SOURCE := true
131+ endif
132+
133+ LIBSDS := $(NIM_SDS_LIB_DIR ) /libsds.$(LIB_EXT )
134+ CGO_CFLAGS+ =-I$(NIM_SDS_INC_DIR )
135+ CGO_LDFLAGS+ =-L$(NIM_SDS_LIB_DIR ) -lsds
136+
137+ # Common flags
138+
107139BUILD_FLAGS ?= -ldflags=""
108140BUILD_FLAGS_MOBILE ?=
109141
@@ -154,7 +186,6 @@ nix-gc-protected:
154186 @echo -e " $( YELLOW) The following paths are protected:$( RESET) " && \
155187 ls -1 $(_NIX_GCROOTS ) | sed ' s/^/ - /'
156188
157-
158189nix-upgrade : SHELL := /bin/sh
159190nix-upgrade : # #@nix Upgrade Nix interpreter to current version.
160191 nix/scripts/upgrade.sh
@@ -175,7 +206,7 @@ nix-purge: ##@nix Completely remove Nix setup, including /nix directory
175206all : $(GO_CMD_NAMES )
176207
177208.PHONY : $(GO_CMD_NAMES ) $(GO_CMD_PATHS ) $(GO_CMD_BUILDS )
178- $(GO_CMD_BUILDS ) : generate $(LIBWAKU )
209+ $(GO_CMD_BUILDS ) : generate $(LIBWAKU ) $( LIBSDS )
179210$(GO_CMD_BUILDS ) : # #@build Build any Go project from cmd folder
180211 CGO_LDFLAGS=" $( CGO_LDFLAGS) " CGO_CFLAGS=" $( CGO_CFLAGS) " \
181212 go build -v \
@@ -184,6 +215,13 @@ $(GO_CMD_BUILDS): ##@build Build any Go project from cmd folder
184215 @echo " Compilation done."
185216 @echo " Run \" build/bin/$( notdir $@ ) -h\" to view available commands."
186217
218+ # Flag needed by nim-based dependencies (e.g., nwaku and nim-sds) that also use nimbus-build-system.
219+ # When USE_SYSTEM_NIM=1 skips compiling Nim compiler locally and instead,
220+ # enforces to use system-installed Nim.
221+ # This is not needed if nim dependencies use nimble.
222+ USE_SYSTEM_NIM ?= 0
223+
224+ # Libwaku targets
187225
188226$(NWAKU_SOURCE_DIR ) : # #@build Clone nwaku
189227ifeq ($(USE_NWAKU ) ,true)
@@ -196,7 +234,7 @@ clone-nwaku: $(NWAKU_SOURCE_DIR)
196234$(LIBWAKU ) : clone-nwaku
197235ifeq ($(USE_NWAKU ) ,true)
198236 @echo "Building libwaku" $(LIBWAKU)
199- $(MAKE) -C $(NWAKU_SOURCE_DIR) libwaku SHELL=/bin/bash
237+ $(MAKE) -C $(NWAKU_SOURCE_DIR) libwaku USE_SYSTEM_NIM=$(USE_SYSTEM_NIM) SHELL=/bin/bash
200238endif
201239
202240build-libwaku : $(LIBWAKU )
@@ -210,6 +248,39 @@ clean-libwaku:
210248
211249rebuild-libwaku : | clean-libwaku $(LIBWAKU )
212250
251+ # libsds targets
252+
253+ $(NIM_SDS_SOURCE_DIR ) : # #@build Clone nim-sds
254+ ifeq ($(NIM_SDS_BUILD_FROM_SOURCE ) ,true)
255+ @echo "Cloning nim-sds ..."
256+ git clone --branch v0.1.0 https://github.com/waku-org/nim-sds.git $(NIM_SDS_SOURCE_DIR)
257+ endif
258+
259+ clone-nim-sds : $(NIM_SDS_SOURCE_DIR )
260+
261+ $(LIBSDS ) : clone-nim-sds
262+ ifeq ($(NIM_SDS_BUILD_FROM_SOURCE ) ,true)
263+ @echo "Building nim-sds: $(LIBSDS)"
264+ $(MAKE) -C $(NIM_SDS_SOURCE_DIR) update
265+ $(MAKE) -C $(NIM_SDS_SOURCE_DIR) libsds USE_SYSTEM_NIM=$(USE_SYSTEM_NIM) SHELL=/bin/bash
266+ else
267+ @test -f $(LIBSDS) || (echo "Error: libsds not found at $(LIBSDS)" && exit 1)
268+ endif
269+
270+ build-libsds : $(LIBSDS )
271+
272+ # build-libsds-android: clone-nim-sds
273+ # @echo "Building nim-sds for Android" $(LIBSDS)
274+ # $(MAKE) -C $(NIM_SDS_SOURCE_DIR) libsds-android USE_SYSTEM_NIM=$(USE_SYSTEM_NIM) SHELL=/bin/bash
275+
276+ clean-libsds :
277+ @echo " Removing libsds"
278+ rm $(LIBSDS )
279+
280+ rebuild-libsds : | clean-libsds $(LIBSDS )
281+
282+ # Status-go targets
283+
213284statusgo : # #@build Build status-go as status-backend server
214285statusgo : build/bin/status-backend
215286
@@ -227,34 +298,33 @@ push-notification-server: build/bin/push-notification-server
227298cmd : # #@build Build all public apps in ./cmd
228299cmd : status-backend push-notification-server
229300
230-
231301status-go-deps :
232302 go clean -cache || true
233303 go clean -modcache || true
234304 go install google.golang.org/protobuf/cmd/
[email protected] 235305
236-
237-
306+ statusgo-c-bindings : STATUS_GO_BINDINGS_PATH ?= build/bin/statusgo-lib
238307statusgo-c-bindings :
239- # # cmd/library/README.md explains the magic incantation behind this
240- mkdir -p build/bin/statusgo-lib
241- go run -mod=mod cmd/library/* .go > build/bin/statusgo-lib /main.go
308+ @ # # cmd/library/README.md explains the magic incantation behind this
309+ mkdir -p $( STATUS_GO_BINDINGS_PATH )
310+ go run -mod=mod cmd/library/* .go > $( STATUS_GO_BINDINGS_PATH ) /main.go
242311
312+ statusgo-library : STATUS_GO_BINDINGS_PATH ?= build/bin/statusgo-lib
313+ statusgo-library : STATUS_GO_LIBRARY_OUT ?= build/bin
243314statusgo-library : generate
244- statusgo-library : statusgo-c-bindings $(LIBWAKU ) # #@cross-compile Build status-go as static library for current platform
315+ statusgo-library : statusgo-c-bindings $(LIBWAKU ) $( LIBSDS ) # #@cross-compile Build status-go as static library for current platform
245316 @echo " Building static library..."
246317 CGO_LDFLAGS=" $( CGO_LDFLAGS) " CGO_CFLAGS=" $( CGO_CFLAGS) " \
247318 go build \
248319 -tags ' $(BUILD_TAGS)' \
249320 $(BUILD_FLAGS ) \
250321 -buildmode=c-archive \
251- -o build/bin/libstatus.a \
252- ./build/bin/statusgo-lib
253- @echo " Static library built:"
254- @ls -la build/bin/libstatus.*
322+ -o $(STATUS_GO_LIBRARY_OUT ) /libstatus.a \
323+ " $( STATUS_GO_BINDINGS_PATH) /main.go"
324+ @echo " Static library built: $( STATUS_GO_LIBRARY_OUT) /libstatus.a"
255325
256326statusgo-shared-library : generate
257- statusgo-shared-library : statusgo-c-bindings $(LIBWAKU ) # #@cross-compile Build status-go as shared library for current platform
327+ statusgo-shared-library : statusgo-c-bindings $(LIBWAKU ) $( LIBSDS ) # #@cross-compile Build status-go as shared library for current platform
258328 @echo " Building shared library..."
259329 @echo " Tags: $( BUILD_TAGS) "
260330 CGO_LDFLAGS=" $( CGO_LDFLAGS) " CGO_CFLAGS=" $( CGO_CFLAGS) " \
@@ -340,7 +410,7 @@ clean-release:
340410 rm -rf $(RELEASE_DIR )
341411
342412lint-fix :
343- golangci-lint --build-tags ' $(BUILD_TAGS)' run --fix ./...
413+ golangci-lint --build-tags ' $(BUILD_TAGS) lint ' run --fix ./...
344414
345415docker-test : # #@tests Run tests in a docker container with golang.
346416 docker run --privileged --rm -it -v " $( PWD) :$( DOCKER_TEST_WORKDIR) " -w " $( DOCKER_TEST_WORKDIR) " $(DOCKER_TEST_IMAGE ) go test ${ARGS}
@@ -363,6 +433,7 @@ test-unit: export UNIT_TEST_PACKAGES ?= $(call sh, go list ./... | \
363433 grep -v /transactions/fake | \
364434 grep -v /tests-unit-network)
365435test-unit : # #@tests Run unit and integration tests
436+ LD_LIBRARY_PATH=" $( NIM_SDS_LIB_DIR) " CGO_LDFLAGS=" $( CGO_LDFLAGS) " CGO_CFLAGS=" $( CGO_CFLAGS) " \
366437 ./_assets/scripts/run_unit_tests.sh
367438
368439test-unit-network : test-unit-prep
@@ -384,12 +455,13 @@ benchmark: export FUNCTIONAL_TESTS_DOCKER_UID ?= $(call sh, id -u)
384455benchmark :
385456 @./_assets/scripts/run_benchmark.sh
386457
387- lint-panics : export GOFLAGS ?= -tags='$(BUILD_TAGS ) '
388458lint-panics : generate
459+ GOFLAGS=-tags=' $(BUILD_TAGS),lint' \
389460 go tool goroutine-defer-guard -skip=./cmd -test=false ./...
390461
391462lint : generate lint-panics
392- golangci-lint --build-tags ' $(BUILD_TAGS)' run ./...
463+ lint :
464+ golangci-lint --build-tags ' $(BUILD_TAGS) lint' run ./...
393465
394466clean : # #@other Cleanup
395467 rm -fr build/bin/*
0 commit comments