-
Notifications
You must be signed in to change notification settings - Fork 9
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 wasm #23
Zig wasm #23
Conversation
Zig-wasm32-wasi project added [draft]
Note: Initial purpose for this contribution doesn't include adding embedded solutions written in zig like Microzig (similar embedded hal [rust]) or sample project like Zig on the Raspberry Pi Pico |
Very interesting! What's the motivation behind switching clang-wasm to the zig toolchain? |
Portability! The key for zig is having all the libc src: Including the zig toolchain might have a blob of his own in wasm. |
Thanks! I'm not sure why portability is important here. Can you please split the pull request into two:
This will make it easier to test and discuss each one separately |
@urish, done (splited) |
Thanks! So regarding zig-wasm, is there any way to move "wokwi_chip_ii.zig" into a different directory? Wokwi always clears the src directory before building the project. |
Done! |
Thanks! I'm doing some integration testing. Meanwhile, a few more things:
|
Ok, after some initial testing, I see that the .wasm file does not export the function table. Wokwi expects a function table to be exported as Do you have any idea how to instruct zig to export the function table? |
One more thing I found:
|
Wow! verbose link $> zig build --verbose-link
LLD Link... wasm-ld --error-limit=0 --stack-first --export=chipInit --export=__wokwi_api_version_1 -z stack-size=1048576 --no-entry --allow-undefined -o /home/kassane/Documentos/Projetos/wokwi-zb/zig-wasm/project/zig-cache/o/855a4f1f50c7af981e02026194e4268c/chip_zig.wasm /home/kassane/Documentos/Projetos/wokwi-zb/zig-wasm/project/zig-cache/o/855a4f1f50c7af981e02026194e4268c/chip_zig.wasm.o /home/kassane/.cache/zig/o/09929859fca6d3f6d14ba8e9662932fe/libc.a /home/kassane/.cache/zig/o/5e1af799a7414de202076d24c9667a2d/libcompiler_rt.a |
So can you please tell it to add |
zig build --verbose-link
LLD Link... wasm-ld --error-limit=0 --stack-first --export=table -z stack-size=1048576 --no-entry --allow-undefined -o /home/kassane/Documentos/Projetos/wokwi-zb/zig-wasm/project/zig-cache/o/855a4f1f50c7af981e02026194e4268c/chip_zig.wasm /home/kassane/Documentos/Projetos/wokwi-zb/zig-wasm/project/zig-cache/o/855a4f1f50c7af981e02026194e4268c/chip_zig.wasm.o /home/kassane/.cache/zig/o/09929859fca6d3f6d14ba8e9662932fe/libc.a /home/kassane/.cache/zig/o/5e1af799a7414de202076d24c9667a2d/libcompiler_rt.a Reference: |
I just copied the name from the original library. Do you want me to rename it? |
The last change added (module
(table $table0 1 1 funcref)
(memory $memory (;0;) (export "memory") 16)
(global $global0 (mut i32) (i32.const 1048576))
)
The original name ended with |
@urish , done zig build --verbose-link
LLD Link... wasm-ld --error-limit=0 --export-table --stack-first --export=chipInit --export=__wokwi_api_version_1 -z stack-size=1048576 --no-entry --allow-undefined -o /home/kassane/Documentos/Projetos/wokwi-zb/zig-wasm/project/zig-cache/o/855a4f1f50c7af981e02026194e4268c/chip_zig.wasm /home/kassane/Documentos/Projetos/wokwi-zb/zig-wasm/project/zig-cache/o/855a4f1f50c7af981e02026194e4268c/chip_zig.wasm.o /home/kassane/.cache/zig/o/09929859fca6d3f6d14ba8e9662932fe/libc.a /home/kassane/.cache/zig/o/5e1af799a7414de202076d24c9667a2d/libcompiler_rt.a |
Thanks, I'll test it shortly! By the way, how did you find out about Wokwi? What was the motivation for adding zig support for the custom chips? |
I got to know wokwi through the franzininho community.
Earlier I spoke only about portability, though believe that zig can improve on this by making solutions simpler (Low Level) and more lightweight. |
Thanks! I did some initial testing, and it seems to work well. I'll merge and deploy the builder to the staging environment, so you can play around and provide feedback too. From my testing so far, Zig seems very efficient at producing small wasm binaries! |
p.s. good job on creating a tidy container. Usually pull requests require a lot more effort and feedback from my end to get them working well and be easy to maintain in the future. For most pull requests this takes weeks - you did it in under 3 hours! |
Link to a demo project in the staging environment: https://zig.preview.wokwi.com/projects/348776765607379539 I'd love if you created a few more custom chips to test the integration with the new builder. If you need some ideas, there are several examples here: https://link.wokwi.com/custom-chips-alpha (under the Chip examples section) |
Hi @urish It will be a pleasure to help in my spare time and I have even been doing some documentation testing of the zig wrapper. doc src [sample]: zig-doc_wokwi_API.tar.gz How to generate doc?Single-file$> zig build-{lib,exe,obj} mylib.zig -femit-docs Project
Reference |
Thanks! As far as I understand it, Zig does not have a standard library manager yet, so the only way to have documentation is to self-host it? |
Exactly. |
New experiment.
Changes:
cc: @urish