Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig + IDF support #12

Merged
merged 1 commit into from
Mar 28, 2024
Merged

Zig + IDF support #12

merged 1 commit into from
Mar 28, 2024

Conversation

kassane
Copy link
Contributor

@kassane kassane commented Mar 27, 2024

Information

  • Language: Ziglang
  • Toolchain: Zig
  • Use IDF: Yes (use heap allocator)
  • Bare-Metal: No
  • FFI: C to Zig

Details

The example uses Zig v0.12.0-dev that has been forked to support the xtensa architecture in addition to other architectures available from the llvm codegen. And also show a idf-wrapper written in ziglang where modules are obtained from the zig-pkg ([decentralized] package manager) zon file.

Note: Hopefully it's pretty clear that the main application is placeholder.c that is attached to main/cmakelists.txt and zig is just a dependency in static library format.
CMake does all the work, but it shares some information with build.zig, including compiled objects that are added to the zig library, avoiding undefined reference (depending on the execution order when building).

cc: @georgik

Reference

@georgik
Copy link
Owner

georgik commented Mar 28, 2024

Thank you very much @kassane . This is impressive work. I'm very glad that we can add Zig into results.
I've tried some bare metal Zig before on ESP32, yet solution with ESP-IDF makes much more sense in this stage.

@georgik georgik merged commit c7562a5 into georgik:main Mar 28, 2024
@kassane kassane deleted the zig branch March 28, 2024 11:59
@kassane
Copy link
Contributor Author

kassane commented Mar 28, 2024

Thanks!
Based on CI error: https://github.com/georgik/esp32-lang-lab/actions/runs/8466882009/job/23196614994#step:4:1478

v5.1.3-416-gd23b7a0361 unparsed version.

idf.ESP_LOG(allocator, tag,
\\[ESP-IDF Info]
\\* Version: {s}
\\
, .{idf.Version.get().toString(allocator)});

Implementation: https://github.com/kassane/zig-esp-idf-sample/blob/a4eaae1683ffb303142dce2ad50d4ec63eba69cf/imports/version.zig#L16-L39

Need to improve panic_handler with esp_backtrace (TODO). I tried zig @breakpoint, however the system reboots all the time.
In general, ziglang's panic_handler works better if the application is only built by the zig compiler, in this case the host is gcc(crosstool-ng).

@kassane
Copy link
Contributor Author

kassane commented Mar 28, 2024

Version fixed: kassane/zig-esp-idf-sample@e571483.

When you want you can update zon file.

cd /path/{build.zig.zon path}
# overwrite idf commit-tag/branch and hash
$> zig fetch --save=idf git+https://github.com/kassane/zig-esp-idf-sample#e57148332bb634c342412756db428b9a5b658387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants