From 9d5c9dfb829914bd2bc176b33ab2b6ab9a8aacf3 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Wed, 23 Oct 2024 11:17:52 +0530 Subject: [PATCH] feat: windows support compress into one big commit --- Makefile | 22 ++++++++++--- README.md | 13 +++++++- config.nims | 10 ++++++ scripts/build_rln.sh | 11 ++++--- scripts/windows_setup.sh | 68 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 scripts/windows_setup.sh diff --git a/Makefile b/Makefile index bf6f9b3861..02de7fc098 100644 --- a/Makefile +++ b/Makefile @@ -29,10 +29,22 @@ GIT_SUBMODULE_UPDATE := git submodule update --init --recursive else # "variables.mk" was included. Business as usual until the end of this file. -ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... - detected_OS := Windows -else - detected_OS := $(strip $(shell uname)) +# Determine the OS +detected_OS := $(shell uname -s) +ifneq (,$(findstring MINGW,$(detected_OS))) + detected_OS := Windows +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 + NIM_PARAMS += $(foreach lib,$(LIBS),--passL:"$(lib)") endif ########## @@ -146,7 +158,7 @@ clean: | clean-libbacktrace LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit LIBRLN_VERSION := v0.5.1 -ifeq ($(OS),Windows_NT) +ifeq ($(detected_OS),Windows) LIBRLN_FILE := rln.lib else LIBRLN_FILE := librln_$(LIBRLN_VERSION).a diff --git a/README.md b/README.md index 5fb8afc1e2..94995d5dd6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The nwaku repository implements Waku, and provides tools related to it. For more details see the [source code](waku/README.md) -## How to Build & Run +## How to Build & Run ( Linux, MacOS & WSL ) These instructions are generic. For more detailed instructions, see the Waku source code above. @@ -48,6 +48,17 @@ For more on how to run `wakunode2`, refer to: ##### WSL If you encounter difficulties building the project on WSL, consider placing the project within WSL's filesystem, avoiding the `/mnt/` directory. +### 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. + +The current setup procedure is as follows: + +1. Clone the repository and checkout master branch +2. Ensure prerequisites are installed (Make, GCC, MSYS2/MinGW) +3. Run scripts/windows_setup.sh + ### Developing #### Nim Runtime diff --git a/config.nims b/config.nims index 4c3d8dfacf..25066dcb26 100644 --- a/config.nims +++ b/config.nims @@ -1,9 +1,19 @@ +import os + if defined(release): switch("nimcache", "nimcache/release/$projectName") else: switch("nimcache", "nimcache/debug/$projectName") if defined(windows): + switch("passL", "rln.lib") + + # Automatically add all vendor subdirectories + for dir in walkDir("./vendor"): + if dir.kind == pcDir: + switch("path", dir.path) + switch("path", dir.path / "src") + # disable timestamps in Windows PE headers - https://wiki.debian.org/ReproducibleBuilds/TimestampsInPEBinaries switch("passL", "-Wl,--no-insert-timestamp") # increase stack size diff --git a/scripts/build_rln.sh b/scripts/build_rln.sh index d4843ca5ed..992c1f4347 100755 --- a/scripts/build_rln.sh +++ b/scripts/build_rln.sh @@ -42,10 +42,13 @@ else # Build rln instead # first, check if submodule version = version in Makefile cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml" - submodule_version=$( - cargo metadata --format-version=1 --no-deps --manifest-path "${build_dir}/rln/Cargo.toml" \ - | jq -r '.packages[] | select(.name == "rln") | .version' - ) + + if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; 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/windows_setup.sh b/scripts/windows_setup.sh new file mode 100644 index 0000000000..02b9bdc4c4 --- /dev/null +++ b/scripts/windows_setup.sh @@ -0,0 +1,68 @@ +#!/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!"