Skip to content

Add a flag to to use arduino header paths - fixes PIO builds#420

Merged
h2zero merged 1 commit intomasterfrom
header-flag
Mar 31, 2026
Merged

Add a flag to to use arduino header paths - fixes PIO builds#420
h2zero merged 1 commit intomasterfrom
header-flag

Conversation

@h2zero
Copy link
Copy Markdown
Owner

@h2zero h2zero commented Mar 31, 2026

Fixes #407

Summary by CodeRabbit

  • Refactor

    • Standardized compile-time header selection across build modes; no public API or runtime behavior changes.
  • Chores

    • Removed an obsolete build configuration option.
    • Minor formatting and indentation tidy-ups across multiple files.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

Arrr — replaced compile-time macro CONFIG_NIMBLE_CPP_IDF with USING_NIMBLE_ARDUINO_HEADERS across includes and a few preprocessor guards; no public API signatures or runtime control-flow semantics were changed. (≤50 words)

Changes

Cohort / File(s) Summary
Core GAP includes
src/NimBLEDevice.h, src/NimBLEClient.h, src/NimBLEConnInfo.h, src/NimBLEExtAdvertising.h, src/NimBLEScan.h, src/NimBLEServer.h, src/NimBLEAdvertising.h, src/NimBLEL2CAPChannel.h, src/NimBLELocalValueAttribute.h, src/NimBLERemoteValueAttribute.h, src/NimBLEUUID.h
Replaced CONFIG_NIMBLE_CPP_IDF with USING_NIMBLE_ARDUINO_HEADERS to select between Arduino-packaged nimble/.../host/ble_gap.h and host/ble_gap.h.
Port / NPL / nimble_port includes
src/NimBLEClient.cpp, src/NimBLEScan.cpp, src/NimBLEStream.cpp, src/NimBLEStream.h, src/NimBLEAttValue.cpp, src/NimBLEAddress.h
Switched preprocessor guards to USING_NIMBLE_ARDUINO_HEADERS for nimble_npl / nimble_port include path selection.
GAP/GATT & adv headers
src/NimBLEAdvertising.cpp, src/NimBLEExtAdvertising.cpp, src/NimBLEServer.cpp, src/NimBLEAdvertisementData.cpp, src/NimBLEAdvertisedDevice.h
Updated include-path selection for service and advertising headers (e.g., ble_svc_gap.h, ble_hs_adv.h) to use USING_NIMBLE_ARDUINO_HEADERS; minor member reformatting in NimBLEAdvertisedDevice.
L2CAP / os_mbuf & related
src/NimBLEL2CAPChannel.h, src/NimBLEStream.cpp
Changed conditional includes for ble_l2cap.h and os/os_mbuf.h to use USING_NIMBLE_ARDUINO_HEADERS.
Logging / ESP-IDF guard
src/NimBLELog.h
Inverted/include guard: use #ifndef USING_NIMBLE_ARDUINO_HEADERS to gate ESP-IDF esp_log.h/console includes instead of CONFIG_NIMBLE_CPP_IDF.
Feature-gating / versioned guards
src/NimBLECharacteristic.cpp, src/NimBLEClient.cpp, src/NimBLEServer.cpp
Adjusted compile-time guards from CONFIG_NIMBLE_CPP_IDF to checks involving !defined(USING_NIMBLE_ARDUINO_HEADERS) for data-length and notify/indicate mapping logic.
Formatting-only changes
src/NimBLEAddress.h, src/NimBLEAdvertisedDevice.h, src/NimBLEUUID.h, src/NimBLEScan.cpp
Whitespace/indentation adjustments for a few conversion operators, member declarations, and argument alignment; no signature or behavioral changes.
Kconfig
Kconfig
Removed config NIMBLE_CPP_IDF option from Kconfig.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

