diff --git a/Makefile b/Makefile index 99ceadbb1..473bb7801 100644 --- a/Makefile +++ b/Makefile @@ -34,14 +34,14 @@ ifneq (,$(findstring MINGW,$(detected_OS))) endif ifeq ($(detected_OS),Windows) - # Define a new temporary directory for Windows - TMP_DIR := $(CURDIR)/tmp - $(shell mkdir -p $(TMP_DIR)) - export TMP := $(TMP_DIR) - export TEMP := $(TMP_DIR) - - # Add the necessary libraries to the linker flags - LIBS = -static -lws2_32 -lbcrypt -luserenv -lntdll -lminiupnpc + # Update MINGW_PATH to standard MinGW location + MINGW_PATH = /mingw64 + NIM_PARAMS += --passC:"-I$(MINGW_PATH)/include" + NIM_PARAMS += --passL:"-L$(MINGW_PATH)/lib" + NIM_PARAMS += --passL:"-Lvendor/nim-nat-traversal/vendor/miniupnp/miniupnpc" + NIM_PARAMS += --passL:"-Lvendor/nim-nat-traversal/vendor/libnatpmp-upstream" + + LIBS = -static -lws2_32 -lbcrypt -liphlpapi -luserenv -lntdll -lminiupnpc -lnatpmp -lpq NIM_PARAMS += $(foreach lib,$(LIBS),--passL:"$(lib)") endif diff --git a/README.md b/README.md index cb13d6cef..9d8b58110 100644 --- a/README.md +++ b/README.md @@ -52,14 +52,42 @@ If you encounter difficulties building the project on WSL, consider placing the ### How to Build & Run ( Windows ) -Note: This is a work in progress. The current setup procedure is as follows: -Goal: Get rid of windows specific procedures and make the build process the same as linux/macos. +### Windows Build Instructions -The current setup procedure is as follows: +#### 1. Install Required Tools +- **Git Bash Terminal**: Download and install from https://git-scm.com/download/win +- **MSYS2**: + a. Download installer from https://www.msys2.org + b. Install at "C:\" (default location). Remove/rename the msys folder in case of previous installation. + c. Use the mingw64 terminal from msys64 directory for package installation. -1. Clone the repository and checkout master branch -2. Ensure prerequisites are installed (Make, GCC, MSYS2/MinGW) -3. Run scripts/windows_setup.sh +#### 2. Install Dependencies +Open MSYS2 mingw64 terminal and run the following one-by-one : +```bash +pacman -Syu --noconfirm +pacman -S --noconfirm --needed mingw-w64-x86_64-toolchain +pacman -S --noconfirm --needed base-devel make cmake upx +pacman -S --noconfirm --needed mingw-w64-x86_64-rust +pacman -S --noconfirm --needed mingw-w64-x86_64-postgresql +pacman -S --noconfirm --needed mingw-w64-x86_64-gcc +pacman -S --noconfirm --needed mingw-w64-x86_64-gcc-libs +pacman -S --noconfirm --needed mingw-w64-x86_64-libwinpthread-git +pacman -S --noconfirm --needed mingw-w64-x86_64-zlib +pacman -S --noconfirm --needed mingw-w64-x86_64-openssl +pacman -S --noconfirm --needed mingw-w64-x86_64-python +``` + +#### 3. Build Wakunode +- Open Git Bash as administrator +- clone nwaku and cd nwaku +- Execute: `./scripts/build_wakunode_windows.sh` + +#### 4. Troubleshooting +If `wakunode2.exe` isn't generated: +- **Missing Dependencies**: Verify with: + `which make cmake gcc g++ rustc cargo python3 upx` + If missing, revisit Step 2 or ensure MSYS2 is at `C:\` +- **Installation Conflicts**: Remove existing MinGW/MSYS2/Git Bash installations and perform fresh install ### Developing diff --git a/config.nims b/config.nims index 25066dcb2..f74fe183f 100644 --- a/config.nims +++ b/config.nims @@ -7,6 +7,7 @@ else: if defined(windows): switch("passL", "rln.lib") + switch("define", "postgres=false") # Automatically add all vendor subdirectories for dir in walkDir("./vendor"): diff --git a/scripts/build_rln.sh b/scripts/build_rln.sh index 992c1f434..1cf9b9879 100755 --- a/scripts/build_rln.sh +++ b/scripts/build_rln.sh @@ -43,12 +43,13 @@ else # first, check if submodule version = version in Makefile cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml" - if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then + detected_OS=$(uname -s) + if [[ "$detected_OS" == MINGW* || "$detected_OS" == MSYS* ]]; then submodule_version=$(cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml" | sed -n 's/.*"name":"rln","version":"\([^"]*\)".*/\1/p') else submodule_version=$(cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml" | jq -r '.packages[] | select(.name == "rln") | .version') fi - + if [[ "v${submodule_version}" != "${rln_version}" ]]; then echo "Submodule version (v${submodule_version}) does not match version in Makefile (${rln_version})" echo "Please update the submodule to ${rln_version}" diff --git a/scripts/build_wakunode_windows.sh b/scripts/build_wakunode_windows.sh new file mode 100755 index 000000000..ef0881836 --- /dev/null +++ b/scripts/build_wakunode_windows.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +echo "- - - - - - - - - - Windows Setup Script - - - - - - - - - -" + +success_count=0 +failure_count=0 + +# Function to execute a command and check its status +execute_command() { + echo "Executing: $1" + if eval "$1"; then + echo -e "✓ Command succeeded \n" + ((success_count++)) + else + echo -e "✗ Command failed \n" + ((failure_count++)) + fi +} + +echo "1. -.-.-.-- Set PATH -.-.-.-" +export PATH="/c/msys64/usr/bin:/c/msys64/mingw64/bin:/c/msys64/usr/lib:/c/msys64/mingw64/lib:$PATH" + +echo "2. -.-.-.- Verify dependencies -.-.-.-" +execute_command "which gcc g++ make cmake cargo upx rustc python" + +echo "3. -.-.-.- Updating submodules -.-.-.-" +execute_command "git submodule update --init --recursive" + +echo "4. -.-.-.- Creating tmp directory -.-.-.-" +execute_command "mkdir -p tmp" + +echo "5. -.-.-.- Building Nim -.-.-.-" +cd vendor/nimbus-build-system/vendor/Nim +execute_command "./build_all.bat" +cd ../../../.. + +echo "6. -.-.-.- Building libunwind -.-.-.-" +cd vendor/nim-libbacktrace +execute_command "make all V=1" +execute_command "make install/usr/lib/libunwind.a V=1" +cp ./vendor/libunwind/build/lib/libunwind.a install/usr/lib +cd ../../ + +echo "7. -.-.-.- Building miniupnpc -.-.-.- " +cd vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc +execute_command "git checkout little_chore_windows_support" +execute_command "make -f Makefile.mingw CC=gcc CXX=g++ libminiupnpc.a V=1" +cd ../../../../.. + +echo "8. -.-.-.- Building libnatpmp -.-.-.- " +cd ./vendor/nim-nat-traversal/vendor/libnatpmp-upstream +make CC="gcc -fPIC -D_WIN32_WINNT=0x0600 -DNATPMP_STATICLIB" libnatpmp.a V=1 +cd ../../../../ + +echo "9. -.-.-.- Building wakunode2 -.-.-.- " +execute_command "make wakunode2 LOG_LEVEL=DEBUG V=1 -j8" + +echo "Windows setup completed successfully!" +echo "✓ Successful commands: $success_count" +echo "✗ Failed commands: $failure_count" diff --git a/scripts/windows_setup.sh b/scripts/windows_setup.sh deleted file mode 100644 index 02b9bdc4c..000000000 --- a/scripts/windows_setup.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -set -e # Exit immediately if a command exits with a non-zero status - -echo "Windows Setup Script" -echo "====================" - -# Function to execute a command and check its status -execute_command() { - echo "Executing: $1" - if eval "$1"; then - echo "✓ Command succeeded" - else - echo "✗ Command failed" - exit 1 - fi -} - -# Function to change directory safely -change_directory() { - echo "Changing to directory: $1" - if cd "$1"; then - echo "✓ Changed directory successfully" - else - echo "✗ Failed to change directory" - exit 1 - fi -} - -# Function to build a component -build_component() { - local dir="$1" - local command="$2" - local name="$3" - - echo "Building $name" - if [ -d "$dir" ]; then - change_directory "$dir" - execute_command "$command" - change_directory - > /dev/null - else - echo "✗ $name directory not found: $dir" - exit 1 - fi -} - -echo "1. Updating submodules" -execute_command "git submodule update --init --recursive" - -echo "2. Creating tmp directory" -execute_command "mkdir -p tmp" - -echo "3. Building Nim" -build_component "vendor/nimbus-build-system/vendor/Nim" "./build_all.bat" "Nim" - -echo "4. Building miniupnpc" -build_component "vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc" "./mingw32make.bat" "miniupnpc" - -echo "5. Building libnatpmp" -build_component "vendor/nim-nat-traversal/vendor/libnatpmp-upstream" "./build.bat" "libnatpmp" - -echo "6. Building libunwind" -build_component "vendor/nim-libbacktrace" "make install/usr/lib/libunwind.a" "libunwind" - -echo "7. Building wakunode2" -execute_command "make wakunode2 V=1 NIMFLAGS="-d:disableMarchNative -d:postgres -d:chronicles_colors:none" " - -echo "Windows setup completed successfully!" diff --git a/waku/common/databases/db_postgres/dbconn.nim b/waku/common/databases/db_postgres/dbconn.nim index 5aa852446..0edb74ede 100644 --- a/waku/common/databases/db_postgres/dbconn.nim +++ b/waku/common/databases/db_postgres/dbconn.nim @@ -182,12 +182,15 @@ proc waitQueryToFinish( let asyncFd = cast[asyncengine.AsyncFD](pqsocket(dbConnWrapper.dbConn)) - asyncengine.addReader2(asyncFd, onDataAvailable).isOkOr: - dbConnWrapper.futBecomeFree.fail(newException(ValueError, $error)) - return err("failed to add event reader in waitQueryToFinish: " & $error) - defer: - asyncengine.removeReader2(asyncFd).isOkOr: - return err("failed to remove event reader in waitQueryToFinish: " & $error) + when not defined(windows): + asyncengine.addReader2(asyncFd, onDataAvailable).isOkOr: + dbConnWrapper.futBecomeFree.fail(newException(ValueError, $error)) + return err("failed to add event reader in waitQueryToFinish: " & $error) + defer: + asyncengine.removeReader2(asyncFd).isOkOr: + return err("failed to remove event reader in waitQueryToFinish: " & $error) + else: + return err("Postgres not supported on Windows") await futDataAvailable