diff --git a/.github/workflows/test-nimble-install.yml b/.github/workflows/test-nimble-install.yml new file mode 100644 index 0000000000..c027cf754a --- /dev/null +++ b/.github/workflows/test-nimble-install.yml @@ -0,0 +1,53 @@ +name: Test Nimble Installation + +on: + pull_request: + push: + branches: + - simpler-deps + +jobs: + test-nimble-install: + continue-on-error: true # Some runs get oddly cancelled + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] # TODO: Windows + nim-version: ['2.2.4'] # TODO: tests with more versions + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: "true" # Needed to pull RLN script + + - uses: nim-lang/setup-nimble-action@v1 + with: + nimble-version: "0.20.1" + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Display Nimble version + run: nimble --version + + - name: Run nimble install on waku + run: nimble install + timeout-minutes: 60 + + - name: Run nimble check on waku + run: nimble check -l + timeout-minutes: 60 + + - name: Build example project + working-directory: examples/nimble + run: | + echo "Building example project..." + nimble --verbose build + + - name: Run example project + working-directory: examples/nimble + run: | + echo "Running example project..." + # nimble --verbose run # TODO: Use nimble run + ./example diff --git a/.gitignore b/.gitignore index 7430c3e995..070dbd0509 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # Nimble packages /vendor/.nimble +nimbledeps # Generated Files *.generated.nim diff --git a/examples/nimble/.gitignore b/examples/nimble/.gitignore new file mode 100644 index 0000000000..aa5500535c --- /dev/null +++ b/examples/nimble/.gitignore @@ -0,0 +1,4 @@ +nimbledeps +nimble.develop +nimble.paths +example \ No newline at end of file diff --git a/examples/nimble/config.nims b/examples/nimble/config.nims new file mode 100644 index 0000000000..29ebdc6f7f --- /dev/null +++ b/examples/nimble/config.nims @@ -0,0 +1,11 @@ +# begin Nimble config (version 2) +when withDir(thisDir(), system.fileExists("nimble.paths")): + include "nimble.paths" +# end Nimble config + +import os + +let rlnLib = getCurrentDir() / "build" / "librln.a" +echo "RLN lib path: ", rlnLib +switch("passL", rlnLib) +switch("passL", "-lm") diff --git a/examples/nimble/example.nimble b/examples/nimble/example.nimble new file mode 100644 index 0000000000..9bacbe8588 --- /dev/null +++ b/examples/nimble/example.nimble @@ -0,0 +1,33 @@ +# Package + +version = "0.1.0" +author = "fryorcraken" +description = "Test Waku with nimble" +license = "MIT" +srcDir = "src" +bin = @["example"] + +# Dependencies + +requires "chronos" +requires "results" +requires "waku#44bfddb245e30eeab850730dee67c41cbe7f7252" + +import os + +proc ensureRln(libFile: string = "build/librln.a", version = "v0.8.0") = + if not fileExists(libFile): + echo "Building RLN library..." + let buildDir = parentDir(parentDir(getCurrentDir())) & "/vendor/zerokit" + let outFile = libFile + + let outDir = parentDir(outFile) + if not dirExists(outDir): + mkDir(outDir) # Ensure build directory exists + + exec "bash ../../scripts/build_rln.sh " & buildDir & " " & version & " " & outFile + else: + echo "RLN library already exists: " & libFile + +before build: + ensureRln() diff --git a/examples/nimble/src/example.nim b/examples/nimble/src/example.nim new file mode 100644 index 0000000000..1ee756ab78 --- /dev/null +++ b/examples/nimble/src/example.nim @@ -0,0 +1,28 @@ +import chronos, results +import waku + +proc main() {.async.} = + echo("Starting Waku node...") + + # Create a basic configuration for the Waku node + # No RLN so we don't need to path an eth rpc endpoint + let config = NodeConfig.init( + protocolsConfig = ProtocolsConfig.init(entryNodes = @[], clusterId = 42) + ) + + # Create the node using the library API's createNode function + let node = (await createNode(config)).valueOr: + echo("Failed to create node: ", error) + quit(1) + + echo("Waku node created successfully!") + + # Start the node + (await startWaku(addr node)).isOkOr: + echo("Failed to start node: ", error) + quit(1) + + echo("Node started successfully! exiting") + +when isMainModule: + waitFor main() diff --git a/scripts/build_rln.sh b/scripts/build_rln.sh index 5e1b0caa5c..c93be290ae 100755 --- a/scripts/build_rln.sh +++ b/scripts/build_rln.sh @@ -19,7 +19,7 @@ host_triplet=$(rustc --version --verbose | awk '/host:/{print $2}') tarball="${host_triplet}" -tarball+="-rln.tar.gz" +tarball+="-default-rln.tar.gz" # Download the prebuilt rln library if it is available if curl --silent --fail-with-body -L \ diff --git a/waku.nimble b/waku.nimble index c63d202464..dee4f7d4c8 100644 --- a/waku.nimble +++ b/waku.nimble @@ -8,6 +8,7 @@ version = "0.36.0" author = "Status Research & Development GmbH" description = "Waku, Private P2P Messaging for Resource-Restricted Devices" license = "MIT or Apache License 2.0" +srcDir = "waku" #bin = @["build/waku"] ### Dependencies @@ -30,7 +31,8 @@ requires "nim >= 2.2.4", "regex", "results", "db_connector", - "minilru" + "minilru", + "https://github.com/vacp2p/mix#v0.1.0" ### Helper functions proc buildModule(filePath, params = "", lang = "c"): bool = diff --git a/waku/utils/requests.nim b/waku/utils/requests.nim index 5e5b9d9602..d9afd2887a 100644 --- a/waku/utils/requests.nim +++ b/waku/utils/requests.nim @@ -7,4 +7,4 @@ import bearssl/rand, stew/byteutils proc generateRequestId*(rng: ref HmacDrbgContext): string = var bytes: array[10, byte] hmacDrbgGenerate(rng[], bytes) - return toHex(bytes) + return byteutils.toHex(bytes) diff --git a/waku/waku_filter_v2/client.nim b/waku/waku_filter_v2/client.nim index 1dc018150a..954a71f564 100644 --- a/waku/waku_filter_v2/client.nim +++ b/waku/waku_filter_v2/client.nim @@ -30,7 +30,7 @@ type WakuFilterClient* = ref object of LPProtocol func generateRequestId(rng: ref HmacDrbgContext): string = var bytes: array[10, byte] hmacDrbgGenerate(rng[], bytes) - return toHex(bytes) + return byteutils.toHex(bytes) proc addSubscrObserver*(wfc: WakuFilterClient, obs: SubscriptionObserver) = wfc.subscrObservers.add(obs) diff --git a/waku/waku_store_sync/reconciliation.nim b/waku/waku_store_sync/reconciliation.nim index 8b196a3e90..f5883190e5 100644 --- a/waku/waku_store_sync/reconciliation.nim +++ b/waku/waku_store_sync/reconciliation.nim @@ -79,7 +79,7 @@ proc messageIngress*( let id = SyncID(time: msg.timestamp, hash: msgHash) self.storage.insert(id, pubsubTopic, msg.contentTopic).isOkOr: - error "failed to insert new message", msg_hash = $id.hash.toHex(), error = $error + error "failed to insert new message", msg_hash = $byteutils.toHex(id.hash), error = $error proc messageIngress*( self: SyncReconciliation, @@ -87,7 +87,7 @@ proc messageIngress*( pubsubTopic: PubsubTopic, msg: WakuMessage, ) = - trace "message ingress", msg_hash = msgHash.toHex(), msg = msg + trace "message ingress", msg_hash = byteutils.toHex(msgHash), msg = msg if msg.ephemeral: return @@ -95,7 +95,7 @@ proc messageIngress*( let id = SyncID(time: msg.timestamp, hash: msgHash) self.storage.insert(id, pubsubTopic, msg.contentTopic).isOkOr: - error "failed to insert new message", msg_hash = $id.hash.toHex(), error = $error + error "failed to insert new message", msg_hash = $byteutils.toHex(id.hash), error = $error proc messageIngress*( self: SyncReconciliation, @@ -104,7 +104,7 @@ proc messageIngress*( contentTopic: ContentTopic, ) = self.storage.insert(id, pubsubTopic, contentTopic).isOkOr: - error "failed to insert new message", msg_hash = $id.hash.toHex(), error = $error + error "failed to insert new message", msg_hash = $byteutils.toHex(id.hash), error = $error proc preProcessPayload( self: SyncReconciliation, payload: RangesData