From 74f3ce0e63a0c2c9901375f447b18c0ecce0ba5c Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:44:33 +0530 Subject: [PATCH] fix: incl rustup in makefile --- Makefile | 17 ++++++++++++++- scripts/install_anvil.sh | 14 +++++++++++++ .../test_rln_group_manager_onchain.nim | 21 ++++++++++++------- 3 files changed, 43 insertions(+), 9 deletions(-) create mode 100755 scripts/install_anvil.sh diff --git a/Makefile b/Makefile index c578efc286..9765de9007 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,20 @@ endif ################## .PHONY: deps libbacktrace +rustup: +ifeq (, $(shell which cargo)) +# Install Rustup if it's not installed +# -y: Assume "yes" for all prompts +# --default-toolchain stable: Install the stable toolchain + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable +endif + +anvil: rustup +ifeq (, $(shell which anvil)) +# Install Anvil if it's not installed + ./scripts/install_anvil.sh +endif + deps: | deps-common nat-libs waku.nims @@ -166,7 +180,8 @@ testcommon: | build deps ########## .PHONY: testwaku wakunode2 testwakunode2 example2 chat2 chat2bridge -testwaku: | build deps librln +# install anvil only for the testwaku target +testwaku: | build deps anvil librln echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim test -d:os=$(shell uname) $(NIM_PARAMS) waku.nims diff --git a/scripts/install_anvil.sh b/scripts/install_anvil.sh new file mode 100755 index 0000000000..13d5f8dfdb --- /dev/null +++ b/scripts/install_anvil.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Install Anvil + + +BASE_DIR="${XDG_CONFIG_HOME:-$HOME}" +FOUNDRY_DIR="${FOUNDRY_DIR-"$BASE_DIR/.foundry"}" +FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin" + +curl -L https://foundry.paradigm.xyz | bash +# Extract the source path from the download result +echo "foundryup_path: $FOUNDRY_BIN_DIR" +# run foundryup +$FOUNDRY_BIN_DIR/foundryup \ No newline at end of file diff --git a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim index 3773bf598d..63efbf7439 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -6,7 +6,7 @@ else: {.push raises: [].} import - std/[options, osproc, sequtils, deques, streams, strutils, tempfiles], + std/[options, os, osproc, sequtils, deques, streams, strutils, tempfiles], stew/[results, byteutils], stew/shims/net as stewNet, testutils/unittests, @@ -117,6 +117,15 @@ proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} = return (pk, acc) +proc getAnvilPath(): string = + var anvilPath = "" + if existsEnv("XDG_CONFIG_HOME"): + anvilPath = joinPath(anvilPath, os.getEnv("XDG_CONFIG_HOME", "")) + else: + anvilPath = joinPath(anvilPath, os.getEnv("HOME", "")) + anvilPath = joinPath(anvilPath, ".foundry/bin/anvil") + return $anvilPath + # Runs Anvil daemon proc runAnvil(): Process = # Passed options are @@ -126,13 +135,9 @@ proc runAnvil(): Process = # --chain-id Chain ID of the network. # See anvil documentation https://book.getfoundry.sh/reference/anvil/ for more details try: - let installAnvil = startProcess("cargo", args = ["install", "--git", "https://github.com/foundry-rs/foundry", "--profile", "local", "--locked", "anvil"], options = {poUsePath}) - let anvilExitCode = waitForExit(installAnvil) - if anvilExitCode != 0: - error "Anvil installation failed", anvilExitCode - raise newException(CatchableError, "Anvil installation failed: " & $anvilExitCode) - - let runAnvil = startProcess("anvil", args = ["--port", "8540", "--gas-limit", "300000000000000", "--balance", "10000", "--chain-id", "1337"], options = {poUsePath}) + let anvilPath = getAnvilPath() + debug "Anvil path", anvilPath + let runAnvil = startProcess(anvilPath, args = ["--port", "8540", "--gas-limit", "300000000000000", "--balance", "10000", "--chain-id", "1337"], options = {poUsePath}) let anvilPID = runAnvil.processID # We read stdout from Anvil to see when daemon is ready