Skip to content

Commit

Permalink
feat: windows support compress into one big commit (#3107)
Browse files Browse the repository at this point in the history
  • Loading branch information
darshankabariya authored Oct 23, 2024
1 parent 3dc3fc8 commit ff21c01
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 10 deletions.
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

##########
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions scripts/build_rln.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
68 changes: 68 additions & 0 deletions scripts/windows_setup.sh
Original file line number Diff line number Diff line change
@@ -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!"

0 comments on commit ff21c01

Please sign in to comment.