Skip to content

Commit 3100db5

Browse files
Ivansete-statusigor-sirotin
authored andcommitted
feat: add nim-sds to build
1 parent 8100997 commit 3100db5

File tree

11 files changed

+183
-46
lines changed

11 files changed

+183
-46
lines changed

.github/workflows/pr.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ jobs:
2424
id: cache-go-deps
2525
with:
2626
path: ~/go/bin
27-
key: go-deps-${{ runner.os }}-v4.0.2-protoc-gen-go-v1.34.1-gopls-latest
27+
key: go-deps-${{ runner.os }}-v4.0.2-protoc-gen-go-v1.34.1
2828
restore-keys: |
2929
go-deps-${{ runner.os }}-
3030
3131
- name: Install Go dependencies
3232
if: steps.cache-go-deps.outputs.cache-hit != 'true'
3333
run: |
3434
go install google.golang.org/protobuf/cmd/[email protected]
35-
go install golang.org/x/tools/gopls@latest
36-
which gopls
3735
3836
- name: Setup Protocol Buffer Compiler
3937
uses: arduino/setup-protoc@v3
@@ -58,7 +56,7 @@ jobs:
5856
uses: golangci/golangci-lint-action@v8
5957
with:
6058
version: v2.3.1
61-
args: --build-tags=gowaku_no_rln
59+
args: --build-tags=gowaku_no_rln,lint
6260

