Skip to content

Commit bb4bd12

Browse files
committed
build: automate mix RLN v2.0.0 build and linking for mix binaries
1 parent 3e24874 commit bb4bd12

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

Makefile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,15 @@ nimbus-build-system-nimble-dir:
187187
##################
188188
## RLN ##
189189
##################
190-
.PHONY: librln
190+
.PHONY: librln mix-librln
191191

192192
LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
193193
LIBRLN_VERSION := v0.9.0
194+
MIX_LIBRLN_VERSION ?= v2.0.0
195+
MIX_LIBRLN_REPO ?= https://github.com/vacp2p/zerokit.git
196+
MIX_LIBRLN_SRCDIR ?= $(CURDIR)/build/zerokit_$(MIX_LIBRLN_VERSION)
197+
MIX_LIBRLN_FILE ?= $(CURDIR)/build/librln_mix_$(MIX_LIBRLN_VERSION).a
198+
MIX_LIBRLN_NIM_PARAMS := --passL:$(MIX_LIBRLN_FILE) --passL:-lm
194199

195200
ifeq ($(detected_OS),Windows)
196201
LIBRLN_FILE ?= rln.lib
@@ -202,12 +207,19 @@ $(LIBRLN_FILE):
202207
echo -e $(BUILD_MSG) "$@" && \
203208
./scripts/build_rln.sh $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(LIBRLN_FILE)
204209

210+
$(MIX_LIBRLN_FILE):
211+
echo -e $(BUILD_MSG) "$@" && \
212+
./scripts/build_rln_mix.sh $(MIX_LIBRLN_SRCDIR) $(MIX_LIBRLN_VERSION) $(MIX_LIBRLN_FILE) $(MIX_LIBRLN_REPO)
213+
205214
librln: | $(LIBRLN_FILE)
206215
$(eval NIM_PARAMS += --passL:$(LIBRLN_FILE) --passL:-lm)
207216

217+
mix-librln: | $(MIX_LIBRLN_FILE)
218+
208219
clean-librln:
209220
cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml
210221
rm -f $(LIBRLN_FILE)
222+
rm -f $(MIX_LIBRLN_FILE)
211223

212224
# Extend clean target
213225
clean: | clean-librln
@@ -232,10 +244,10 @@ testwaku: | build deps rln-deps librln
232244
echo -e $(BUILD_MSG) "build/$@" && \
233245
$(ENV_SCRIPT) nim test -d:os=$(shell uname) $(NIM_PARAMS) waku.nims
234246

235-
wakunode2: | build deps librln
247+
wakunode2: | build deps librln mix-librln
236248
echo -e $(BUILD_MSG) "build/$@" && \
237249
\
238-
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims
250+
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) $(MIX_LIBRLN_NIM_PARAMS) waku.nims
239251

240252
benchmarks: | build deps librln
241253
echo -e $(BUILD_MSG) "build/$@" && \
@@ -253,9 +265,9 @@ chat2: | build deps librln
253265
echo -e $(BUILD_MSG) "build/$@" && \
254266
$(ENV_SCRIPT) nim chat2 $(NIM_PARAMS) waku.nims
255267

256-
chat2mix: | build deps librln
268+
chat2mix: | build deps librln mix-librln
257269
echo -e $(BUILD_MSG) "build/$@" && \
258-
$(ENV_SCRIPT) nim chat2mix $(NIM_PARAMS) waku.nims
270+
$(ENV_SCRIPT) nim chat2mix $(NIM_PARAMS) $(MIX_LIBRLN_NIM_PARAMS) waku.nims
259271

260272
rln-db-inspector: | build deps librln
261273
echo -e $(BUILD_MSG) "build/$@" && \

scripts/build_rln_mix.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Build a separate, pinned RLN library for mix spam-protection usage.
4+
# This keeps the main nwaku RLN dependency flow unchanged.
5+
6+
set -euo pipefail
7+
8+
source_dir="${1:-}"
9+
version="${2:-}"
10+
output_file="${3:-}"
11+
repo_url="${4:-https://github.com/vacp2p/zerokit.git}"
12+
13+
if [[ -z "${source_dir}" || -z "${version}" || -z "${output_file}" ]]; then
14+
echo "Usage: $0 <source_dir> <version_tag> <output_file> [repo_url]"
15+
exit 1
16+
fi
17+
18+
mkdir -p "$(dirname "${source_dir}")"
19+
mkdir -p "$(dirname "${output_file}")"
20+
21+
if [[ ! -d "${source_dir}/.git" ]]; then
22+
echo "Cloning zerokit ${version} from ${repo_url}..."
23+
if [[ -e "${source_dir}" ]]; then
24+
echo "Path exists but is not a git repository: ${source_dir}"
25+
echo "Please remove it and retry."
26+
exit 1
27+
fi
28+
git clone --depth 1 --branch "${version}" "${repo_url}" "${source_dir}"
29+
else
30+
echo "Using existing zerokit checkout in ${source_dir}"
31+
current_tag="$(git -C "${source_dir}" describe --tags --exact-match 2>/dev/null || true)"
32+
if [[ "${current_tag}" != "${version}" ]]; then
33+
echo "Updating zerokit checkout to ${version}..."
34+
git -C "${source_dir}" fetch --tags origin "${version}"
35+
git -C "${source_dir}" checkout --detach "${version}"
36+
fi
37+
fi
38+
39+
echo "Building mix RLN library from source (version ${version})..."
40+
cargo build --release -p rln --manifest-path "${source_dir}/rln/Cargo.toml"
41+
42+
cp "${source_dir}/target/release/librln.a" "${output_file}"
43+
echo "Successfully built ${output_file}"

0 commit comments

Comments
 (0)