Arrr, the macros be reefed and set anew,
Headers now point where Arduino winds blew.
No signatures keel-hauled, nor behavior torn,
Just include paths shifted with morn.
Hoist the build — may compilations brew! ⚓️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective: introducing a flag (USING_NIMBLE_ARDUINO_HEADERS) to conditionally select Arduino header paths, which directly addresses the PlatformIO/esp-idf build issue.
Linked Issues check ✅ Passed The changes systematically replace CONFIG_NIMBLE_CPP_IDF with USING_NIMBLE_ARDUINO_HEADERS across 26 files to fix header path selection for PlatformIO builds, directly addressing issue #407's core problem.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing header include paths via the new USING_NIMBLE_ARDUINO_HEADERS flag and removing the obsolete CONFIG_NIMBLE_CPP_IDF mechanism, with only minor whitespace adjustments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch header-flag

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/NimBLEExtAdvertising.cpp (1)

21-25: Arr, the cargo be mostly shipshape, but I spy a wee barnacle!

The header path logic be correct, matey. However, I notice the # endif on line 25 has inconsistent spacing compared to the #ifdef and #else above it. The preprocessor be tolerant of such things, but for a clean deck:

🧹 Minor style cleanup for consistent preprocessor indentation
 `#ifdef` USING_NIMBLE_ARDUINO_HEADERS
 #  include "nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h"
 `#else`
 #  include "services/gap/ble_svc_gap.h"
-# endif
+#endif
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NimBLEExtAdvertising.cpp` around lines 21 - 25, The preprocessor block
using `#ifdef` USING_NIMBLE_ARDUINO_HEADERS / `#else` is fine but the closing
directive is written as "# endif" with a space; change it to "#endif" to match
the style of the other directives and keep consistent indentation for the block
that includes ble_svc_gap.h (references: the `#ifdef`
USING_NIMBLE_ARDUINO_HEADERS, `#else`, and the closing `#endif`).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/NimBLEDevice.h`:
- Around line 32-35: The build never defines the macro
USING_NIMBLE_ARDUINO_HEADERS so all `#ifdef` USING_NIMBLE_ARDUINO_HEADERS include
branches (e.g., in src/NimBLEDevice.h) never trigger; add a compile definition
for this macro in the build system: update library.json to add a build.flags
entry (e.g., "-DUSING_NIMBLE_ARDUINO_HEADERS") for PlatformIO/Arduino builds,
update CMakeLists.txt to add target_compile_definitions or
add_compile_definitions when the Arduino framework is detected, and optionally
expose a Kconfig boolean (e.g., CONFIG_USING_NIMBLE_ARDUINO_HEADERS) that when
enabled adds the -D define so developers can toggle the Arduino header path
behavior.

---

Nitpick comments:
In `@src/NimBLEExtAdvertising.cpp`:
- Around line 21-25: The preprocessor block using `#ifdef`
USING_NIMBLE_ARDUINO_HEADERS / `#else` is fine but the closing directive is
written as "# endif" with a space; change it to "#endif" to match the style of
the other directives and keep consistent indentation for the block that includes
ble_svc_gap.h (references: the `#ifdef` USING_NIMBLE_ARDUINO_HEADERS, `#else`, and
the closing `#endif`).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8a3ecef6-3727-45a8-99b5-af06401696aa

📥 Commits

Reviewing files that changed from the base of the PR and between dd32365 and f7b55b8.

📒 Files selected for processing (27)
  • src/NimBLEAddress.h
  • src/NimBLEAdvertisedDevice.h
  • src/NimBLEAdvertisementData.cpp
  • src/NimBLEAdvertising.cpp
  • src/NimBLEAdvertising.h
  • src/NimBLEAttValue.cpp
  • src/NimBLECharacteristic.cpp
  • src/NimBLEClient.cpp
  • src/NimBLEClient.h
  • src/NimBLEConnInfo.h
  • src/NimBLEDevice.cpp
  • src/NimBLEDevice.h
  • src/NimBLEExtAdvertising.cpp
  • src/NimBLEExtAdvertising.h
  • src/NimBLEL2CAPChannel.cpp
  • src/NimBLEL2CAPChannel.h
  • src/NimBLELocalValueAttribute.h
  • src/NimBLELog.h
  • src/NimBLERemoteValueAttribute.h
  • src/NimBLEScan.cpp
  • src/NimBLEScan.h
  • src/NimBLEServer.cpp
  • src/NimBLEServer.h
  • src/NimBLEStream.cpp
  • src/NimBLEStream.h
  • src/NimBLEUUID.h
  • src/NimBLEUtils.cpp

