Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/content/docs/components/esphome.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Advanced options:
- **platformio_options** (*Optional*, mapping): Additional options to pass over to PlatformIO in the
platformio.ini file. See [`platformio_options`](#esphome-platformio_options).

- **build_flags** (*Optional*, list of strings): Extra compiler flags to add to the build. Works on
both the PlatformIO and native ESP-IDF backends. See [`build_flags`](#esphome-build_flags).

- **environment_variables** (*Optional*, mapping): Environment variables to set during the build process.
See [`environment_variables`](#esphome-environment_variables).

Expand Down Expand Up @@ -191,6 +194,31 @@ esphome:
board_build.f_flash: 80000000L
```

<span id="esphome-build_flags"></span>

## `build_flags`

The `build_flags` option lets you add extra compiler flags to the build. Unlike
`platformio_options.build_flags`, this option also works on the native ESP-IDF build (for variants
Comment thread
swoboda1337 marked this conversation as resolved.
that use it, such as ESP32-P4 and ESP32-H2), and is the recommended way to pass extra flags when
you want a configuration that works on both backends.

```yaml
# Example configuration entry
esphome:
# ...
build_flags:
- "-DMY_CUSTOM_DEFINE"
- "-Wno-error=maybe-uninitialized"
```

Flags are processed as follows:

- `-D...` and `-W...` (non-linker warning) flags are applied project-wide on the IDF backend so
they reach every component, including managed ones.
- `-Wl,...` linker flags are applied to the link step.
- On the PlatformIO backend, flags are written to `build_flags` in `platformio.ini`.

<span id="esphome-environment_variables"></span>

## `environment_variables`
Expand Down