Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remain windows support #3162

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ 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 += --passL:"-L$(MINGW_PATH)/lib"
LIBS = -static -lws2_32 -lbcrypt -liphlpapi -luserenv -lntdll -lminiupnpc -lnatpmp -lpq
NIM_PARAMS += $(foreach lib,$(LIBS),--passL:"$(lib)")
NIM_PARAMS += --passC:"-I$(MINGW_PATH)/include"
endif

##########
Expand Down
23 changes: 23 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,36 @@ else:

if defined(windows):
switch("passL", "rln.lib")
switch("define", "postgres=false")

# MinGW library paths
switch("passL", "-L/mingw64/lib")
switch("passC", "-I/mingw64/include")

# Standard MinGW linking
switch("passL", "-static -lws2_32 -lbcrypt -luserenv -lntdll")

# NAT traversal libraries
switch("passL", "-lminiupnpc -Lvendor/nim-nat-traversal/vendor/miniupnp/miniupnpc")
switch("passL", "-lnatpmp -Lvendor/nim-nat-traversal/vendor/libnatpmp-upstream")

# Disable timestamp in PE headers
switch("passL", "-Wl,--no-insert-timestamp")
switch("passL", "-Wl,--stack,8388608")

# Chronicles configuration
switch("define", "chronicles_colors=off")

# Automatically add all vendor subdirectories
for dir in walkDir("./vendor"):
if dir.kind == pcDir:
switch("path", dir.path)
switch("path", dir.path / "src")

switch("path", "./vendor/nim-nat-traversal")
switch("path", "./vendor/nim-nat-traversal/vendor/libnatpmp-upstream")
switch("path", "./vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc")

# disable timestamps in Windows PE headers - https://wiki.debian.org/ReproducibleBuilds/TimestampsInPEBinaries
switch("passL", "-Wl,--no-insert-timestamp")
# increase stack size
Expand Down
5 changes: 3 additions & 2 deletions scripts/build_rln.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
61 changes: 52 additions & 9 deletions scripts/windows_setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
#!/bin/bash

# 1. Install Git Bash terminal
# Download and install from: https://git-scm.com/download/win
#
# 2. Install MSYS2
# a. Download the installer from: https://www.msys2.org
# b. Run the installer
# c. inside msys2 directory mutiple terminal you need to use mingw64 terminal all package and library
#
# 3. Open MSYS2 MINGW^$ terminal and run the following commands to install requirements:
# pacman -Syu --noconfirm
# pacman -S --noconfirm --needed mingw-w64-x86_64-toolchain
# pacman -S --noconfirm --needed base-devel
# pacman -S --noconfirm --needed make
# pacman -S --noconfirm --needed cmake
# pacman -S --noconfirm --needed 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
#
# 4. Setup PATH
# MSYS_DIR = xyz
# export PATH="{MSYS_DIR}/msys64/mingw64/bin:$PATH"
# export PATH="{MSYS_DIR}/msys64/mingw64/lib:$PATH"
# export PATH="{MSYS_DIR}/msys64/ucrt64/bin:$PATH"
# export PATH="{MSYS_DIR}/msys64/ucrt64/lib:$PATH"
#
# 5. on git bash terminal run this scripts

set -e # Exit immediately if a command exits with a non-zero status

echo "Windows Setup Script"
Expand Down Expand Up @@ -32,7 +64,7 @@ build_component() {
local dir="$1"
local command="$2"
local name="$3"

echo "Building $name"
if [ -d "$dir" ]; then
change_directory "$dir"
Expand All @@ -51,18 +83,29 @@ 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"
cd vendor/nimbus-build-system/vendor/Nim
execute_command "./build_all.bat"
cd ../../../..

echo "4. Building miniupnpc"
build_component "vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc" "./mingw32make.bat" "miniupnpc"
echo "4. Building libunwind"
cd vendor/nim-libbacktrace
execute_command "make all V=1"
execute_command "make install/usr/lib/libunwind.a V=1"
cd ../../

echo "5. Building libnatpmp"
build_component "vendor/nim-nat-traversal/vendor/libnatpmp-upstream" "./build.bat" "libnatpmp"
echo "5. Building miniupnpc"
cd vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc
git checkout little_chore_windows_support
execute_command "make -f Makefile.mingw CC=gcc CXX=g++ V=1"
cd ../../../../..

echo "6. Building libunwind"
build_component "vendor/nim-libbacktrace" "make install/usr/lib/libunwind.a" "libunwind"
echo "6. Building libnatpmp"
cd ./vendor/nim-nat-traversal/vendor/libnatpmp-upstream
execute_command "./build.bat"
execute_command "mv natpmp.a libnatpmp.a"
cd ../../../../

echo "7. Building wakunode2"
execute_command "make wakunode2 V=1 NIMFLAGS="-d:disableMarchNative -d:postgres -d:chronicles_colors:none" "
execute_command "make wakunode2 LOG_LEVEL=DEBUG V=1 -j8"

echo "Windows setup completed successfully!"
Loading