Comment on lines +32 to +35
# ifdef USING_NIMBLE_ARDUINO_HEADERS
# include "nimble/nimble/host/include/host/ble_gap.h"
# else
# include <nimble/nimble/host/include/host/ble_gap.h>
# include "host/ble_gap.h"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Macro usage / definitions =="
rg -n --no-heading '\bUSING_NIMBLE_ARDUINO_HEADERS\b'

echo
echo "== Old vs new build-flag references =="
rg -n --no-heading 'CONFIG_NIMBLE_CPP_IDF|USING_NIMBLE_ARDUINO_HEADERS'

echo
echo "== Include gates for ble_gap.h after migration =="
rg -n --no-heading -C2 'ble_gap\.h|USING_NIMBLE_ARDUINO_HEADERS'

Repository: h2zero/esp-nimble-cpp

Length of output: 16255


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Search for macro definition in build config files ==="
echo
echo "Checking library.json for build flags:"
if [ -f library.json ]; then
    cat -n library.json | head -30
fi
echo
echo "Checking for CMakeLists.txt files:"
find . -name "CMakeLists.txt" -type f | head -5
echo
echo "Checking platformio.ini:"
if [ -f platformio.ini ]; then
    cat -n platformio.ini
fi
echo
echo "=== Searching for -DUSING_NIMBLE_ARDUINO_HEADERS ==="
rg -n 'USING_NIMBLE_ARDUINO_HEADERS' --type-list | grep -i config
rg -r '-DUSING_NIMBLE_ARDUINO_HEADERS' .
echo
echo "=== Check for Arduino framework integration ==="
fd -e 'h' -e 'hpp' -e 'cmake' | xargs rg -l 'Arduino\|ARDUINO' 2>/dev/null | head -5

Repository: h2zero/esp-nimble-cpp

Length of output: 1543


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Full library.json content ==="
wc -l library.json
cat library.json
echo
echo "=== CMakeLists.txt for macro definitions ==="
cat CMakeLists.txt
echo
echo "=== Search for USING_NIMBLE_ARDUINO_HEADERS definition ==="
rg -n 'define.*USING_NIMBLE_ARDUINO_HEADERS|add_compile_definitions.*USING_NIMBLE_ARDUINO_HEADERS|-DUSING_NIMBLE_ARDUINO_HEADERS'

Repository: h2zero/esp-nimble-cpp

Length of output: 3083


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Search for `#define` USING_NIMBLE_ARDUINO_HEADERS in any file ==="
rg -n '#define.*USING_NIMBLE_ARDUINO_HEADERS' --type-all

echo
echo "=== Check if it's conditionally defined in any header ==="
rg -n -A3 'ifdef.*ARDUINO|if defined.*ARDUINO' src/ | head -50

echo
echo "=== Search library.json in git history or PR changes ==="
git log --oneline -n 20 -- library.json 2>/dev/null || echo "No git history available"

echo
echo "=== Check if Arduino framework itself would define this macro ==="
echo "Searching for any references to Arduino framework macros or build system variables:"
rg -n 'ARDUINO|__PLATFORMIO__|ESP_PLATFORM' src/ | head -20

Repository: h2zero/esp-nimble-cpp

Length of output: 588


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Search for `#define` USING_NIMBLE_ARDUINO_HEADERS ==="
rg -n '#define USING_NIMBLE_ARDUINO_HEADERS'

echo
echo "=== Check if macro is conditionally set based on build environment ==="
rg -n -B5 -A5 'USING_NIMBLE_ARDUINO_HEADERS' src/ | grep -E '(`#define`|#if|Arduino|PLATFORMIO)' | head -40

echo
echo "=== Look for build configuration that sets this macro ==="
find . -name '*.cmake' -o -name '*.py' -o -name 'setup.py' | xargs rg -l 'USING_NIMBLE_ARDUINO_HEADERS' 2>/dev/null || echo "No cmake/python build files set this macro"

echo
echo "=== Check if this should come from Arduino ESP32 framework ==="
rg -n 'framework-arduinoespressif32|arduino-esp32' CMakeLists.txt

echo
echo "=== Search for build system or preprocessor integration ==="
fd -e 'idf_component.yml' -o -e 'build.gradle' -o -e 'platformio.ini'

Repository: h2zero/esp-nimble-cpp

