Язык Zig (канал)
174 subscribers
26 photos
3 videos
6 files
239 links
Download Telegram
Язык Zig (канал)
Zig Using WASI and the C backend to delete the C++ compiler implementation #upstream
Nuke the C++ implementation of Zig from orbit using WASI #13560

The idea here is to use a small WASI binary as a stage1 kernel that is committed to source control and therefore can be used to build any commit from source. We provide a minimal WASI interpreter implementation that is built from C source, and then used to translate the Zig self-hosted compiler source code into C code. The C code is then compiled & linked, again by the system C compiler, into a stage2 binary. The stage2 binary can then be used repeatedly with zig build to build from source from that point on.

The WASI stage1 blob only needs to be updated when a breaking change or new feature affects the self-hosted compiler when building itself. For example, a bug fix that the self-hosted compiler does not trigger when building itself can be ignored. However, if the bug fix is required for zig to build itself, then the stage1 WASI blob needs to be updated. Similarly when the language is changed and the compiler wants to use the changes to build itself, the blob needs to be updated.

The WASI blob is produced with zig build update-zig1 which uses the LLVM backend to produce a ReleaseSmall binary that targets wasm32-wasi with a CPU of generic+bulk_memory. This produces a 2.6 MiB file. It is then optimized with wasm-opt -Oz --enable-bulk-memory bringing the total down to 2.4 MiB. Finally, it is compressed with zstd, bringing the total down to 655 KB. This is offset by the size of the zstd decoder implementation in C, however it is worth it because the zstd implementation will change rarely if ever, saving a total of 1.8 MiB every time the blob is updated.

I built this branch and master branch from source at the same time and got these results:

compiling from source with ninja install,
configured with
-DCMAKE_BUILD_TYPE=Release -DZIG_NO_LIB=ON:
master branch: 13m20s with 10.3 GiB peak RSS
wasi-bootstrap branch: 10m53s with 3.2 GiB peak RSS


Big thanks to @jacobly0 who has done significant work on the C backend to enable this possibility, as well as helping write the WASI interpreter and make it go fast, over in the external zig-wasi repo. In fact, after rewriting the interpreter a few times he figured out how to make it run even faster by translating the wasm code to C instead of interpreting it directly.
Closes #5246
Closes #6378
Closes #6485

# Prerequisites:

These are already merged inside this branch:
remove -fstage1 option #13383
WebAssembly-only fast allocator #13513
C backend: unblock progress on #13560 #13561
cbe bug fixes and improvements #13715

# Enhancements Needed
Merge blockers:
make zig1.c detect the host -target and pass correct flags to WASI argv
avoid hard-coding --color on in CMake
fix the -target parameter computation in CMake

Nice to have:

look into compressing zig1.wasm with zstd or gzip and having a mini zstd or gzip decoder in zig1.
enhance C backend so it generates fewer bytes of .c code
enhance C backend so it generates .c code that compiles faster
* enhance C backend so compiling the .c code generates no warnings
* C backend: generate MSVC-compatible code  #13574
* C backend: generate GCC-compatible code #13575

#upstream
👍1
Язык Zig (канал)
Nuke the C++ implementation of Zig from orbit using WASI #13560 The idea here is to use a small WASI binary as a stage1 kernel that is committed to source control and therefore can be used to build any commit from source. We provide a minimal WASI interpreter…
> We will be temporarily regressing async/await/suspend/resume in master branch.

Компилятор на C++ удалят ДО того, как добавят поддержку вышеуказанного в self–hosted компилятор

> The plan is to merge this into master branch before completing #6025. Users of async functions should stick to 0.10.0 for now.
🔥1
Channel photo updated
С НООООВЫМ ГОДОМ! 🎄🎊❄️🎄🦎🦎🦎
🎉1032🤯2
In the Zig project, we closed 19% of total open issues during December this year.

This was not the work of a "stale bot", but of humans who painstakingly verified that each and every issue was resolved and had test coverage if applicable.

Finally, our technical debt is being paid off and we can reach for some ambitious goals in 2023.
https://mastodon.social/@andrewrk/109621905821062620
👍2
In about 30 minutes I'll stream working towards the Zig Package Manager.

This will be a yak-shaving stream - there is much to do before we can work on the package manager logic itself.

https://twitch.tv/andrewrok/
https://mastodon.social/@andrewrk/109627337708582296
👍1
For those who haven't followed the discusison in #berlin, March 1st we're going to have a one-off event hosted by Delivery Hero.

We're going to have 3 short talks by Adam (the organizer), Joachim (everyone's favorite german-singaporean, also core team member), and me. The talks are going to be accessible for newcomers so don't be afraid.

Delivery Hero is offering food, drinks and afterwards we're going out to a pub with those who want to spend a bit of extra time together.

https://www.meetup.com/zigberlin-meetup-group/events/290511497
👍1
Язык Zig (канал)
https://kristoff.it/blog/zig-self-hosted-now-what/ #upstream #блоги
А вот и "new for loop syntax" из поста :)
https://github.com/ziglang/zig/pull/14671
zig fmt пофиксит старый код 😋
#upstream

P.S. тут ответ на более ранний пост в канале, но в чате походу не видно

upd: Смержили 🎉🎉🎉
🎉4🤔1
Кстати, совсем забыл: я тут вместе с Gso321 (он начал, я закончил) запилили на Gentoo Wiki статью про Zig:
https://wiki.gentoo.org/wiki/Zig
https://wiki.gentoo.org/wiki/Zig/ru

Там (само собой) в основном генто-специфичная информация, но какая-то информация может быть полезна всем пользователям :)
🔥41👏1
Ещё я тут обвязал libgccjit в Zig, вроде выглядит идиоматично :)

https://git.sr.ht/~bratishkaerik/zig-libgccjit

Там осталось несколько мелочей, но библиотека уже сейчас юзабельна, в папке "examples/" есть 4 из 5 портированных примера с C на Zig, из официального сайта libgccjit (сам примеры выглядят не так идиоматично, потому чтоя пытался воссоздать примеры строка-в-строку)

для сравнения:
https://git.sr.ht/~bratishkaerik/zig-libgccjit/tree/a287291ba38cdf99ebac08b5fef745b547ef177f/item/examples/gcc_tutorial_5.zig#L24
const char_ptr_ptr_type: *GccJit.Type = ctxt.getType(.char).getPointer().getPointer();

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/jit/docs/examples/tut05-bf.c;h=f948ede796a48dbae6e903c3b4b99cf2d5d4a103;hb=HEAD#l23
gcc_jit_type *char_ptr_ptr_type =
gcc_jit_type_get_pointer (
gcc_jit_type_get_pointer (
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR)));

#библиотеки