Hello, I've been trying to get the example build a few times on 2 separate machines recently and I always fail during the build with the output ending with "[7/132] Building Swift Module '__idf_main' with 6 sources
FAILED: esp-idf/main/__idf_main.swiftmodule ........... Matter/Node.swift
error: unknown argument: '-import-bridging-header'".

From what I gather, this happens if one were to try using Swift toolchain that does not contain Swift Embeded yet.

However, I'm pretty positive that I have the toolchain set up correctly. My setup:

I use VSCode on macOS 14.5. I have Xcode 15.4 and the latest nightly Swift from main (swift-DEVELOPMENT-SNAPSHOT-2024-07-24-a-osx).

In VSCode, I have installed:

  • Swift support
  • ESP-IDF 5.2.2 (tried with 5.3 on a second machine as well)
  • Installed ESP-Matter successfully
  • Configured the example workspace for ESP-IDF, ESP-Matter
  • Configured VSCode to use the Swift nightly toolchain (I also tried the export in terminal). Output of % swift --version
    Apple Swift version 6.0-dev (LLVM 3c6e1d334961f5e, Swift 384d7f77a53d8a0)
  • CMake version is 3.30.1

I can get a normal ESP example to build (some that does not use Swift Embeded).

Any ideas where I might've made a mistake in setting up the environment?

I've tried the terminal approach set up on the second machine as well, but I have the same issue there as well (along with some other Python issues that do not happen on this primary machine).

Setting/resetting the command line tools did not help me as it did the other devs, they were always set properly to the Xcode 15.4 ones (I have tried though).

What ESP device is the program written for?
I tried to write under ESP32-C3, but it didn’t work because the Matter in the example only wants ESP32-C6 :)

It's the 'smart-light' example in the ' swift-matter-examples' repository. I have set the build target to the C6 variant.

Did you try to complete Documentation ?

Yes. The first approach was to follow that on the old machine, which did not work. After getting a second machine, I tried to install everything only through VSCode and got the same results, I always end up with the import headers issue.

error: unknown argument: '-import-bridging-header'".

This means the swiftc compiler that's used is too old. Do you have a nightly toolchain from "main" installed? Can we see your export TOOLCHAINS=... command and output of xcrun -f swiftc and swiftc -v?

Did you mean Trunk Development (main) snapshots ?

Yes.

1 Like

Versions:

  • main: 59202407241a
  • dev 6.0: 600202407241a

Hmm, have other problem today... can't install esp-matter :(
The problem is python 3.12 :)

@kubamracek
% xcrun -f swiftc
/Applications/Xcode-15.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc

% swiftc -v
Apple Swift version 6.0-dev (LLVM 3c6e1d334961f5e, Swift 384d7f77a53d8a0)
Target: arm64-apple-macosx14.0

That is managed by VSCode, I selected the Swift toolchain by using its Swift extension and the "Select toolchain" command. I tried manually setting the toolchain in its terminal as well, with no change.

The older macbook where I tried the terminal setup approach had the toolchain set normally by export TOOLCHAINS= and I had the correct Swift 6.0 version from those Trunk Development (main) snapshots that I've installed (currently swift-DEVELOPMENT-SNAPSHOT-2024-07-24-a-osx downloaded today on the new VSCode machine, 15-07 on the previous terminal set up machine I believe).

@iQQator
I had that same issue with esp-matter on the older macbook where Python 3.12 was installed. I even submitted issue to esp-idf repo, where a fix was provided for using 'pip3' in the setup script instead of 'pip', but that didn't fix it, it just moved the issue with Python elsewhere. I'd try pyenv and set the global version to 3.9.2 if possible. This new fresh macbook does not have the newer homebrew python installed and esp-matter does install correctly.

I fix this issue with python3

And now try to build project smart-light )

idf.py set-target eps32c3 # in my case
idf.py build

build complete success :slight_smile:

But:

  • i have UTM VM with Sequoia & Xcode 16 (for tests purpose)
  • i have main Toolchain
  • i install esp-matter by instructions from github issue :)
  • i suppress errors in python 3 install by ~/.pip/pip.conf edit with:
[install] 
break-system-package = true 
  • and use micro-app for zsh to run environment for build:
do_esp() {
     export TOOLCHAINS=org.swift.59202407241a
     . ~/esp/esp-idf/export.sh
     . ~/esp/esp-matter/export.sh
}

If you are building for the ESP32c3 (instead of the c6), you need to add the following lines to the target_compile_options in CMakeLists.txt:

        -Xcc -march=rv32imc_zicsr_zifencei
        -Xcc -mabi=ilp32

Otherwise your binary will likely crash.

1 Like

I got a little bit further today when having Xcode 16 installed (on Sonoma) and using the main Swift toolchain as required by the Documentation. I can't get the example to build, however at least I don't have the issue with the bridging header argument now.

The new error seems to be an issue of the esp-matter library directly. Log here.

Yeah, crash on device without this :)

Where is this options should be ?

The relevant CMakeLists.txt file is typically in the main folder of the example. E.g., in the led-blink example (under Apple's swift-matter-examples), there is a CMakeLists.txt in the main folder that has the following (line 25 onwards):

# Swift compiler flags to build in Embedded Swift mode, optimize for size, choose the right ISA, ABI, C++ language standard, etc.
target_compile_options(${COMPONENT_LIB} PUBLIC "$<$<COMPILE_LANGUAGE:Swift>:SHELL:
        -target riscv32-none-none-eabi
        -Xfrontend -function-sections -enable-experimental-feature Embedded -wmo -parse-as-library -Osize
        -color-diagnostics
        -Xcc -DCHIP_HAVE_CONFIG_H
        -Xcc -std=c++17
        -cxx-interoperability-mode=default
        -Xcc -fno-exceptions
        -Xcc -fno-rtti

This is where you would insert the two additional options, i.e. add:

        -Xcc -march=rv32imc_zicsr_zifencei
        -Xcc -mabi=ilp32
1 Like

Thanks. I found some information too (patch for project)

1 Like

I suppose this is because swift-6.0 branch doesn't support yet swift embedding, try to use main branch for Toolchains and select toolchains for xcode ;)

I have installed the toolchain from 'main' that is linked in the documentation, for example this one. Those are nightly snapshots that now contain Swift 6. I also tried 'Swift 6.0 Development' before which caused the exact same issue.

Maybe you stumbled upon a particular link that contained the correct version or during the time of writing the docs, the nightlies contained a different version? That doesn't make much sense though.

Would you please share your 'swift --version' or 'swiftc -v' output when you have your terminal/environment set for building the example and the build passes?

Hi @Vybo

Function for set environment, commented value was develop swift-6.0 branch
Снимок экрана 2024-07-31 в 13.23.53

Versions of swift --version and swiftc -v
Снимок экрана 2024-07-31 в 13.24.47