Length of output: 120


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Check PR changes for library.json or build flag additions ==="
git diff HEAD~1 library.json 2>/dev/null || echo "No git diff available, checking if library.json was modified"

echo
echo "=== Look for any build flag or compile definition changes in this PR ==="
git show --stat 2>/dev/null | head -30

echo
echo "=== Verify if USING_NIMBLE_ARDUINO_HEADERS might come from Arduino core ==="
echo "Checking for Arduino framework detection patterns:"
rg -n 'ARDUINO\b' src/ | head -20

echo
echo "=== Check if macro should be set as a compiler flag in build system ==="
echo "Looking for similar macro patterns (CONFIG_*, USING_*, etc):"
rg -n '#ifdef.*CONFIG_|#ifdef.*USING_' src/ | head -20

echo
echo "=== Summary: Is USING_NIMBLE_ARDUINO_HEADERS actually defined? ==="
if rg -q 'USING_NIMBLE_ARDUINO_HEADERS' . && ! rg -q '#define USING_NIMBLE_ARDUINO_HEADERS'; then
    echo "MACRO USED: Yes (44+ locations)"
    echo "MACRO DEFINED: No"
    echo "RESULT: Macro is referenced but never defined in the repository"
fi

Repository: h2zero/esp-nimble-cpp

Length of output: 1956


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Read Kconfig file for USING_NIMBLE_ARDUINO_HEADERS ==="
cat Kconfig | head -100

echo
echo "=== Search for where macro is actually DEFINED/SET in CMakeLists ==="
rg -n -A5 -B5 'add_compile_definitions|idf_component_set_property|target_compile_definitions' CMakeLists.txt

echo
echo "=== Check idf_component.yml if it exists ==="
if [ -f idf_component.yml ]; then
    cat idf_component.yml
fi

echo
echo "=== Final check: Where is this macro defined in the build system? ==="
rg -n 'USING_NIMBLE_ARDUINO_HEADERS' CMakeLists.txt Kconfig 2>/dev/null || echo "Not found in CMakeLists or Kconfig"

Repository: h2zero/esp-nimble-cpp

Length of output: 3650


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Search entire Kconfig for USING_NIMBLE_ARDUINO_HEADERS ==="
rg -n 'USING_NIMBLE_ARDUINO_HEADERS' Kconfig

echo
echo "=== Get full CMakeLists.txt and check for compile definitions ==="
wc -l CMakeLists.txt
echo "---"
cat CMakeLists.txt

echo
echo "=== Check if Arduino framework sets this macro externally ==="
echo "Searching for any mechanism that might auto-define this:"
rg -n 'idf_component_register' CMakeLists.txt -A50 | grep -i 'compile\|flag\|define'

echo
echo "=== Final diagnosis: Is USING_NIMBLE_ARDUINO_HEADERS supposed to be set? ==="
git log --all --oneline --grep="arduino" 2>/dev/null | head -10 || echo "No git history"

Repository: h2zero/esp-nimble-cpp

Length of output: 127


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Display complete CMakeLists.txt again with line count ==="
cat -n CMakeLists.txt | tail -50

echo
echo "=== Check if USING_NIMBLE_ARDUINO_HEADERS is set via CMake variable ==="
rg -n 'set\(.*ARDUINO\|add_compile_options.*ARDUINO' CMakeLists.txt

echo
echo "=== Comprehensive search: Where should this macro be set? ==="
echo "Checking for any preprocessor flag definition pattern:"
rg -rn '\-DUSING_NIMBLE_ARDUINO_HEADERS|\-DARDUINO' . --include='*.txt' --include='*.cmake' --include='*.json' --include='*.yml'

echo
echo "=== Conclusion: Is the macro actually defined anywhere? ==="
if ! rg -q 'USING_NIMBLE_ARDUINO_HEADERS.*=' .; then
    echo "NO DEFINITION FOUND for USING_NIMBLE_ARDUINO_HEADERS"
    echo "This macro is used in 44+ places but is never set in:"
    echo "  - CMakeLists.txt"
    echo "  - Kconfig"
    echo "  - library.json"
    echo "  - Any source files"
fi

Repository: h2zero/esp-nimble-cpp

