Add ulfius webserver support to macos native target (#10366)
* Add ulfius webserver support to macos native target * fix: update PiWebServer docs for macOS and add explicit cstring include Agent-Logs-Url: https://github.com/meshtastic/firmware/sessions/3ce82582-23e0-4afe-b22f-b24f81721488 Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix: add --cflags to openssl@3 pkg-config and fix apt package name Agent-Logs-Url: https://github.com/meshtastic/firmware/sessions/1a6c59aa-4393-4134-8cee-61eeee0e9127 Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
GitHub
copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot Autofix powered by AI
parent
90744ee0b7
commit
55f40ecdfd
@@ -1,22 +1,34 @@
|
|||||||
/*
|
/*
|
||||||
Adds a WebServer and WebService callbacks to meshtastic as Linux Version. The WebServer & Webservices
|
Adds a WebServer and WebService callbacks to meshtastic via the Portduino/native target (Linux and
|
||||||
runs in a real linux thread beside the portdunio threading emulation. It replaces the complete ESP32
|
macOS). The WebServer & Webservices run in a real host thread beside the Portduino threading
|
||||||
Webserver libs including generation of SSL certifcicates, because the use ESP specific details in
|
emulation. It replaces the complete ESP32 Webserver libs including generation of SSL certificates,
|
||||||
the lib that can't be emulated.
|
because those libs use ESP-specific details that can't be emulated.
|
||||||
|
|
||||||
The WebServices adapt to the two major phoneapi functions "handleAPIv1FromRadio,handleAPIv1ToRadio"
|
The WebServices adapt to the two major phoneapi functions "handleAPIv1FromRadio,handleAPIv1ToRadio"
|
||||||
The WebServer just adds basaic support to deliver WebContent, so it can be used to
|
The WebServer just adds basic support to deliver WebContent, so it can be used to
|
||||||
deliver the WebGui definded by the WebClient Project.
|
deliver the WebGui defined by the WebClient Project.
|
||||||
|
|
||||||
Steps to get it running:
|
Steps to get it running:
|
||||||
1.) Add these Linux Libs to the compile and target machine:
|
|
||||||
|
Linux (apt):
|
||||||
|
1.) Add these libs to the compile and target machine:
|
||||||
|
|
||||||
sudo apt update && \
|
sudo apt update && \
|
||||||
apt -y install openssl libssl-dev libopenssl libsdl2-dev \
|
apt -y install openssl libssl-dev libsdl2-dev \
|
||||||
libulfius-dev liborcania-dev
|
libulfius-dev liborcania-dev
|
||||||
|
|
||||||
|
macOS (Homebrew):
|
||||||
|
1.) Install prerequisites via Homebrew:
|
||||||
|
|
||||||
|
brew install ulfius openssl@3
|
||||||
|
|
||||||
|
The PlatformIO env (native-macos) picks up compiler/linker flags via
|
||||||
|
`pkg-config`. In particular, OpenSSL needs `pkg-config --cflags --libs openssl@3`
|
||||||
|
so both the Homebrew include path and linker flags are provided; ulfius and its
|
||||||
|
dependencies (liborcania, libyder) are also resolved via `pkg-config`.
|
||||||
|
|
||||||
2.) Configure the root directory of the web Content in the config.yaml file.
|
2.) Configure the root directory of the web Content in the config.yaml file.
|
||||||
The followinng tags should be included and set at your needs
|
The following tags should be included and set at your needs
|
||||||
|
|
||||||
Example entry in the config.yaml
|
Example entry in the config.yaml
|
||||||
Webserver:
|
Webserver:
|
||||||
@@ -34,7 +46,10 @@ Author: Marc Philipp Hammermann
|
|||||||
mail: marchammermann@googlemail.com
|
mail: marchammermann@googlemail.com
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#ifdef PORTDUINO_LINUX_HARDWARE
|
// Mirrors the guard in PiWebServer.h — see comment there. macOS Homebrew
|
||||||
|
// provides ulfius + deps; Linux pulls them via apt. Either way, this
|
||||||
|
// translation unit only compiles when the headers are present.
|
||||||
|
#ifdef ARCH_PORTDUINO
|
||||||
#if __has_include(<ulfius.h>)
|
#if __has_include(<ulfius.h>)
|
||||||
#include "PiWebServer.h"
|
#include "PiWebServer.h"
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef PORTDUINO_LINUX_HARDWARE
|
// Portduino webserver is built whenever the ulfius headers are reachable,
|
||||||
|
// not only on Linux. macOS users can `brew install ulfius` to enable it;
|
||||||
|
// without ulfius the entire body is skipped and main.cpp's matching
|
||||||
|
// __has_include guard avoids referencing the type.
|
||||||
|
#ifdef ARCH_PORTDUINO
|
||||||
#if __has_include(<ulfius.h>)
|
#if __has_include(<ulfius.h>)
|
||||||
#include "PhoneAPI.h"
|
#include "PhoneAPI.h"
|
||||||
#include "ulfius-cfg.h"
|
#include "ulfius-cfg.h"
|
||||||
|
|||||||
@@ -33,6 +33,16 @@
|
|||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Used by getMacAddr()'s macOS fallback to read the en0 link-layer address.
|
||||||
|
// `getifaddrs()` is the BSD-portable way; `<net/if_dl.h>` provides the
|
||||||
|
// `sockaddr_dl` cast and the `LLADDR()` macro that points at the 6-byte MAC.
|
||||||
|
#include <cstring> // strcmp, memcpy
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <net/if_dl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "platform/portduino/USBHal.h"
|
#include "platform/portduino/USBHal.h"
|
||||||
|
|
||||||
portduino_config_struct portduino_config;
|
portduino_config_struct portduino_config;
|
||||||
@@ -156,9 +166,35 @@ void getMacAddr(uint8_t *dmac)
|
|||||||
dmac[3] = di.bdaddr.b[2];
|
dmac[3] = di.bdaddr.b[2];
|
||||||
dmac[4] = di.bdaddr.b[1];
|
dmac[4] = di.bdaddr.b[1];
|
||||||
dmac[5] = di.bdaddr.b[0];
|
dmac[5] = di.bdaddr.b[0];
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
// No BlueZ on macOS, but we can fall back to the host's primary
|
||||||
|
// network interface MAC. `en0` is Wi-Fi on every shipping Mac
|
||||||
|
// (Ethernet, when present, is en1 or higher), which gives the user
|
||||||
|
// the same kind of stable, host-derived identifier that the BlueZ
|
||||||
|
// path provides on Linux. If en0 isn't found or has no MAC, dmac is
|
||||||
|
// left untouched and the caller's "Blank MAC Address not allowed!"
|
||||||
|
// check will still fire — preserving existing behavior for users
|
||||||
|
// who deliberately rely on --hwid or YAML override.
|
||||||
|
struct ifaddrs *ifap = nullptr;
|
||||||
|
if (getifaddrs(&ifap) == 0) {
|
||||||
|
for (struct ifaddrs *p = ifap; p != nullptr; p = p->ifa_next) {
|
||||||
|
if (p->ifa_addr == nullptr || p->ifa_addr->sa_family != AF_LINK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (strcmp(p->ifa_name, "en0") != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto *sdl = reinterpret_cast<struct sockaddr_dl *>(p->ifa_addr);
|
||||||
|
if (sdl->sdl_alen == 6) {
|
||||||
|
memcpy(dmac, LLADDR(sdl), 6);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
freeifaddrs(ifap);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
// No BlueZ on non-Linux hosts (e.g. macOS). Leave dmac at its default;
|
// No platform-specific MAC source; leave dmac at its default. Caller
|
||||||
// the caller can override via the --hwid CLI flag or the YAML config.
|
// can override via the --hwid CLI flag or the YAML config.
|
||||||
(void)dmac;
|
(void)dmac;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ test_testing_command =
|
|||||||
;
|
;
|
||||||
; Prerequisites (Homebrew):
|
; Prerequisites (Homebrew):
|
||||||
; brew install platformio yaml-cpp libuv openssl@3 libusb argp-standalone pkg-config
|
; brew install platformio yaml-cpp libuv openssl@3 libusb argp-standalone pkg-config
|
||||||
|
; # Optional: enable the HTTP API (PiWebServer) on macOS:
|
||||||
|
; brew install ulfius
|
||||||
;
|
;
|
||||||
; The macOS-side patches now live upstream:
|
; The macOS-side patches now live upstream:
|
||||||
; * meshtastic/platform-native — `String.h`-shadow shim, `-Wno-enum-constexpr-conversion`,
|
; * meshtastic/platform-native — `String.h`-shadow shim, `-Wno-enum-constexpr-conversion`,
|
||||||
@@ -191,7 +193,16 @@ build_flags = ${portduino_base.build_flags_common}
|
|||||||
; style screen-driver hooks scattered through sensor sources.
|
; style screen-driver hooks scattered through sensor sources.
|
||||||
-DHAS_SCREEN=0
|
-DHAS_SCREEN=0
|
||||||
-DMESHTASTIC_EXCLUDE_SCREEN=1
|
-DMESHTASTIC_EXCLUDE_SCREEN=1
|
||||||
!pkg-config --libs openssl --silence-errors || :
|
; openssl@3 is the keg-only Homebrew formula; --cflags is required so the
|
||||||
|
; compiler finds <openssl/*.h> in the Homebrew prefix (not just the linker).
|
||||||
|
!pkg-config --cflags --libs openssl@3 --silence-errors || :
|
||||||
|
; PiWebServer (src/mesh/raspihttp/PiWebServer.cpp) auto-engages when ulfius
|
||||||
|
; headers are reachable via `#if __has_include(<ulfius.h>)`. The `|| :`
|
||||||
|
; tail keeps the build green when the user hasn't run `brew install ulfius`
|
||||||
|
; — they just don't get the HTTP API in that case.
|
||||||
|
!pkg-config --cflags --libs libulfius --silence-errors || :
|
||||||
|
!pkg-config --cflags --libs liborcania --silence-errors || :
|
||||||
|
!pkg-config --cflags --libs libyder --silence-errors || :
|
||||||
; src/input/Linux*.{cpp,h} drive evdev (`<linux/input.h>`) which doesn't exist
|
; src/input/Linux*.{cpp,h} drive evdev (`<linux/input.h>`) which doesn't exist
|
||||||
; on macOS. graphics/Panel_sdl.* and graphics/TFTDisplay.cpp pull LovyanGFX
|
; on macOS. graphics/Panel_sdl.* and graphics/TFTDisplay.cpp pull LovyanGFX
|
||||||
; (which we lib_ignore on macOS for the <malloc.h> issue). Neither is needed
|
; (which we lib_ignore on macOS for the <malloc.h> issue). Neither is needed
|
||||||
@@ -206,3 +217,28 @@ build_src_filter = ${native_base.build_src_filter}
|
|||||||
lib_ignore =
|
lib_ignore =
|
||||||
${portduino_base.lib_ignore}
|
${portduino_base.lib_ignore}
|
||||||
LovyanGFX
|
LovyanGFX
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Same as [env:native-macos] but built with AddressSanitizer for catching
|
||||||
|
; use-after-free, leaks, and OOB access during local development. Headless
|
||||||
|
; (no SDL/X11/libinput) so it stays cheap to build. Mirrors the shape of
|
||||||
|
; [env:native-tft-debug] but without the TFT/X11 dependencies.
|
||||||
|
;
|
||||||
|
; pio run -e native-macos-debug
|
||||||
|
; .pio/build/native-macos-debug/meshtasticd -s
|
||||||
|
;
|
||||||
|
; ASan runtime tuning (set in the shell before launching):
|
||||||
|
; ASAN_OPTIONS=detect_leaks=1:halt_on_error=0:abort_on_error=1
|
||||||
|
; MallocStackLogging=1 # macOS: nicer stack traces in malloc reports
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
[env:native-macos-debug]
|
||||||
|
extends = native_base
|
||||||
|
build_type = debug
|
||||||
|
build_unflags = ${env:native-macos.build_unflags}
|
||||||
|
build_flags = ${env:native-macos.build_flags}
|
||||||
|
-O0
|
||||||
|
-g
|
||||||
|
-fsanitize=address
|
||||||
|
-fno-omit-frame-pointer
|
||||||
|
build_src_filter = ${env:native-macos.build_src_filter}
|
||||||
|
lib_ignore = ${env:native-macos.lib_ignore}
|
||||||
|
|||||||
Reference in New Issue
Block a user