Skip to content

Support hosted builds against Arduino-Emulator#420

Open
MitchBradley wants to merge 7 commits intoESP32Async:mainfrom
MitchBradley:HOSTmacro
Open

Support hosted builds against Arduino-Emulator#420
MitchBradley wants to merge 7 commits intoESP32Async:mainfrom
MitchBradley:HOSTmacro

Conversation

@MitchBradley
Copy link
Copy Markdown

This partially supersedes #416 , addressing only the topic of compatibility with Arduino-Emulator, without the emptyString part (already addressed) and without the on-close state machine fixes (to be addressed in a separate PR).

  • Factors the locking into one place
  • Adds "|| defined(HOST)" as needed elsewhere
  • Adds "override" in a few places where it was missing

* Factors the locking into one place
* Adds "|| defined(HOST)" as needed elsewhere
* Adds "override" in a few places where it was missing
Copilot AI review requested due to automatic review settings April 4, 2026 21:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves hosted/POSIX build compatibility (Arduino-Emulator) by expanding HOST platform guards, centralizing locking primitives, and tightening virtual overrides across the async webserver components.

Changes:

  • Add HOST to platform-specific include/behavior guards (WiFi, MD5, String clearing paths, TCP backends).
  • Factor ESP32-style locking into shared macros and apply them consistently in WebSocket and SSE (EventSource) code paths.
  • Add missing override specifiers for response implementations.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/WebServer.cpp Include WiFi.h under HOST to support hosted builds.
src/WebRequest.cpp Treat HOST like certain embedded cores for _temp clearing behavior.
src/WebAuthentication.cpp Add missing include and extend MD5 implementation selection to HOST.
src/ESPAsyncWebServer.h Guard lwIP include for HOST; introduce shared locking macros; define __unused if missing.
src/AsyncWebSocket.h Add HOST platform section; switch mutex members to shared locking macro; add overrides.
src/AsyncWebSocket.cpp Replace ESP32-only mutex usage with shared lock macros; add hosted SHA1 backport include.
src/AsyncWebServerLogging.h Disable framework logging macros for HOST.
src/AsyncEventSource.h Add HOST to AsyncTCP include path; switch mutex members to shared locking macro; add overrides.
src/AsyncEventSource.cpp Replace ESP32-only mutex usage with shared lock macros for queue/client-list protection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +39
#define async_ws_log_e(format, ...)
#define async_ws_log_w(format, ...)
#define async_ws_log_i(format, ...)
#define async_ws_log_d(format, ...)
#define async_ws_log_v(format, ...)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@MitchBradley is it normal to not implement them ? Cannot even be similar to what is done for 8266 ? All logs will be muted... Is that expected ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I fixed it. Note that the other versions that use Serial.printf() probably are missing newlines, possibly causing run-on lines and perhaps output delays depending on buffering.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indeed! For the RPI use cases right ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I will raise a fix PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PR raised: #421

Comment on lines +57 to +59
#if !defined(ASYNCWEBSERVER_USE_MUTEX)
#define ASYNCWEBSERVER_USE_MUTEX defined(ESP32) || defined(HOST)
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#if !defined(ASYNCWEBSERVER_USE_MUTEX)
#define ASYNCWEBSERVER_USE_MUTEX defined(ESP32) || defined(HOST)
#endif
#if !defined(ASYNCWEBSERVER_USE_MUTEX)
#if defined(ESP32) || defined(HOST)
#define ASYNCWEBSERVER_USE_MUTEX 1
#else
#define ASYNCWEBSERVER_USE_MUTEX 0
#endif
#endif

I would prefer that in order to be able to document a consistant behavior: ASYNCWEBSERVER_USE_MUTEX can be either 1 or 0.


#ifndef __unused
#define __unused __attribute__((unused))
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I placed a comment previously about that but it got lost I think.

This can define __unused globally to any use code that includes our header. Maybe that's not what the user expects. And definitely it is at risk that he depends in his code on a macro definition that comes from a library and is internal to this library.

I would rather have it defined as #define __asyncws_unused __attribute__((unused))

Or surrounded with #ifdef HOST to scope this definition to 1 platform only, but that does not remove the issue.

@mathieucarbou
Copy link
Copy Markdown
Member

@MitchBradley : thank you for your last updates :-) I have 2 more comments left.

I will first merge #421, then you will be able to rebase this PR with the comments fixed and it will be ready to be merged.

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.

4 participants