kassane / zig-esp-idf-sample

Run Zig on esp-idf
Apache License 2.0
25 stars 1 forks source link

Roadmap and FAQs #1

Open kassane opened 3 months ago

kassane commented 3 months ago

TODO

mini-FAQ

So Zig can read C headers. Why manual wrappers?

Indeed @cImport/@cInclude doesn't access C types directly, but it converts to zig binding automatically (like binding-rs). However, there have been some limits to support at the moment, in particular when converting macros (difficult to parse). One example is ESP_LOGx, which has been done manually, since the original version provided in esp_log.h has become untranslatable. see: zig doc - @cImport vs translate-c


So why not use microzig to make the project fully zig-written?

I am currently using zig v0.12.0-dev (nightly/master) and the microzig project does not support this version yet. see: https://github.com/ZigEmbeddedGroup/microzig/pull/178 The use of regz (svd converter) will also need to be evaluated, since it is under development and not all peripherals are guaranteed during translation. see: https://github.com/ZigEmbeddedGroup/microzig/pull/180


Why did you add C++ example using Zig?

Isn't it clear? Okay, so instead of using crosstool-NG you switch to zig c++/clang++, but only with libc++ (LLVM C++ ABI) and not libstdc++ (GNU C++ ABI). However, the final binary will still be compiled via cmake with crosstool-NG and libgcc (compiler ABI), not compiler-rt (compiler ABI). see: https://github.com/kubo39/esp32-resource/issues/1

Note: Zig (the toolchain) doesn't just prefer its own language!

kassane commented 3 months ago

Although the readme claims to support v4.4 to 5.x, it is actually being tested on 5.3-dev.

The last commit added a wrapper to handle the IDF version. The main idea was to read the esp_idf_version.h header, but zig couldn't find it even though it had access to the include path.

https://github.com/kassane/zig-esp-idf-sample/blob/414dabaec91ad524482e30117d0d73061b7bd271/imports/idf-sys.zig#L6-L48

The idea of managing multiple versions of functions could be done in a similar way to crc_xx, depending on the version of the IDF.

https://github.com/kassane/zig-esp-idf-sample/blob/414dabaec91ad524482e30117d0d73061b7bd271/imports/idf-sys.zig#L335-L342

Reference

kassane commented 2 months ago

New tarballs: https://github.com/kassane/zig-espressif-bootstrap/releases/tag/0.12.0-xtensa added commit: https://github.com/kassane/zig-esp-idf-sample/commit/abcef439b5672b585de82955c8c6a5850d731230