Skip to content

Commit 5141a33

Browse files
feat: libstorage support in build system (#7332)
* feat: support libstorage in the build system * build: make sure linting includes logos-storage * build: tweaking native build of libstorage that avoids calling make update (allowing to build on RYZEN processors) * build: removes redundant scripts * build: removes printing libstorage version on nix env * test: more uniform naming (USE_LOGOS_STORAGE) * build: bumps vendor hash * test: include logosstorage tests in the coverage on the CI * build: remove passing lib paths to the generate target Co-authored-by: Jakub <jakub@status.im> * build: Update Dockerfile - remove indentation Co-authored-by: Jakub <jakub@status.im> * build: remove redundant check in Makefile Co-authored-by: Jakub <jakub@status.im> * build: remove noise from Makefile Co-authored-by: Jakub <jakub@status.im> * build: remove redundant IFs from Makefile * build: adds README to be used when printing logosstorage help messages * build: move some Makefile vars to be better visible in context --------- Co-authored-by: Jakub <jakub@status.im>
1 parent 384a179 commit 5141a33

34 files changed

Lines changed: 3480 additions & 44 deletions

.github/workflows/pr.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Setup Protocol Buffer Compiler
3737
uses: arduino/setup-protoc@v3
3838
with:
39-
version: "29.3"
39+
version: '29.3'
4040
repo-token: ${{ secrets.GITHUB_TOKEN }}
4141

4242
- name: Cache go-generate-fast
@@ -57,11 +57,11 @@ jobs:
5757
uses: golangci/golangci-lint-action@v8
5858
with:
5959
version: v2.3.1
60-
args: --build-tags=gowaku_no_rln,lint
60+
args: --build-tags=gowaku_no_rln,lint,use_logos_storage
6161

6262
- name: lint-panics
6363
run: |
64-
make lint-panics
64+
make lint-panics USE_LOGOS_STORAGE=true
6565
6666
- name: go mod tidy
6767
run: go mod tidy && git diff --exit-code

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,8 @@ go.work.sum
121121
# Token deployment cache files
122122
tests-functional/snt_addresses.json*
123123

124-
# Codex AI (chatGPT)
124+
# libstorage
125+
libs
126+
127+
# CODEX (ChatGPT plugin)
125128
.codex

.vscode/settings.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
2-
"go.testTags": "gowaku_skip_migrations,gowaku_no_rln",
2+
"go.testTags": "gowaku_skip_migrations,gowaku_no_rln,use_logos_storage",
33
"cSpell.words": ["unmarshalling"],
44
"gopls": {
55
"formatting.local": "github.com/status-im/status-go",
6-
"build.buildFlags": ["-tags=gowaku_skip_migrations,gowaku_no_rln"]
6+
"build.buildFlags": [
7+
"-tags=gowaku_skip_migrations,gowaku_no_rln,use_logos_storage"
8+
]
79
},
810
// format all files on save if a formatter is available
911
"editor.formatOnSave": true,
@@ -14,9 +16,13 @@
1416
"CGO_ENABLED": "1"
1517
},
1618
"go.testEnvVars": {
17-
"CGO_CFLAGS": "-I${workspaceFolder}/../nim-sds/library",
18-
"CGO_LDFLAGS": "-L${workspaceFolder}/../nim-sds/build -lsds -Wl,-rpath,${workspaceFolder}/../nim-sds/build"
19+
"CGO_CFLAGS": "-I${workspaceFolder}/../logos-storage-nim/library -I${workspaceFolder}/../nim-sds/library",
20+
"CGO_LDFLAGS": "-L${workspaceFolder}/../logos-storage-nim/build -lstorage -Wl,-rpath,${workspaceFolder}/../logos-storage-nim/build -L${workspaceFolder}/../nim-sds/build -lsds"
1921
},
20-
"go.buildFlags": ["-tags=gowaku_skip_migrations,gowaku_no_rln"],
21-
"go.testFlags": ["-tags=gowaku_skip_migrations,gowaku_no_rln"]
22+
"go.buildFlags": [
23+
"-tags=gowaku_skip_migrations,gowaku_no_rln,use_logos_storage"
24+
],
25+
"go.testFlags": [
26+
"-tags=gowaku_skip_migrations,gowaku_no_rln,use_logos_storage"
27+
]
2228
}

