Skip to content

Conversation

caiohamamura
Copy link

@caiohamamura caiohamamura commented Sep 2, 2025

  • This PR is for the dev branch rather than for the release branch.
  • This PR is compliant with the other contributing guidelines as well.
  • I have thoroughly tested my contribution.
  • The code changes are reflected in the documentation at docs/*.

Summary

This PR improves Windows compilation support for NodeMCU-Firmware by addressing missing headers, inconsistent function names, and toolchain differences between Windows and Linux.

Changes

Makefile:

  • Correctly handles Windows vs. Linux toolchain download and expansion.
  • Allows implicit functions.
  • Defines WIN32.
  • Defines stricmp as a macro for strcasecmp.

cc.h:

  • Adds a check to avoid redefining BYTE_ORDER when already defined in Windows toolchain.

socket.h:

  • Adds safeguard to avoid redefining timeval if already included.

locale support:

  • Defines __locale_c_type_ptr function since locale/ctype support is missing in Windows toolchain.

Headers

  • Adds missing headers required by the Windows toolchain.

Building in windows

These fixes allow building NodeMCU-Firmware with the official windows toolchains provided by espressif: https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/windows-setup.html.

Follow these steps:

  1. Download and extract the "Windows all-in-one toolchain & MSYS2": https://dl.espressif.com/dl/esp32_win32_msys2_environment_and_toolchain-20181001.zip
  2. Open the mingw32 version (mingw32.exe)
  3. Clone this fork: git clone https://github.com/caiohamamura/nodemcu-firmware --branch=windows_compilation --depth=1 --recurse-submodules --shallow-submodules
  4. Change to directory and run make: cd nodemcu-firmware && make

Motivation

Besides allowing other developers to use Windows for developing and eventually contributing to this repository, I am writing a VSCode/VSCodium extension for developing for nodemcu, allowing to manage the firmware compilation, selection of modules, flashing and compiling/loading lua code. So I need this repository to be compile ready cross-platform wise for the extension to also work cross-platform.

@caiohamamura
Copy link
Author

In addition this will also allow to more throughly test and CI with a windows github action relying in MSYS2.

@caiohamamura caiohamamura force-pushed the windows_compilation branch 3 times, most recently from 5d021d2 to ec95c38 Compare September 3, 2025 00:59
@caiohamamura
Copy link
Author

caiohamamura commented Sep 3, 2025

Now I added compilation and tests support for windows using the official toolchainhttps://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/windows-setup.html.

Note: question?

Would it be better if we provided a github release for the windows toolchain just in case espressif stop giving support?

toolchain: $(TOOLCHAIN_ROOT)/bin $(ESPTOOL)

$(TOOLCHAIN_ROOT)/bin: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz
$(TOOLCHAIN_ROOT)/bin: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).$(TOOLCHAIN_EXT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a debugging leftover

@caiohamamura caiohamamura force-pushed the windows_compilation branch 4 times, most recently from 9c02252 to 5155aa8 Compare September 3, 2025 04:21
@marcelstoer
Copy link
Member

marcelstoer commented Sep 3, 2025

Would it be better if we provided a github release for the windows toolchain just in case espressif stop giving support?

I support that idea. IIRC there are other tools for which (at some point but not anymore?) we kept or keep local copies.

@caiohamamura
Copy link
Author

caiohamamura commented Sep 3, 2025

@marcelstoer
Copy link
Member

IIRC there are other tools for which (at some point but not anymore?)...

I just remembered: https://github.com/nodemcu/espressif-sdk-archive

As those two Win tools are ~750MB I suggest we add them both to our espressif-sdk-archive project.

@caiohamamura
Copy link
Author

Will you create the releases there? Then if you could provide me the links to update this PR.

@marcelstoer
Copy link
Member

marcelstoer commented Sep 3, 2025

GitHub doesn't allow artifacts >100MB in repositories without Git LFS. Hence, that repository now uses LFS to track those two files. Their raw location is as follows:

However, the workflow checkout action or similar allow you reference their repository location without hard-coding the raw URL.

@caiohamamura
Copy link
Author

GitHub doesn't allow artifacts >100MB in repositories without Git LFS. Hence, that repository now uses LFS to track those two files. Their raw location is as follows:

However, the workflow checkout action or similar allow you reference their repository location without hard-coding the raw URL.

Done, I have updated the urls in both the Makefile and the github action.

…tion names in windows.

 - Makefile: allow implicit functions warnings, define stricmp as macro for strcasecmp, define WIN32.
 - cc.h: check if BYTE_ORDER is not already defined (which is in windows toolchain)
 - socket.h: Check if timeval.h hasn't already been included before defining the timeval struct
 - Define __locale_c_type_ptr function, locale/ctype support is not enabled in windows toolchain.
 - Previously lwIP_ASSERT expanded to `return;`, which breaks when used inside functions with non-void return types (causing -Werror failures): this patch updates the macro to allow specifying an appropriate return value.
 - nodemcu_mdns.c: `send_packet`, also had empty returns.

While these could be bypassed with `-Wno-error=return-type`, explicitly returning a value is safer and more correct.
- Project Makefile: Fallback $OS in linux to $(UNAME_S) which uses `uname -s`  in linux, since $(OS) is specific to windows.
- Luac Cross: add .exe when compiling for windows.
@caiohamamura
Copy link
Author

Rebase done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants