diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ddf904ef..67a29fa31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,12 +89,15 @@ jobs: path: | nimbledeps/ nimble.paths - key: ${{ runner.os }}-nimbledeps-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} + key: ${{ runner.os }}-nimbledeps-v2-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | - nimble setup --localdeps -y + # nim's source tree checksums differently across platforms, so its + # locked checksum is unreliable. --useSystemNim uses the CI nim and + # skips that check, while still verifying every other locked dep. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps make rebuild-bearssl-nimbledeps touch nimbledeps/.nimble-setup @@ -142,12 +145,15 @@ jobs: path: | nimbledeps/ nimble.paths - key: ${{ runner.os }}-nimbledeps-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} + key: ${{ runner.os }}-nimbledeps-v2-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | - nimble setup --localdeps -y + # nim's source tree checksums differently across platforms, so its + # locked checksum is unreliable. --useSystemNim uses the CI nim and + # skips that check, while still verifying every other locked dep. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps make rebuild-bearssl-nimbledeps touch nimbledeps/.nimble-setup @@ -207,12 +213,15 @@ jobs: path: | nimbledeps/ nimble.paths - key: ${{ runner.os }}-nimbledeps-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} + key: ${{ runner.os }}-nimbledeps-v2-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | - nimble setup --localdeps -y + # nim's source tree checksums differently across platforms, so its + # locked checksum is unreliable. --useSystemNim uses the CI nim and + # skips that check, while still verifying every other locked dep. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps make rebuild-bearssl-nimbledeps touch nimbledeps/.nimble-setup diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml index 0ff427d87..b2066438b 100644 --- a/.github/workflows/container-image.yml +++ b/.github/workflows/container-image.yml @@ -15,6 +15,10 @@ env: NPROC: 2 MAKEFLAGS: "-j${NPROC}" NIMFLAGS: "--parallelBuild:${NPROC}" + # waku.nimble reads compile flags from NIM_PARAMS, not NIMFLAGS. Without + # -d:disableMarchNative here, config.nims applies -march=native and + # secp256k1 fails to compile. + NIM_PARAMS: "-d:disableMarchNative" NIM_VERSION: '2.2.4' NIMBLE_VERSION: '0.22.3' diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 50f1602cd..4d955de23 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -24,6 +24,16 @@ jobs: MSYSTEM: MINGW64 steps: + - name: Configure Git to keep LF line endings + # Windows Git defaults to core.autocrlf=true. The LF→CRLF conversion + # changes the SHA1 of nimble's cloned deps, so they no longer match + # nimble.lock and nimble re-downloads them on every run (hanging the + # job). Disable autocrlf so clones match the Linux-computed checksums. + shell: pwsh + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - name: Checkout code uses: actions/checkout@v4 @@ -52,6 +62,14 @@ jobs: mingw-w64-x86_64-clang mingw-w64-x86_64-nasm + - name: Configure Git in MSYS2 to keep LF line endings + # The step above only configures Git for Windows. nimble clones its deps + # from the MSYS2 shell, whose git reads a separate global config, so the + # same setting must be repeated here. + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - name: Manually install nasm run: | bash scripts/install_nasm_in_windows.sh @@ -80,19 +98,16 @@ jobs: cd /tmp && nimble install "nimble@${{ env.NIMBLE_VERSION }}" -y echo "$HOME/.nimble/bin" >> $GITHUB_PATH - - name: Patch nimble.lock for Windows nim checksum - # nimble.exe uses Windows Git (core.autocrlf=true by default), which converts LF→CRLF - # on checkout. This changes the SHA1 of the nim package source tree relative to the - # Linux-computed checksum stored in nimble.lock. Patch the lock file with the - # Windows-computed checksum before nimble reads it. - run: | - sed -i 's/68bb85cbfb1832ce4db43943911b046c3af3caab/a092a045d3a427d127a5334a6e59c76faff54686/g' nimble.lock - - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$HOME/.nimble/bin:$PATH" - nimble setup --localdeps -y + # nim's source tree checks out differently per platform (its own + # .gitattributes forces line endings), so its locked checksum never + # matches on Windows — even with autocrlf disabled. --useSystemNim + # uses the CI-installed nim and skips that check, while still + # verifying every other locked dependency. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps CC=gcc make rebuild-bearssl-nimbledeps CC=gcc touch nimbledeps/.nimble-setup diff --git a/Makefile b/Makefile index ea1bf66f0..344743c86 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,9 @@ export PATH := $(HOME)/.nimble/bin:$(PATH) # NIM binary location NIM_BINARY := $(shell which nim 2>/dev/null) NPH := $(HOME)/.nimble/bin/nph -NIMBLE := $(HOME)/.nimble/bin/nimble +# Resolve nimble via PATH (Windows has no $(HOME)/.nimble/bin); --useSystemNim +# reuses the nim on PATH so nimble never re-clones the locked nim. +NIMBLE := nimble --useSystemNim NIMBLEDEPS_STAMP := nimbledeps/.nimble-setup # Compilation parameters @@ -204,7 +206,7 @@ clean: | clean-librln testcommon: | build-deps build echo -e $(BUILD_MSG) "build/$@" && \ - nimble testcommon + $(NIMBLE) testcommon ########## ## Waku ## @@ -213,47 +215,54 @@ testcommon: | build-deps build testwaku: | build-deps build rln-deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble test + $(NIMBLE) test +# Windows: build with nim directly — `nimble ` re-clones git deps every +# build and they intermittently hang on the MSYS2 runner. Flags mirror waku.nimble. wakunode2: | build-deps build deps librln +ifeq ($(detected_OS),Windows) echo -e $(BUILD_MSG) "build/$@" && \ - nimble wakunode2 + nim c --out:build/wakunode2 --mm:refc --cpu:amd64 $(NIM_PARAMS) -d:chronicles_log_level=TRACE apps/wakunode2/wakunode2.nim +else + echo -e $(BUILD_MSG) "build/$@" && \ + $(NIMBLE) wakunode2 +endif benchmarks: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble benchmarks + $(NIMBLE) benchmarks testwakunode2: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble testwakunode2 + $(NIMBLE) testwakunode2 example2: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble example2 + $(NIMBLE) example2 chat2: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble chat2 + $(NIMBLE) chat2 chat2mix: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble chat2mix + $(NIMBLE) chat2mix rln-db-inspector: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble rln_db_inspector + $(NIMBLE) rln_db_inspector chat2bridge: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble chat2bridge + $(NIMBLE) chat2bridge liteprotocoltester: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble liteprotocoltester + $(NIMBLE) liteprotocoltester lightpushwithmix: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble lightpushwithmix + $(NIMBLE) lightpushwithmix api_example: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ @@ -261,12 +270,12 @@ api_example: | build-deps build deps librln build/%: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$*" && \ - nimble buildone $* + $(NIMBLE) buildone $* compile-test: | build-deps build deps librln echo -e $(BUILD_MSG) "$(TEST_FILE)" "\"$(TEST_NAME)\"" && \ - nimble buildTest $(TEST_FILE) && \ - nimble execTest $(TEST_FILE) "\"$(TEST_NAME)\"" + $(NIMBLE) buildTest $(TEST_FILE) && \ + $(NIMBLE) execTest $(TEST_FILE) "\"$(TEST_NAME)\"" ################ ## Waku tools ## @@ -277,11 +286,11 @@ tools: networkmonitor wakucanary wakucanary: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble wakucanary + $(NIMBLE) wakucanary networkmonitor: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble networkmonitor + $(NIMBLE) networkmonitor ############ ## Format ## @@ -327,7 +336,7 @@ clean: docs: | build deps echo -e $(BUILD_MSG) "build/$@" && \ - nimble doc --run --index:on --project --out:.gh-pages waku/waku.nim waku.nims + $(NIMBLE) doc --run --index:on --project --out:.gh-pages waku/waku.nim waku.nims coverage: echo -e $(BUILD_MSG) "build/$@" && \ @@ -423,11 +432,16 @@ else ifeq ($(detected_OS),Linux) BUILD_COMMAND := $(BUILD_COMMAND)Linux endif +# Windows: build with nim directly (see wakunode2). Flags mirror waku.nimble. libwaku: | build-deps librln - nimble --verbose libwaku$(BUILD_COMMAND) waku.nimble +ifeq ($(detected_OS),Windows) + nim c --out:build/libwaku.dll --threads:on --app:lib --opt:speed --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:off -d:discv5_protocol_id=d5waku --cpu:amd64 $(NIM_PARAMS) library/libwaku.nim +else + $(NIMBLE) --verbose libwaku$(BUILD_COMMAND) waku.nimble +endif liblogosdelivery: | build-deps librln - nimble --verbose liblogosdelivery$(BUILD_COMMAND) waku.nimble + $(NIMBLE) --verbose liblogosdelivery$(BUILD_COMMAND) waku.nimble logosdelivery_example: | build liblogosdelivery @echo -e $(BUILD_MSG) "build/$@" @@ -502,7 +516,7 @@ endif build-libwaku-for-android-arch: ifneq ($(findstring /nix/store,$(LIBRLN_FILE)),) mkdir -p $(CURDIR)/build/android/$(ABIDIR)/ - CPU=$(CPU) ABIDIR=$(ABIDIR) ANDROID_ARCH=$(ANDROID_ARCH) ANDROID_COMPILER=$(ANDROID_COMPILER) ANDROID_TOOLCHAIN_DIR=$(ANDROID_TOOLCHAIN_DIR) nimble libWakuAndroid + CPU=$(CPU) ABIDIR=$(ABIDIR) ANDROID_ARCH=$(ANDROID_ARCH) ANDROID_COMPILER=$(ANDROID_COMPILER) ANDROID_TOOLCHAIN_DIR=$(ANDROID_TOOLCHAIN_DIR) $(NIMBLE) libWakuAndroid else ./scripts/build_rln_android.sh $(CURDIR)/build $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(CROSS_TARGET) $(ABIDIR) endif @@ -559,7 +573,7 @@ else endif build-libwaku-for-ios-arch: - IOS_SDK=$(IOS_SDK) IOS_ARCH=$(IOS_ARCH) IOS_SDK_PATH=$(IOS_SDK_PATH) nimble libWakuIOS + IOS_SDK=$(IOS_SDK) IOS_ARCH=$(IOS_ARCH) IOS_SDK_PATH=$(IOS_SDK_PATH) $(NIMBLE) libWakuIOS libwaku-ios-device: IOS_ARCH=arm64 libwaku-ios-device: IOS_SDK=iphoneos diff --git a/waku.nimble b/waku.nimble index 4ed98917e..38548b5dc 100644 --- a/waku.nimble +++ b/waku.nimble @@ -59,6 +59,7 @@ requires "nim >= 2.2.4", "unittest2" # Packages not on nimble (use git URLs) + requires "https://github.com/logos-messaging/nim-ffi#v0.1.3" requires "https://github.com/logos-messaging/nim-sds.git#abdd40cc645f1b024c3ee99cced7e287c4e4c441"