Length of output: 1666


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Show FIRST 31 lines of CMakeLists.txt (Arduino detection) ==="
head -31 CMakeLists.txt

echo
echo "=== Look for any conditional compile definitions based on Arduino detection ==="
rg -n -A10 '__COMPONENT_TARGETS.*arduino' CMakeLists.txt

echo
echo "=== Search for idf_component_set_property or target_compile_definitions ==="
rg -n 'idf_component_set_property\|target_compile_definitions\|idf_build_set_property' . --include='*.txt' --include='*.cmake'

echo
echo "=== Check if this PR is incomplete - search commit files ==="
git show --name-only 2>/dev/null | grep -i 'cmake\|kconfig\|library' || echo "Checking file modifications..."

echo
echo "=== CRITICAL CHECK: Does any part of the code SET this macro? ==="
echo "Exact search for where macro gets defined:"
git show HEAD 2>/dev/null | grep -i 'USING_NIMBLE_ARDUINO_HEADERS' | head -20 || rg -n 'USING_NIMBLE_ARDUINO_HEADERS.*=' . --include='*.cpp' --include='*.h'

Repository: h2zero/esp-nimble-cpp

Length of output: 2313


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Does CMAKE actually SET the macro anywhere? ==="
rg -n 'idf_component_set_property\|target_compile_definitions'

echo
echo "=== Verify CMakeLists.txt is COMPLETE (check file size) ==="
wc -l CMakeLists.txt
tail -5 CMakeLists.txt

echo
echo "=== FINAL DIAGNOSIS: Search for USING_NIMBLE_ARDUINO_HEADERS definition ==="
echo "In CMakeLists: "
rg 'USING_NIMBLE_ARDUINO_HEADERS' CMakeLists.txt || echo "  NOT FOUND"

echo "In Kconfig: "
rg 'USING_NIMBLE_ARDUINO_HEADERS' Kconfig || echo "  NOT FOUND"

echo "In library.json: "
rg 'USING_NIMBLE_ARDUINO_HEADERS' library.json || echo "  NOT FOUND"

echo "In ANY source file: "
rg 'USING_NIMBLE_ARDUINO_HEADERS' src/ | wc -l
echo "  (matches found above)"

echo
echo "=== CONCLUSION ==="
echo "Macro USED: 44+ times in code"
echo "Macro DEFINED: 0 times in build system"
echo "RESULT: Macro is referenced but NEVER SET"

Repository: h2zero/esp-nimble-cpp

Length of output: 116


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Final verification: library.json for build.flags ==="
cat library.json
echo
echo "=== Does library.json have build.flags section? ==="
rg 'build.flags' library.json || echo "NO build.flags section found"

echo
echo "=== COMPREHENSIVE FINAL RESULT ==="
echo "1. Macro Usage: 44+ locations use USING_NIMBLE_ARDUINO_HEADERS"
echo "2. Macro Definition: ZERO locations define it"
echo
echo "Files that USE the macro:"
rg -l 'USING_NIMBLE_ARDUINO_HEADERS' src/ | wc -l
echo
echo "Files that DEFINE the macro:"
rg -l '#define USING_NIMBLE_ARDUINO_HEADERS' . || echo "NONE"
echo
echo "Build system files that SET it:"
rg 'USING_NIMBLE_ARDUINO_HEADERS' CMakeLists.txt Kconfig library.json 2>/dev/null || echo "NONE FOUND"

Repository: h2zero/esp-nimble-cpp

Length of output: 943


Arrr, the USING_NIMBLE_ARDUINO_HEADERS macro be used in 44+ places but ne'er actually defined in the build system, ye scallywag!

The macro be referenced across 27 source/header files in conditional include gates (lines like 32-35 in src/NimBLEDevice.h), but there be no mechanism to set it:

  • library.json lacks a build.flags section to define -DUSING_NIMBLE_ARDUINO_HEADERS
  • CMakeLists.txt detects Arduino frameworks but don't add any compile definitions
  • Kconfig contains no flag fer this macro

