Define [env] in `default_envs`

From this platformio post I have learned that I can create a separate env for each of my libraries’ examples in order to have a shortcut for testing them (alternatively to using the pio ci command). Now, of course I want all of these “example” envs to be copies of [env]. But I also want [env] to be the default env, so I can press the Build button in VSCode (the check mark) and it only builds for [env]. But now my question is, how can I list [env] in the default_envs?

As far as I know I have to give it a name, like [env:due], but then my “example” envs don’t copy the due env anymore.

How can I solve this?

Here is my platformio.ini file:

;default_envs = ?

platform = atmelsam
board = due
framework = arduino
test_framework = unity
lib_deps =
  adafruit/Adafruit ADS1X15@^2.4.0
  adafruit/Adafruit MCP23017 Arduino Library@^2.3.0
  adafruit/Adafruit BusIO@^1.14.1

; envs for running library examples

build_src_filter = +<../lib/mylib/examples/example1/example1.cpp>

build_src_filter = +<../lib/mylib/examples/example2/example2.cpp>

Like this, the build button builds all the envs.

Just set default_envs = example1 - is that what you’re asking?

No, I want the first env, [env], to be the default env, so that when I press the build button, the project builds for [env]. If I leave the default_envs empty, when I press the build button, my project gets built for all the envs, which I don’t want.

That’s not how it works, [env] is not a target, it’s a collection of common settings.

default_envs = example1



<settings with add/override what's in [env]>

<settings with add/override what's in [env]>


In this setup, the default target is [example1], taking all the settings from [env], and the other targets are variations, which also take the settings from [env], and add/modify their own.