Esp32 and updating xtensa toolchain 12


Recently I have been trying to update xtensa toolchain to 12 (or 11 but same result) to finally make use of c++ modules

Here is my recent ini file:

platform = espressif32@^6.4.0
board = esp32dev
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_unflags = -std=gnu++11
build_flags =
platform_packages =

However any attempts ends up with tons of errors like these:

Any ideas if updating toolchain is possible? Do i need to update core as well? if so, then to which version?

Havae you tried what’s written in instead?

Yes I did but it turns out, error was somewhere else (the ini above works), I was able to partially use C++ 20 modules, some example

// Order of this is important, first module, then includes, then export

#include <Arduino.h>
#include <NimBLECharacteristic.h>

export module UARTWrapper;

export struct __attribute__((packed)) UartDataPacket {
	uint32_t dataLength;
	uint8_t data[256];

export struct __attribute__((packed)) UartBeginRequest {
	uint32_t baud;
	uint32_t config;

export class UARTWrapper {
	bool started;
	NimBLECharacteristic* bleCharacteristic;
	QueueDefinition* queue;

	UARTWrapper() {
		started = false;
		bleCharacteristic = nullptr;
		queue = xQueueGenericCreate(10, sizeof(UartDataPacket), queueQUEUE_TYPE_BASE);

	void begin(UartBeginRequest* request, NimBLECharacteristic* bleChar) {
		// ...

	void onReceive() {
		// ...

	static void sendQueue(void* p) {
		// ...

	void end() {

	void send(UartDataPacket* pPacket) {
		// ...

However there are several problems, perhaps with pio build scripts:

  1. Clean does not clean module cache, files like that remains:
  2. Probably build order isn’t correct because i am getting errors sometimes - am i correct pio build scripts would need update?:
UARTWrapper: error: failed to read compiled module: No such file or directory
UARTWrapper: note: compiled module file is 'gcm.cache/UARTWrapper.gcm'
UARTWrapper: note: imports must be built before being imported
UARTWrapper: fatal error: returning to the gate for a mechanical issue
  1. -fmodules-ts needs to be applied only for C++ files, is there a way to do so with pio ini? Adding this to build flags works but produces tons of warnings
  2. And current issues i am struggling with and unable to pinpoint:
src/AppSerial.cpp:17:8: internal compiler error: in write_location, at cp/
   17 | export module AppSerial;
      |        ^~~~~~
libbacktrace could not find executable to open

Would be nice to work out even partial support for modules, i have been waiting for this for a very long time :slight_smile:

Can you file an issue with Arduino-ESP32 so that they pull it in officially first?

I believe updating toolchain is not ready yet as besides the issues with modules, normal compilation gives pretty high amount of warnings. While my project did compile i did not test even a third of functions.

I have also pushed my module tests here: GitHub - kaminaris/Esp32DiagnosticDongle at modules-test
branch modules-test contains almost compiling code, at some point it even worked.