Without this macro being defined, all #ifdef USING_NIMBLE_ARDUINO_HEADERS blocks will always evaluate false, causin' the code to always use the fallback host/ble_gap.h paths instead o' the Arduino header layouts. The commit message says "Add a flag to use arduino header paths" but the flag was ne'er added to the build configuration. Set this macro explicitly in the build system so Arduino-oriented PlatformIO builds actually use the correct header paths.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NimBLEDevice.h` around lines 32 - 35, The build never defines the macro
USING_NIMBLE_ARDUINO_HEADERS so all `#ifdef` USING_NIMBLE_ARDUINO_HEADERS include
branches (e.g., in src/NimBLEDevice.h) never trigger; add a compile definition
for this macro in the build system: update library.json to add a build.flags
entry (e.g., "-DUSING_NIMBLE_ARDUINO_HEADERS") for PlatformIO/Arduino builds,
update CMakeLists.txt to add target_compile_definitions or
add_compile_definitions when the Arduino framework is detected, and optionally
expose a Kconfig boolean (e.g., CONFIG_USING_NIMBLE_ARDUINO_HEADERS) that when
enabled adds the -D define so developers can toggle the Arduino header path
behavior.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/NimBLEDevice.h (1)

32-35: ⚠️ Potential issue | 🔴 Critical

Blocker: ye switched the gate, but the new macro still be unhooked in build config.

Line 32 now depends on USING_NIMBLE_ARDUINO_HEADERS, but the provided CMakeLists.txt snippet does not define it. That leaves Line 35’s fallback include active, so the missing-header failure this PR targets can still persist.

🏴‍☠️ Proposed fix (in CMakeLists.txt)
 idf_component_register(
   REQUIRED_IDF_TARGETS
     "esp32"
@@
   PRIV_REQUIRES
     ${ESP_NIMBLE_PRIV_REQUIRES}
 )
+
+# Enable Arduino-oriented NimBLE include layout when Arduino framework component is present.
+if(__COMPONENT_TARGETS MATCHES "___idf_espressif__arduino-esp32|__idf_arduino|___idf_framework-arduinoespressif32")
+  target_compile_definitions(${COMPONENT_LIB} PUBLIC USING_NIMBLE_ARDUINO_HEADERS=1)
+endif()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NimBLEDevice.h` around lines 32 - 35, NimBLEDevice.h now conditions on
the macro USING_NIMBLE_ARDUINO_HEADERS but your build doesn't define it, so the
fallback include stays active; update the build config to define
USING_NIMBLE_ARDUINO_HEADERS for the target that builds this header (e.g., add a
target_compile_definitions or equivalent definition for the library/executable
target) so the branch including "nimble/nimble/host/include/host/ble_gap.h" is
used; ensure the definition is applied to the same target that compiles sources
including NimBLEDevice.h and verify the preprocessor symbol name exactly matches
USING_NIMBLE_ARDUINO_HEADERS.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/NimBLEDevice.h`:
- Around line 32-35: NimBLEDevice.h now conditions on the macro
USING_NIMBLE_ARDUINO_HEADERS but your build doesn't define it, so the fallback
include stays active; update the build config to define
USING_NIMBLE_ARDUINO_HEADERS for the target that builds this header (e.g., add a
target_compile_definitions or equivalent definition for the library/executable
target) so the branch including "nimble/nimble/host/include/host/ble_gap.h" is
used; ensure the definition is applied to the same target that compiles sources
including NimBLEDevice.h and verify the preprocessor symbol name exactly matches
USING_NIMBLE_ARDUINO_HEADERS.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f712f8ca-c97f-4de3-9d1f-99c5291f7566

📥 Commits

Reviewing files that changed from the base of the PR and between f7b55b8 and b3ce8ad.

📒 Files selected for processing (28)
  • Kconfig
  • src/NimBLEAddress.h
  • src/NimBLEAdvertisedDevice.h
  • src/NimBLEAdvertisementData.cpp
  • src/NimBLEAdvertising.cpp
  • src/NimBLEAdvertising.h
  • src/NimBLEAttValue.cpp
  • src/NimBLECharacteristic.cpp
  • src/NimBLEClient.cpp
  • src/NimBLEClient.h
  • src/NimBLEConnInfo.h
  • src/NimBLEDevice.cpp
  • src/NimBLEDevice.h
  • src/NimBLEExtAdvertising.cpp
  • src/NimBLEExtAdvertising.h
  • src/NimBLEL2CAPChannel.cpp
  • src/NimBLEL2CAPChannel.h
  • src/NimBLELocalValueAttribute.h
  • src/NimBLELog.h
  • src/NimBLERemoteValueAttribute.h
  • src/NimBLEScan.cpp
  • src/NimBLEScan.h
  • src/NimBLEServer.cpp
  • src/NimBLEServer.h
  • src/NimBLEStream.cpp
  • src/NimBLEStream.h
  • src/NimBLEUUID.h
  • src/NimBLEUtils.cpp
