Skip to content

Add native Portduino malloc shim#10677

Open
h3lix1 wants to merge 8 commits into
meshtastic:developfrom
h3lix1:codex/native-portduino-malloc-shim
Open

Add native Portduino malloc shim#10677
h3lix1 wants to merge 8 commits into
meshtastic:developfrom
h3lix1:codex/native-portduino-malloc-shim

Conversation

@h3lix1

@h3lix1 h3lix1 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Add Darwin malloc.h Shim For Portduino

Branch: codex/native-portduino-malloc-shim

Target: meshtastic/firmware:develop

Why

Some native macOS build paths encounter code that includes <malloc.h>, which is a Linux header name. On Darwin, the equivalent allocator declarations live in <malloc/malloc.h>, and memalign() is not provided directly.

What

This adds a small Portduino-local compatibility header:

  • On macOS, include <malloc/malloc.h> and <stdlib.h>.
  • Provide memalign() through posix_memalign().
  • On non-Apple platforms, defer to the next real <malloc.h> with include_next.

The file is scoped to variants/native/portduino, so firmware targets and Linux native builds keep their existing behavior.

How

flowchart LR
    LGFX["Code includes <malloc.h>"] --> Shim["variants/native/portduino/malloc.h"]
    Shim --> Apple{"__APPLE__?"}
    Apple -->|yes| Darwin["malloc/malloc.h + posix_memalign"]
    Apple -->|no| Native["include_next <malloc.h>"]
Loading

Validation

  • trunk fmt variants/native/portduino/malloc.h
  • ~/.platformio/penv/bin/platformio run -e native-macos

The native build progressed past the original <malloc.h> failure.

Test Notes

No unit test is needed for this header shim. The useful check is a macOS native build in an environment with the documented native prerequisites installed.

@github-actions github-actions Bot added needs-review Needs human review hardware-support Hardware related: new devices or modules, problems specific to hardware labels Jun 10, 2026
@vidplace7 vidplace7 requested a review from thebentern June 10, 2026 11:52
@h3lix1 h3lix1 marked this pull request as ready for review June 10, 2026 17:53
@thebentern

Copy link
Copy Markdown
Contributor

@h3lix1 looks good. You still have it in draft for a reason?

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Try this PR in the Web Flasher

Flash this PR in the Web Flasher

firmware commit boards expires

Warning

This is an automated, unreviewed CI test build. Back up your device configuration
before flashing, and only flash devices you are able to recover.

Supported boards built by this PR (21)
Device Board Platform
Crowpanel Adv 3.5 TFT elecrow-adv-35-tft esp32-s3
Heltec HT62 heltec-ht62-esp32c3-sx1262 esp32-c3
Heltec Mesh Node 096 heltec-mesh-node-t096 nrf52840
Heltec Mesh Node T1 heltec-mesh-node-t1 nrf52840
Heltec Mesh Node T114 heltec-mesh-node-t114 nrf52840
Heltec V3 heltec-v3 esp32-s3
Raspberry Pi Pico pico rp2040
Raspberry Pi Pico W picow rp2040
RAK WisBlock 11200 rak11200 esp32
RAK WisBlock 11310 rak11310 rp2040
RAK3312 rak3312 esp32-s3
RAK WisBlock 4631 rak4631 nrf52840
Seeed Xiao NRF52840 Kit seeed_xiao_nrf52840_kit nrf52840
Seeed Xiao ESP32-S3 seeed-xiao-s3 esp32-s3
Station G2 station-g2 esp32-s3
Station G3 station-g3 esp32-s3
LILYGO T-Deck t-deck-tft esp32-s3
LILYGO T-Echo t-echo nrf52840
LILYGO T-Echo Plus t-echo-plus nrf52840
LilyGo T3-C6 tlora-c6 esp32-c6
Seeed SenseCAP T1000-E tracker-t1000-e nrf52840

Build artifacts expire on 2026-07-10. Updated for e513d80.

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Firmware Size Report

22 targets | vs develop: 22 decreased, net -12,412 (-12.1 KB)

Target Size vs develop
heltec-v4 2,255,360 📉 -848
rak3312 2,241,616 📉 -848
seeed-xiao-s3 2,245,600 📉 -832
t-eth-elite 2,461,200 📉 -832
heltec-v3 2,234,848 📉 -816
Show 17 more target(s)
Target Size vs develop
t-deck-tft 3,781,216 📉 -816
station-g2 2,246,160 📉 -768
station-g3 2,236,576 📉 -768
rak11200 1,830,464 📉 -752
picow 1,220,192 📉 -668
pico 759,928 📉 -664
rak11310 782,520 📉 -664
seeed_xiao_rp2040 758,144 📉 -664
pico2w 1,196,796 📉 -580
pico2 747,920 📉 -552
seeed_xiao_rp2350 746,072 📉 -552
elecrow-adv-35-tft 3,387,920 📉 -208
heltec-vision-master-e213-inkhud 2,195,392 📉 -176
wio-e5 232,564 📉 -112
rak3172 180,200 📉 -100
heltec-ht62-esp32c3-sx1262 2,106,880 📉 -96
tlora-c6 2,340,784 📉 -96

Updated for be211ba

@thebentern thebentern requested a review from Copilot June 11, 2026 17:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a Portduino-local malloc.h compatibility shim so native macOS (Darwin) builds can compile code that includes the Linux header name <malloc.h>, by redirecting to Darwin’s <malloc/malloc.h> and providing a memalign() implementation.

Changes:

  • Introduces variants/native/portduino/malloc.h to satisfy <malloc.h> includes in native Portduino builds.
  • On __APPLE__, includes <malloc/malloc.h>/<stdlib.h> and implements memalign() via posix_memalign().
  • On non-Apple platforms, defers to the real system <malloc.h> via #include_next.

Comment thread variants/native/portduino/malloc.h
h3lix1 and others added 2 commits June 11, 2026 23:07
Honestly I don't think it matters that much, but if it makes copilot happy, return ret if something weird happens.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@h3lix1

h3lix1 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

@thebentern will need a re-approval after applying the thing copilot recommended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hardware-support Hardware related: new devices or modules, problems specific to hardware needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants