apple / swift-matter-examples

An Embedded Swift Matter application running on ESP32-C6
https://apple.github.io/swift-matter-examples/tutorials/tutorial-table-of-contents/
Apache License 2.0
212 stars 16 forks source link

Code fails to compile #4

Open dennis777 opened 1 month ago

dennis777 commented 1 month ago

Cannot compile the smart-light build on my MBP running macOS 15 beta

running idf.py build flash monitor runs about partially through, then fails and yields the following output

...
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: No available targets are compatible with triple "riscv32-none-none-eabi"
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
...
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
...

Ngl I just have no idea as to where to even start to debug this... 😅 theres so many layers of frameworks and things all playing in on each other. Any tips would be appreciated

MaxDesiatov commented 1 month ago

Which version of Swift are you using to build this? Would you be able to provide output of a swift --version invocation just before the build?

dennis777 commented 1 month ago

Certainly!

image

MaxDesiatov commented 1 month ago

It looks like a version of Swift included with Xcode. What you need is the latest snapshot from https://swift.org/download, which would look like this (exact commit hashes may be different):

❯ swift --version
Apple Swift version 6.0-dev (LLVM 0872cb59adca699, Swift d138ca4b1442d90)
Target: arm64-apple-macosx14.0
dennis777 commented 1 month ago

Okay interesting. I did download it and install it previously and I did it again just now but running swift --version still gives me the same result. Now after some testing I see that only if I write the TOOLCHAINS=org.swift... swift --version, only then do I get the correct output. I tried to put it into my .zshrc profile but that doesn't seem to do it.

❯ TOOLCHAINS=org.swift.59202406131a swift --version
Apple Swift version 6.0-dev (LLVM 57177aa1b91540b, Swift 8be62863326595c)
Target: arm64-apple-macosx15.0
❯ swift --version                                  
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx15.0
MaxDesiatov commented 1 month ago

What's the output of xcode-select -p command on your machine? See this comment to make sure that the TOOLCHAINS environment variables has any effect. Also, if you add plain TOOLCHAINS=org.swift.59202406131a in .zshrc, it won't work, it has to be spelled as export TOOLCHAINS=org.swift.59202406131a.

dennis777 commented 1 month ago

Runing xcode-select -p gives

/Applications/Xcode.app/Contents/Developer

Putting these three into my .zshrc profile (and reloading the profile ofc)

# Swift Toolchains
export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw ~/Library/Developer/Toolchains/swift-latest.xctoolchain/Info$
# esp-idf
. ~/Documents/Programming/esp32/esp-idf/export.sh
# matter
. ~/Documents/Programming/esp32/esp-matter/export.sh

and running idf.py build errors out on the same spot

yaJannik commented 1 month ago

Hi there,

I might be able to help with this issue. I'm currently working on something similar and have encountered a different challenge further along. I'll open a separate issue for that.

I faced the same problems and found the following solution helpful:

export TOOLCHAINS=<TOOLCHAIN>
export PATH=/Library/Developer/Toolchains/<TOOLCHAIN>/usr/bin:$PATH

By setting these environment variables, I was able to resolve the issue. Give it a try and see if it works for you.

EDIT: Check the log of the build-script. Do you get this message: "The Swift compiler identification is Apple 6.0"?

dennis777 commented 4 weeks ago

Unfortunately doesn't seem to help my cause. I don't have that message in my logs. I was wondering if all these PATHS conflict in my zshrc file?

image

They're for various python versions and bun.js (and now this additional one for toolchains)

tali commented 2 weeks ago

I had the same problem and had to remove the build folder to get idf.py to recognise my new toolchain.

dennis777 commented 2 weeks ago

I had the same problem and had to remove the build folder to get idf.py to recognize my new toolchain.

Wow this actually worked 😂

First rm -rf build, then idf.py set-target esp32c6 and finally idf.py build flash monitor