💤 Files with no reviewable changes (1)
  • Kconfig
✅ Files skipped from review due to trivial changes (11)
  • src/NimBLEL2CAPChannel.cpp
  • src/NimBLEServer.h
  • src/NimBLEExtAdvertising.h
  • src/NimBLELocalValueAttribute.h
  • src/NimBLEClient.h
  • src/NimBLEAdvertising.h
  • src/NimBLEAdvertisedDevice.h
  • src/NimBLEStream.h
  • src/NimBLEServer.cpp
  • src/NimBLEClient.cpp
  • src/NimBLEUUID.h
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/NimBLEUtils.cpp
  • src/NimBLECharacteristic.cpp
  • src/NimBLEAdvertisementData.cpp
  • src/NimBLEStream.cpp
  • src/NimBLELog.h
  • src/NimBLEDevice.cpp
  • src/NimBLEAddress.h
  • src/NimBLEL2CAPChannel.h

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/NimBLEDevice.cpp (1)

1028-1035: ⚠️ Potential issue | 🔴 Critical

Fix asymmetry in deinit path — Arduino builds leak controller resources!

Avast! The deinit path be NOT mirroring the init logic, matey. Thar be a resource leak lurkin' in these waters!

On init (line 914), the guard be:

#  if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) || defined(USING_NIMBLE_ARDUINO_HEADERS)

This means: execute if (IDF < 5.0.0) OR usin' Arduino headers.

On deinit (lines 1028-1029), the guard be:

# ifndef USING_NIMBLE_ARDUINO_HEADERS
#  if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)

This means: execute if NOT usin' Arduino AND IDF < 5.0.0.

When USING_NIMBLE_ARDUINO_HEADERS be defined with IDF < 5.0.0:

  • Init: Executes esp_bt_controller_init()
  • Deinit: Skips esp_nimble_hci_and_controller_deinit()

That be a resource leak fer Arduino builds! The controller be initialized but never properly deinitialized.

Change the deinit guard to match init:

#  if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) || defined(USING_NIMBLE_ARDUINO_HEADERS)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NimBLEDevice.cpp` around lines 1028 - 1035, The deinit preprocessor
guards around esp_nimble_hci_and_controller_deinit() are asymmetric with the
init guards used around esp_bt_controller_init(), causing Arduino builds to skip
controller deinitialization and leak resources; modify the deinit guards so they
match the init condition (i.e., run the deinit when ESP_IDF_VERSION <
ESP_IDF_VERSION_VAL(5,0,0) OR USING_NIMBLE_ARDUINO_HEADERS is defined) so
esp_nimble_hci_and_controller_deinit() is invoked in the same cases where
esp_bt_controller_init() was called.
🧹 Nitpick comments (1)
src/NimBLEStream.cpp (1)

23-29: Arr, this flag flip be shipshape and seaworthy!

The switch from CONFIG_NIMBLE_CPP_IDF to USING_NIMBLE_ARDUINO_HEADERS be a clever refactorin', matey! Rather than inferrin' Arduino paths by the absence of the IDF flag, ye now explicitly check fer Arduino headers—a cleaner sail into the harbor. This pattern flies consistent across the entire fleet of source files (27+ sightings from bow to stern), showin' this be no rogue flag.

