diff --git a/Makefile b/Makefile index 8f98e90bd..5d960c4c0 100644 --- a/Makefile +++ b/Makefile @@ -187,10 +187,15 @@ nimbus-build-system-nimble-dir: ################## ## RLN ## ################## -.PHONY: librln +.PHONY: librln mix-librln LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit LIBRLN_VERSION := v0.9.0 +MIX_LIBRLN_VERSION ?= v2.0.0 +MIX_LIBRLN_REPO ?= https://github.com/vacp2p/zerokit.git +MIX_LIBRLN_SRCDIR ?= $(CURDIR)/build/zerokit_$(MIX_LIBRLN_VERSION) +MIX_LIBRLN_FILE ?= $(CURDIR)/build/librln_mix_$(MIX_LIBRLN_VERSION).a +MIX_LIBRLN_NIM_PARAMS := --passL:$(MIX_LIBRLN_FILE) --passL:-lm ifeq ($(detected_OS),Windows) LIBRLN_FILE ?= rln.lib @@ -202,12 +207,19 @@ $(LIBRLN_FILE): echo -e $(BUILD_MSG) "$@" && \ ./scripts/build_rln.sh $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(LIBRLN_FILE) +$(MIX_LIBRLN_FILE): + echo -e $(BUILD_MSG) "$@" && \ + ./scripts/build_rln_mix.sh $(MIX_LIBRLN_SRCDIR) $(MIX_LIBRLN_VERSION) $(MIX_LIBRLN_FILE) $(MIX_LIBRLN_REPO) + librln: | $(LIBRLN_FILE) $(eval NIM_PARAMS += --passL:$(LIBRLN_FILE) --passL:-lm) +mix-librln: | $(MIX_LIBRLN_FILE) + clean-librln: cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml rm -f $(LIBRLN_FILE) + rm -f $(MIX_LIBRLN_FILE) # Extend clean target clean: | clean-librln @@ -232,10 +244,10 @@ testwaku: | build deps rln-deps librln echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim test -d:os=$(shell uname) $(NIM_PARAMS) waku.nims -wakunode2: | build deps librln +wakunode2: | build deps librln mix-librln echo -e $(BUILD_MSG) "build/$@" && \ \ - $(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims + $(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) $(MIX_LIBRLN_NIM_PARAMS) waku.nims benchmarks: | build deps librln echo -e $(BUILD_MSG) "build/$@" && \ @@ -253,9 +265,9 @@ chat2: | build deps librln echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim chat2 $(NIM_PARAMS) waku.nims -chat2mix: | build deps librln +chat2mix: | build deps librln mix-librln echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim chat2mix $(NIM_PARAMS) waku.nims + $(ENV_SCRIPT) nim chat2mix $(NIM_PARAMS) $(MIX_LIBRLN_NIM_PARAMS) waku.nims rln-db-inspector: | build deps librln echo -e $(BUILD_MSG) "build/$@" && \ diff --git a/scripts/build_rln_mix.sh b/scripts/build_rln_mix.sh new file mode 100755 index 000000000..786ef76f5 --- /dev/null +++ b/scripts/build_rln_mix.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Build a separate, pinned RLN library for mix spam-protection usage. +# This keeps the main nwaku RLN dependency flow unchanged. + +set -euo pipefail + +source_dir="${1:-}" +version="${2:-}" +output_file="${3:-}" +repo_url="${4:-https://github.com/vacp2p/zerokit.git}" + +if [[ -z "${source_dir}" || -z "${version}" || -z "${output_file}" ]]; then + echo "Usage: $0 [repo_url]" + exit 1 +fi + +mkdir -p "$(dirname "${source_dir}")" +mkdir -p "$(dirname "${output_file}")" + +if [[ ! -d "${source_dir}/.git" ]]; then + echo "Cloning zerokit ${version} from ${repo_url}..." + if [[ -e "${source_dir}" ]]; then + echo "Path exists but is not a git repository: ${source_dir}" + echo "Please remove it and retry." + exit 1 + fi + git clone --depth 1 --branch "${version}" "${repo_url}" "${source_dir}" +else + echo "Using existing zerokit checkout in ${source_dir}" + current_tag="$(git -C "${source_dir}" describe --tags --exact-match 2>/dev/null || true)" + if [[ "${current_tag}" != "${version}" ]]; then + echo "Updating zerokit checkout to ${version}..." + git -C "${source_dir}" fetch --tags origin "${version}" + git -C "${source_dir}" checkout --detach "${version}" + fi +fi + +echo "Building mix RLN library from source (version ${version})..." +cargo build --release -p rln --manifest-path "${source_dir}/rln/Cargo.toml" + +cp "${source_dir}/target/release/librln.a" "${output_file}" +echo "Successfully built ${output_file}"