Skip to content

Support for Windows through MSYS2 - #57

Merged
thiagoralves merged 13 commits into
mainfrom
development
Dec 31, 2025
Merged

Support for Windows through MSYS2#57
thiagoralves merged 13 commits into
mainfrom
development

Conversation

@thiagoralves

Copy link
Copy Markdown
Contributor

This pull request introduces comprehensive support for building and running the OpenPLC Runtime on Windows via MSYS2/Cygwin environments. The changes include a new GitHub Actions workflow for building a Windows installer, numerous portability fixes across the codebase, and adjustments to installation and runtime scripts to handle platform-specific differences. The most important changes are grouped below by theme.

Windows/MSYS2 Platform Support:

  • Added a new .github/workflows/windows-installer.yml GitHub Actions workflow to automate building a Windows installer using MSYS2 and Inno Setup, including dependency installation, payload preparation, and artifact upload.
  • Updated install.sh and start_openplc.sh scripts to detect MSYS2/Cygwin environments, skip root checks where not applicable, install dependencies using pacman, and adjust runtime directory creation for Windows. [1] [2] [3] [4] [5] [6]

Portability and Platform Conditionals in C Code:

  • Modified core/src/CMakeLists.txt to disable treating warnings as errors on Cygwin/MSYS2 due to header conflicts, improving build reliability on these platforms.
  • Added preprocessor checks and conditional compilation throughout the C source (e.g., plugin_driver.c, python_plugin_bridge.h, scan_cycle_manager.c, utils.c) to handle MSYS2/Cygwin-specific issues such as missing real-time features, header redefinition warnings, and mutex attribute differences. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Python Webserver Robustness on Windows:

  • Patched the SSL socket recv method in webserver/app.py to handle EAGAIN/EWOULDBLOCK errors on non-Linux platforms (such as MSYS2), preventing "Resource temporarily unavailable" issues. [1] [2]
  • Made psutil an optional import in webserver/runtimemanager.py, logging a message if unavailable, to support platforms where psutil cannot be installed.

These changes collectively enable seamless building, installation, and running of OpenPLC Runtime on Windows environments, while maintaining compatibility and feature parity with Linux systems.

devin-ai-integration Bot and others added 13 commits December 27, 2025 18:09
- Add Inno Setup script (setup.iss) for creating Windows installer
- Add MSYS2 provisioning script for CI builds
- Add Windows launcher batch file (StartOpenPLC.bat)
- Add GitHub Actions workflow for automated installer builds
- Workflow triggers on version tags and manual dispatch
- Installer bundles pre-provisioned MSYS2 with GCC, Python, and dependencies
- Per-user installation (no admin rights required)
- Creates Start Menu shortcuts automatically

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Add is_msys2() function to detect MSYS2/MinGW/Cygwin environments
- Skip root check on MSYS2 (not required/meaningful on Windows)
- Add install_deps_msys2() function for pacman-based package installation
- Handle runtime directory creation appropriately for MSYS2
- Update check_installation() message to not suggest sudo on MSYS2

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Add environment marker to requirements.txt to skip psutil on cygwin platforms
- Add conditional import with HAS_PSUTIL flag in runtimemanager.py
- Gracefully degrade when psutil is not available:
  - find_running_process() returns None (cannot detect existing processes)
  - is_runtime_alive() and stop() handle subprocess.Popen only
- Log informational message when psutil is not available

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Add conditional compilation for Linux-specific real-time features:
  - mlockall/MCL_CURRENT/MCL_FUTURE (memory locking)
  - sched_setscheduler/SCHED_FIFO (real-time scheduling)
  - clock_nanosleep with TIMER_ABSTIME (absolute time sleep)
- Use HAS_REALTIME_FEATURES macro to detect platform support
- Provide fallback implementations for MSYS2/Cygwin:
  - sleep_until() uses nanosleep with relative time calculation
  - set_realtime_priority() and lock_memory() log info message and return
- Add -Wno-error=cpp flag on Cygwin/MSYS2 to handle _POSIX_C_SOURCE
  redefinition warning from Python headers

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Use CMAKE_SYSTEM_NAME MATCHES instead of CYGWIN/MSYS variables
- Use -Wno-error to disable all warnings-as-errors on MSYS2/Cygwin
- The -Werror=format-security is still applied after -Wno-error

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Add OPENPLC_CLOCK macro to use CLOCK_MONOTONIC on MSYS2/Cygwin
  (CLOCK_MONOTONIC_RAW is Linux-specific)
- Use proper #ifdef blocks instead of CMake -Wno-error workaround
- Change CMake from -Wno-error to -Wno-cpp to only suppress the
  _POSIX_C_SOURCE redefinition warning from Python headers

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Wrap Python.h includes with GCC diagnostic push/pop to suppress
  the _POSIX_C_SOURCE redefinition warning on MSYS2/Cygwin
- Fix applied to python_plugin_bridge.h and plugin_driver.c
- Remove CMake -Wno-cpp workaround since the fix is now in the code
- This is more robust than CMake platform detection which was unreliable

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Use WIN32 AND UNIX detection which is more reliable than CMAKE_SYSTEM_NAME
- WIN32 AND UNIX is true on MSYS2/Cygwin but not on native Windows or Linux
- Keep GCC diagnostic pragmas in Python.h includes as additional safety
- The -Wno-error flag comes after -Werror to properly override it

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Wrap priority inheritance mutex code with conditional compilation
- Use __CYGWIN__ and __MSYS__ preprocessor definitions for detection
- On MSYS2/Cygwin, use a regular mutex without priority inheritance
- Priority inheritance is a Linux-specific feature not available on MSYS2

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- Patch ssl.SSLSocket.recv to handle EAGAIN/EWOULDBLOCK (errno 11) errors
- On non-Linux platforms, return empty bytes instead of raising exception
- This fixes 'Resource temporarily unavailable' error on MSYS2/Cygwin
- Same fix as applied in OpenPLC_v3 commit 3ac3252

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- GitHub Actions workflow now uses install.sh instead of manual dependency installation
- provision-msys2.sh now delegates to install.sh for consistent installation
- This ensures all MSYS2-specific fixes in install.sh are used during CI builds

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
…nstaller

Add Windows installer infrastructure with GitHub Actions workflow
@thiagoralves
thiagoralves merged commit 15b6827 into main Dec 31, 2025
2 checks passed
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.

1 participant