The USING_NIMBLE_ARDUINO_HEADERS macro be injected by the PlatformIO framework build system, not explicitly defined in library.json or CMakeLists.txt, which be the intended design fer this build environment. The header paths be correctly hoisted fer all ports through this mechanism.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NimBLEStream.cpp` around lines 23 - 29, The conditional include in
NimBLEStream.cpp should use the new macro consistently across the codebase:
replace any remaining checks for CONFIG_NIMBLE_CPP_IDF with
USING_NIMBLE_ARDUINO_HEADERS so all files (including NimBLEStream.cpp) detect
Arduino header paths the same way; verify the build system (PlatformIO) injects
USING_NIMBLE_ARDUINO_HEADERS (no change to CMakeLists.txt/library.json) and
update any files referencing os_mbuf.h or nimble_port.h to follow the same
`#ifdef` USING_NIMBLE_ARDUINO_HEADERS pattern to avoid divergent include paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/NimBLEDevice.cpp`:
- Around line 1028-1035: The deinit preprocessor guards around
esp_nimble_hci_and_controller_deinit() are asymmetric with the init guards used
around esp_bt_controller_init(), causing Arduino builds to skip controller
deinitialization and leak resources; modify the deinit guards so they match the
init condition (i.e., run the deinit when ESP_IDF_VERSION <
ESP_IDF_VERSION_VAL(5,0,0) OR USING_NIMBLE_ARDUINO_HEADERS is defined) so
esp_nimble_hci_and_controller_deinit() is invoked in the same cases where
esp_bt_controller_init() was called.

---

Nitpick comments:
In `@src/NimBLEStream.cpp`:
- Around line 23-29: The conditional include in NimBLEStream.cpp should use the
new macro consistently across the codebase: replace any remaining checks for
CONFIG_NIMBLE_CPP_IDF with USING_NIMBLE_ARDUINO_HEADERS so all files (including
NimBLEStream.cpp) detect Arduino header paths the same way; verify the build
system (PlatformIO) injects USING_NIMBLE_ARDUINO_HEADERS (no change to
CMakeLists.txt/library.json) and update any files referencing os_mbuf.h or
nimble_port.h to follow the same `#ifdef` USING_NIMBLE_ARDUINO_HEADERS pattern to
avoid divergent include paths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 37ddafd4-d30e-4c8e-82fb-a501ac913a6d

📥 Commits

Reviewing files that changed from the base of the PR and between b3ce8ad and d12b2b3.

📒 Files selected for processing (28)
  • Kconfig
  • src/NimBLEAddress.h
  • src/NimBLEAdvertisedDevice.h
  • src/NimBLEAdvertisementData.cpp
  • src/NimBLEAdvertising.cpp
  • src/NimBLEAdvertising.h
  • src/NimBLEAttValue.cpp
  • src/NimBLECharacteristic.cpp
  • src/NimBLEClient.cpp
  • src/NimBLEClient.h
  • src/NimBLEConnInfo.h
  • src/NimBLEDevice.cpp
  • src/NimBLEDevice.h
  • src/NimBLEExtAdvertising.cpp
  • src/NimBLEExtAdvertising.h
  • src/NimBLEL2CAPChannel.cpp
  • src/NimBLEL2CAPChannel.h
  • src/NimBLELocalValueAttribute.h
  • src/NimBLELog.h
  • src/NimBLERemoteValueAttribute.h
  • src/NimBLEScan.cpp
  • src/NimBLEScan.h
  • src/NimBLEServer.cpp
  • src/NimBLEServer.h
  • src/NimBLEStream.cpp
  • src/NimBLEStream.h
  • src/NimBLEUUID.h
  • src/NimBLEUtils.cpp
💤 Files with no reviewable changes (1)
  • Kconfig
✅ Files skipped from review due to trivial changes (6)
  • src/NimBLEScan.h
  • src/NimBLEDevice.h
  • src/NimBLEAdvertisementData.cpp
  • src/NimBLEScan.cpp
  • src/NimBLEAttValue.cpp
  • src/NimBLEL2CAPChannel.h
🚧 Files skipped from review as they are similar to previous changes (11)
  • src/NimBLEClient.h
  • src/NimBLEServer.h
  • src/NimBLEExtAdvertising.h
  • src/NimBLEAddress.h
  • src/NimBLEUtils.cpp
  • src/NimBLEStream.h
  • src/NimBLELog.h
  • src/NimBLEUUID.h
  • src/NimBLEServer.cpp
  • src/NimBLECharacteristic.cpp
  • src/NimBLEClient.cpp

@h2zero h2zero merged commit ac2bf13 into master Mar 31, 2026
66 checks passed
@h2zero h2zero deleted the header-flag branch March 31, 2026 22:59
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.

ble_gap.h no such file

1 participant