6361
- name: lint-panics
6462
run: |

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ COPY --from=builder /go/src/github.com/status-im/status-go/build/bin/push-notifi
5252
COPY --from=builder /go/src/github.com/status-im/status-go/tests-functional/scripts/scan_waku_fleet.py /usr/local/bin
5353
COPY --from=builder /go/src/github.com/status-im/status-go/static/keys/* /static/keys/
5454
COPY --from=builder /go/src/github.com/status-im/status-go/tests-functional/waku_configs/* /static/configs/
55+
COPY --from=builder /go/src/github.com/status-im/nim-sds/build/libsds.so /usr/local/lib/
56+
57+
ENV LD_LIBRARY_PATH=/usr/local/lib/
5558

5659
COPY _assets/scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
5760
RUN chmod +x /usr/local/bin/entrypoint.sh

Makefile

Lines changed: 94 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
67
export GOROOT=
@@ -75,14 +76,14 @@ endif
7576

7677
ifeq ($(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
8081
else ifeq ($(detected_OS),Windows)
8182
GOBIN_SHARED_LIB_EXT := dll
82-
LIBWAKU_EXT := dll
83+
LIB_EXT := dll
8384
else 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"
8788
endif
8889

@@ -95,15 +96,46 @@ GIT_AUTHOR ?= $(shell git config user.email || echo $$USER)
9596

9697
BUILD_TAGS ?= gowaku_no_rln
9798

99+
# `nwaku` variables
100+
98101
ifeq ($(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
105108
endif
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+
107139
BUILD_FLAGS ?= -ldflags=""
108140
BUILD_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-
158189
nix-upgrade: SHELL := /bin/sh
159190
nix-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
175206
all: $(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
189227
ifeq ($(USE_NWAKU),true)
@@ -196,7 +234,7 @@ clone-nwaku: $(NWAKU_SOURCE_DIR)
196234
$(LIBWAKU): clone-nwaku
197235
ifeq ($(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
200238
endif
201239

202240
build-libwaku: $(LIBWAKU)
@@ -210,6 +248,39 @@ clean-libwaku:
210248

211249
rebuild-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+
213284
statusgo: ##@build Build status-go as status-backend server
214285
statusgo: build/bin/status-backend
215286

@@ -227,34 +298,33 @@ push-notification-server: build/bin/push-notification-server
227298
cmd: ##@build Build all public apps in ./cmd
228299
cmd: status-backend push-notification-server
229300

230-
231301
status-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
238307
statusgo-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
243314
statusgo-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

256326
statusgo-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

342412
lint-fix:
343-
golangci-lint --build-tags '$(BUILD_TAGS)' run --fix ./...
413+
golangci-lint --build-tags '$(BUILD_TAGS) lint' run --fix ./...
344414

345415
docker-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)
365435
test-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

368439
test-unit-network: test-unit-prep
@@ -384,12 +455,13 @@ benchmark: export FUNCTIONAL_TESTS_DOCKER_UID ?= $(call sh, id -u)
384455
benchmark:
385456
@./_assets/scripts/run_benchmark.sh
386457

387-
lint-panics: export GOFLAGS ?= -tags='$(BUILD_TAGS)'
388458
lint-panics: generate
459+
GOFLAGS=-tags='$(BUILD_TAGS),lint' \
389460
go tool goroutine-defer-guard -skip=./cmd -test=false ./...
390461

391462
lint: generate lint-panics
392-
golangci-lint --build-tags '$(BUILD_TAGS)' run ./...
463+
lint:
464+
golangci-lint --build-tags '$(BUILD_TAGS) lint' run ./...
393465

394466
clean: ##@other Cleanup
395467
rm -fr build/bin/*

_assets/scripts/run_functional_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ pytest --reruns 2 -m rpc -c "${root_path}/pytest.ini" -n 12 \
7676
--docker-image=${image_name} \
7777
--codecov_dir="${binary_coverage_reports_path}" \
7878
--logs-dir="${logs_path}" \
79-
--junitxml="${test_results_path}/report.xml"
79+
--junitxml="${test_results_path}/report.xml" \
80+
${root_path}
8081
exit_code=$?
8182

8283
# Stop containers

flake.lock

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
nixpkgs.url = "github:NixOS/nixpkgs/0ef228213045d2cdb5a169a95d63ded38670b293";
1919
# We cannot do follows since the nim-unwrapped-2_0 doesn't exist in this nixpkgs version above
2020
nwaku.url = "git+https://github.com/waku-org/nwaku?submodules=1&rev=e755fd834f5f3d6fba216b09469316f0328b3b6f";
21+
nim-sds.url = "git+https://github.com/waku-org/nim-sds?submodules=1&rev=b6431260110fe62956ff4d7bab6767556c19d040";
2122
};
2223

23-
outputs = { self, nixpkgs, nwaku }:
24+
outputs = { self, nixpkgs, nwaku, nim-sds }:
2425
let
2526
stableSystems = [
2627
"x86_64-linux" "aarch64-linux"
@@ -38,7 +39,21 @@
3839
};
3940
overlays = [
4041
pkgsOverlay
41-
(final: prev: { nwaku = nwaku.packages.${system}; })
42+
(final: prev: let
43+
libSds = nim-sds.packages.${system}.libsds;
44+
in {
45+
# Make nwaku available
46+
nwaku = nwaku.packages.${system};
47+
48+
# Wrap nim-sds package so its dependencies propagate
49+
lib-sds-pkg = libSds.overrideAttrs (old: {
50+
propagatedBuildInputs = with final; [
51+
openssl
52+
gmp
53+
nim-unwrapped-2_2
54+
];
55+
});
56+
})
4257
];
4358
}
4459
);

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ require (
103103
github.com/status-im/extkeys v1.4.0
104104
github.com/status-im/go-wallet-sdk v0.0.0-20251027141302-43edbd6abc92
105105
github.com/waku-org/go-waku v0.10.1-0.20251003225121-06c9af60f35b
106+
github.com/waku-org/sds-go-bindings v0.0.0-20251119184907-e78f76307965
106107
github.com/waku-org/waku-go-bindings v0.0.0-20251030105913-aa64c47d2bf3
107108
github.com/wk8/go-ordered-map/v2 v2.1.7
108109
go.uber.org/atomic v1.11.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,8 @@ github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230916171929-1dd9494ff065 h1:Sd7
25412541
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230916171929-1dd9494ff065/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4=
25422542
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230916171518-2a77c3734dd1 h1:4HSdWMFMufpRo3ECTX6BrvA+VzKhXZf7mS0rTa5cCWU=
25432543
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230916171518-2a77c3734dd1/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y=
2544+
github.com/waku-org/sds-go-bindings v0.0.0-20251119184907-e78f76307965 h1:1xx0AQeLfxSLxuGvu7em1LrNM5lVXTU6PiuaPfTkbpA=
2545+
github.com/waku-org/sds-go-bindings v0.0.0-20251119184907-e78f76307965/go.mod h1:rC5yaoM7ee8h/zEyCGfdnYTOEhyW3jpdck7maoiRQQE=
25442546
github.com/waku-org/waku-go-bindings v0.0.0-20251030105913-aa64c47d2bf3 h1:VimYvS377VZh/b/kipnv2rp0a2r8Dd7D+4ihVd3hipI=
25452547
github.com/waku-org/waku-go-bindings v0.0.0-20251030105913-aa64c47d2bf3/go.mod h1:v6ogkMCyQRUTazRyQR5LIouukY4/2bkjjHpnBKBxcAY=
25462548
github.com/wealdtech/go-ens/v3 v3.5.0 h1:Huc9GxBgiGweCOGTYomvsg07K2QggAqZpZ5SuiZdC8o=

0 commit comments

Comments
 (0)