Dockerfile

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Build status-go in a Go builder container
2-
FROM golang:1.24.7-bookworm AS builder
2+
FROM golang:1.24.7-trixie AS builder
33

44
# Set environment variables to use Clang
55
ENV CC=clang
66
ENV CXX=clang++
77

88
RUN apt-get update \
9-
&& apt-get install -y git bash make llvm clang protobuf-compiler build-essential pkg-config curl xz-utils jq \
9+
&& apt-get install -y git bash make cmake llvm clang protobuf-compiler build-essential pkg-config curl xz-utils jq unzip \
1010
&& apt-get clean \
1111
&& rm -rf /var/lib/apt/lists/*
1212

@@ -15,16 +15,16 @@ ARG NIM_VERSION=2.2.4
1515
RUN set -eu && \
1616
DPKG_ARCH="$(dpkg --print-architecture)" && \
1717
case "$DPKG_ARCH" in \
18-
amd64) NIM_ARCH="x64" ;; \
19-
arm64) NIM_ARCH="arm64" ;; \
20-
*) echo "Unsupported architecture: $DPKG_ARCH" >&2; exit 1 ;; \
18+
amd64) NIM_ARCH="x64" ;; \
19+
arm64) NIM_ARCH="arm64" ;; \
20+
*) echo "Unsupported architecture: $DPKG_ARCH" >&2; exit 1 ;; \
2121
esac && \
2222
NIM_URL=$(curl -sSf https://nim-lang.org/releases.json \
23-
| jq -r --arg ver "$NIM_VERSION" --arg arch "$NIM_ARCH" \
24-
'.[$ver]["linux_" + $arch].github_url // empty') && \
23+
| jq -r --arg ver "$NIM_VERSION" --arg arch "$NIM_ARCH" \
24+
'.[$ver]["linux_" + $arch].github_url // empty') && \
2525
if [ -z "$NIM_URL" ]; then \
26-
echo "ERROR: No download URL found for Nim $NIM_VERSION linux_$NIM_ARCH" >&2; \
27-
exit 1; \
26+
echo "ERROR: No download URL found for Nim $NIM_VERSION linux_$NIM_ARCH" >&2; \
27+
exit 1; \
2828
fi && \
2929
curl -sSfL "$NIM_URL" -o /tmp/nim.tar.xz && \
3030
mkdir -p /opt/nim && \
@@ -37,6 +37,7 @@ ENV PATH="/opt/nim/bin:${PATH}"
3737
ARG build_tags='gowaku_no_rln'
3838
ARG build_flags=''
3939
ARG build_target='cmd'
40+
ARG use_logos_storage='false'
4041

4142
RUN mkdir -p /go/src/github.com/status-im/status-go
4243
WORKDIR /go/src/github.com/status-im/status-go
@@ -50,20 +51,27 @@ ARG cache_id='local'
5051
ARG enable_go_cache=true
5152

5253
RUN if [ "$enable_go_cache" = "true" ]; then \
53-
go env -w GOCACHE=/root/.cache/go-build; \
54+
go env -w GOCACHE=/root/.cache/go-build; \
5455
fi
5556
RUN --mount=type=cache,target="/root/.cache/go-build",id=statusgo-build-$cache_id \
56-
make $build_target BUILD_TAGS="$build_tags" BUILD_FLAGS="$build_flags"
57+
make $build_target BUILD_TAGS="$build_tags" BUILD_FLAGS="$build_flags" USE_LOGOS_STORAGE="$use_logos_storage"
58+
59+
# Stage runtime shared libraries required by built binaries.
60+
RUN mkdir -p /tmp/status-runtime-libs \
61+
&& cp /go/src/github.com/status-im/nim-sds/build/libsds.so /tmp/status-runtime-libs/ \
62+
&& if [ -f /go/src/github.com/status-im/logos-storage-nim/build/libstorage.so ]; then \
63+
cp /go/src/github.com/status-im/logos-storage-nim/build/libstorage.so /tmp/status-runtime-libs/; \
64+
fi
5765

5866
# Copy binaries to the second image
59-
FROM debian:bookworm-slim
67+
FROM debian:trixie-slim
6068

6169
LABEL maintainer="support@status.im"
6270
LABEL source="https://github.com/status-im/status-go"
6371
LABEL description="status-go is an underlying part of Status - a browser, messenger, and gateway to a decentralized world."
6472

6573
RUN apt-get update \
66-
&& apt-get install -y ca-certificates bash curl python3 \
74+
&& apt-get install -y ca-certificates bash curl python3 libgomp1 \
6775
&& apt-get clean \
6876
&& rm -rf /var/lib/apt/lists/*
6977

@@ -73,10 +81,10 @@ RUN mkdir -p /static/configs
7381
COPY --from=builder /go/src/github.com/status-im/status-go/build/bin/status-backend /usr/local/bin/
7482
COPY --from=builder /go/src/github.com/status-im/status-go/build/bin/push-notification-server /usr/local/bin/
7583
COPY --from=builder /go/src/github.com/status-im/status-go/tests-functional/waku_configs/* /static/configs/
76-
COPY --from=builder /go/src/github.com/status-im/nim-sds/build/libsds.so /usr/local/lib/
84+
COPY --from=builder /tmp/status-runtime-libs/ /usr/local/lib/
7785

7886
ENV LD_LIBRARY_PATH=/usr/local/lib/
7987

8088
EXPOSE 8080 8545 30303 30303/udp 30304/udp
8189

82-
CMD ["status-backend", "--help"]
90+
CMD ["status-backend", "--help"]

Makefile

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.PHONY: statusgo all test clean help
22
.PHONY: statusgo-ios-library statusgo-android-library
33
.PHONY: build-libsds clean-libsds rebuild-libsds
4+
.PHONY: clone-storage build-storage clean-storage test-storage
5+
.PHONY: storage-help
46

57
# Clear any GOROOT set outside of the Nix shell
68
export GOROOT=
@@ -133,6 +135,70 @@ LIBSDS ?= $(NIM_SDS_LIB_DIR)/libsds.$(LIB_EXT)
133135
CGO_CFLAGS+=-I$(NIM_SDS_INC_DIR)
134136
CGO_LDFLAGS+=-L$(NIM_SDS_LIB_DIR) -lsds
135137

138+
# `logos-storage` variables (opt-in)
139+
USE_LOGOS_STORAGE ?= false
140+
LOGOS_STORAGE_VERSION ?= 3c09f008bb5266a669fd19f18368f9e8b861b664
141+
LOGOS_STORAGE_SOURCE_DIR ?= $(GIT_ROOT)/../logos-storage-nim
142+
143+
# Option 1: Provide LOGOS_STORAGE_SOURCE_DIR. Make clones it if missing.
144+
# Option 2: Provide LOGOS_STORAGE_LIB_DIR and LOGOS_STORAGE_INC_DIR.
145+
ifdef LOGOS_STORAGE_LIB_DIR
146+
ifdef LOGOS_STORAGE_INC_DIR
147+
LOGOS_STORAGE_BUILD_FROM_SOURCE := false
148+
else
149+
$(error LOGOS_STORAGE_INC_DIR must be provided when LOGOS_STORAGE_LIB_DIR is set)
150+
endif
151+
else
152+
LOGOS_STORAGE_LIB_DIR := $(LOGOS_STORAGE_SOURCE_DIR)/build
153+
LOGOS_STORAGE_INC_DIR := $(LOGOS_STORAGE_SOURCE_DIR)/library
154+
LOGOS_STORAGE_BUILD_FROM_SOURCE := true
155+
endif
156+
157+
LIBSTORAGE ?= $(LOGOS_STORAGE_LIB_DIR)/libstorage.$(LIB_EXT)
158+
159+
RUNTIME_LIB_DIRS := $(NIM_SDS_LIB_DIR)
160+
LOGOS_STORAGE_BUILD_DEPS :=
161+
ifeq ($(USE_LOGOS_STORAGE),true)
162+
BUILD_TAGS += use_logos_storage
163+
CGO_CFLAGS += -I$(LOGOS_STORAGE_INC_DIR)
164+
CGO_LDFLAGS += -L$(LOGOS_STORAGE_LIB_DIR) -lstorage -Wl,-rpath,$(LOGOS_STORAGE_LIB_DIR)
165+
RUNTIME_LIB_DIRS := $(LOGOS_STORAGE_LIB_DIR):$(RUNTIME_LIB_DIRS)
166+
LOGOS_STORAGE_BUILD_DEPS += $(LIBSTORAGE)
167+
endif
168+
169+
clone-storage: ##@build Clone or update logos-storage-nim
170+
ifeq ($(LOGOS_STORAGE_BUILD_FROM_SOURCE),true)
171+
@echo "Cloning or updating logos-storage-nim ..."
172+
if [ ! -d "$(LOGOS_STORAGE_SOURCE_DIR)" ]; then \
173+
git clone --recurse-submodules https://github.com/logos-storage/logos-storage-nim.git $(LOGOS_STORAGE_SOURCE_DIR); \
174+
else \
175+
cd $(LOGOS_STORAGE_SOURCE_DIR) && git fetch --tags; \
176+
fi
177+
cd $(LOGOS_STORAGE_SOURCE_DIR) && git checkout $(LOGOS_STORAGE_VERSION) && git submodule update --init --recursive
178+
endif
179+
180+
$(LIBSTORAGE): clone-storage
181+
ifeq ($(LOGOS_STORAGE_BUILD_FROM_SOURCE),true)
182+
@echo "Building logos-storage: $(LIBSTORAGE)"
183+
$(MAKE) -C $(LOGOS_STORAGE_SOURCE_DIR) libstorage
184+
endif
185+
186+
build-storage: $(LIBSTORAGE)
187+
188+
clean-storage: ##@other Remove built native libstorage artifacts
189+
ifeq ($(LOGOS_STORAGE_BUILD_FROM_SOURCE),true)
190+
@rm -f "$(LOGOS_STORAGE_LIB_DIR)"/libstorage.*
191+
endif
192+
193+
test-storage: build-storage $(LIBSDS) generate ##@tests Run logosstorage package tests via gotestsum
194+
LD_LIBRARY_PATH="$(LOGOS_STORAGE_LIB_DIR):$(RUNTIME_LIB_DIRS)" \
195+
CGO_LDFLAGS="$(CGO_LDFLAGS) -L$(LOGOS_STORAGE_LIB_DIR) -lstorage -Wl,-rpath,$(LOGOS_STORAGE_LIB_DIR)" \
196+
CGO_CFLAGS="$(CGO_CFLAGS) -I$(LOGOS_STORAGE_INC_DIR)" \
197+
gotestsum --packages="./services/logosstorage" -f testname -- -count 1 -tags "use_logos_storage $(BUILD_TAGS) gowaku_skip_migrations"
198+
199+
storage-help: ##@build Show logos-storage build/test toggles and env vars
200+
@cat services/logosstorage/README.md
201+
136202
# mbedtls configuration for go-sqlcipher
137203
ifeq ($(detected_OS),Windows)
138204
# On Windows, use portable C implementations and add -Werror=implicit-function-declaration workaround
@@ -211,7 +277,7 @@ nix-purge: ##@nix Completely remove Nix setup, including /nix directory
211277
all: $(GO_CMD_NAMES)
212278

213279
.PHONY: $(GO_CMD_NAMES) $(GO_CMD_PATHS) $(GO_CMD_BUILDS)
214-
$(GO_CMD_BUILDS): generate $(LIBSDS)
280+
$(GO_CMD_BUILDS): generate $(LOGOS_STORAGE_BUILD_DEPS) $(LIBSDS)
215281
$(GO_CMD_BUILDS): ##@build Build any Go project from cmd folder
216282
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" \
217283
go build -v \
@@ -400,14 +466,14 @@ clean-generated: ##@generate Remove orphaned generated files
400466
echo "Skipping cleanup of generated files"; \
401467
fi
402468

403-
generate: PACKAGES ?= $$(go list -e ./... | grep -v "/contracts/")
404469
generate: PACKAGES ?= $$(go list -e ./... | grep -v "/contracts/")
405470
generate: GO_GENERATE_CMD ?= go tool go-generate-fast
406471
generate: export GO_GENERATE_FAST_DEBUG ?= false
407472
generate: export GO_GENERATE_FAST_RECACHE ?= false
408473
generate: clean-generated
409474
generate: ##@ Run generate for all given packages using go-generate-fast, fallback to `go generate` (e.g. for docker)
410475
@GOROOT=$$(go env GOROOT) $(GO_GENERATE_CMD) $(PACKAGES)
476+
@go generate -tags "use_logos_storage $(BUILD_TAGS)" ./services/logosstorage
411477

412478
generate-contracts:
413479
go generate ./contracts
@@ -433,7 +499,7 @@ docker-test: ##@tests Run tests in a docker container with golang.
433499

434500
test: test-unit ##@tests Run basic, short tests during development
435501

436-
test-unit-prep: $(LIBSDS)
502+
test-unit-prep: $(LOGOS_STORAGE_BUILD_DEPS) $(LIBSDS)
437503
test-unit-prep: generate
438504
test-unit-prep: export BUILD_TAGS ?=
439505
test-unit-prep: export UNIT_TEST_DRY_RUN ?= false
@@ -444,17 +510,17 @@ test-unit-prep: export UNIT_TEST_REPORT_CODECOV ?= false
444510

445511
test-unit: test-unit-prep
446512
test-unit: export UNIT_TEST_RERUN_FAILS ?= true
447-
test-unit: export UNIT_TEST_PACKAGES ?= $(call sh, go list ./... | \
513+
test-unit: export UNIT_TEST_PACKAGES ?= $(call sh, go list -tags '$(BUILD_TAGS)' ./... | \
448514
grep -v /t/e2e | \
449515
grep -v /t/benchmarks | \
450516
grep -v /transactions/fake | \
451517
grep -v /tests-unit-network)
452518
test-unit: ##@tests Run unit and integration tests
453-
LD_LIBRARY_PATH="$(NIM_SDS_LIB_DIR)" CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" \
519+
LD_LIBRARY_PATH="$(RUNTIME_LIB_DIRS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" \
454520
./scripts/run_unit_tests.sh
455521

456522
test-single: test-unit-prep
457-
LD_LIBRARY_PATH="$(NIM_SDS_LIB_DIR)" CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" \
523+
LD_LIBRARY_PATH="$(RUNTIME_LIB_DIRS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" \
458524
go test -v $(PKG) -testify.m $(TEST)
459525

460526
test-unit-network: test-unit-prep
@@ -469,15 +535,20 @@ test-unit-race: test-unit ##@tests Run unit and integration tests with -race fla
469535
test-functional: generate
470536
test-functional: export FUNCTIONAL_TESTS_DOCKER_UID ?= $(call sh, id -u)
471537
test-functional: export FUNCTIONAL_TESTS_REPORT_CODECOV ?= false
538+
test-functional: export USE_LOGOS_STORAGE := $(USE_LOGOS_STORAGE)
472539
test-functional:
473540
@./scripts/run_functional_tests.sh
474541

475542
benchmark: export FUNCTIONAL_TESTS_DOCKER_UID ?= $(call sh, id -u)
476543
benchmark:
477544
@./scripts/run_benchmark.sh
478545

546+
empty :=
547+
space := $(empty) $(empty)
548+
comma := ,
549+
479550
lint-panics: generate
480-
GOFLAGS=-tags='$(BUILD_TAGS),lint' \
551+
GOFLAGS=-tags='$(subst $(space),$(comma),$(strip $(BUILD_TAGS) lint))' \
481552
go tool goroutine-defer-guard -test=false -target github.com/status-im/status-go/common.LogOnPanic ./...
482553

483554
lint: generate lint-panics
@@ -487,7 +558,7 @@ lint:
487558
lint-fix: generate
488559
golangci-lint --build-tags '$(BUILD_TAGS) lint' run --fix ./...
489560

490-
clean: ##@other Cleanup
561+
clean: clean-storage ##@other Cleanup
491562
rm -fr build/bin/*
492563

493564
git-clean:
@@ -559,5 +630,5 @@ pytest-lint:
559630
$(MAKE) -C tests-functional lint
560631

561632
generate-db: ##@build Generate fake sqlite DBs in ./build directory for IDE SQL inspections
562-
LD_LIBRARY_PATH="$(NIM_SDS_LIB_DIR)" CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" \
633+
LD_LIBRARY_PATH="$(RUNTIME_LIB_DIRS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" \
563634
go run tools/generate-db/main.go -out-dir build/db

_assets/ci/Jenkinsfile.tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pipeline {
123123
variable: 'CODECOV_TOKEN'
124124
),
125125
]) {
126-
nix.develop('make test-unit V=1', pure: false)
126+
nix.develop('make test-unit V=1 USE_LOGOS_STORAGE=true', pure: false)
127127
}
128128
archiveArtifacts('report_*.xml, test_*.log, test-coverage.html')
129129
}

0 commit comments

Comments
 (0)