You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
self-host building musl, glibc, and mingw-w64 #4313
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.stage1The process of building from source via WebAssembly and the C backend.
Once we have the "cache hash" API self-hosted (See #4311), another big win is self-hosting the code that builds zig's libcs from source, for the target platform.
This provides several benefits:
There will only be one implementation, across stage1 and self-hosted, rather than two. Less room for bugs. Improving and maintaining the self-hosted version will be work that benefits both stage1 and self-hosted.
zig translate-c is already self-hosted. Once building libc is also self-hosted, creating the clang command line can be moved (at least partially) to self-hosted as well. Combined with making linking self-hosted (see self-host linking #4314), this will make it possible to self-host the drop-in C compiler feature (see use case: ability to use zig as a drop-in replacement for a C compiler #3089).
multi threading. The C++ stage1 compiler is single-threaded. However, the Zig Standard Library and self-hosted compiler is designed to take advantage of multiple CPUs & cores. With building of libc self-hosted, it's a straightforward path to make compilation of C objects multi-threaded, taking full advantage of hardware resources.
@andrewrk
I've been investigating this issue. The question I have is, how much code should be ported from C++ to Zig? For example: the build_musl and build_libcxx call the function codegen_build_and_link.
Should this function also be ported from C++ to Zig? (I don't have good intuition for which functions should stay in C++ and which functions should be ported to Zig).
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.stage1The process of building from source via WebAssembly and the C backend.
Activity
vedantroy commentedon Jun 17, 2020
@andrewrk
I've been investigating this issue. The question I have is, how much code should be ported from C++ to Zig? For example: the
build_muslandbuild_libcxxcall the functioncodegen_build_and_link.Should this function also be ported from C++ to Zig? (I don't have good intuition for which functions should stay in C++ and which functions should be ported to Zig).
andrewrk commentedon Jun 18, 2020
In general, as much code should be moved from C++ to zig as possible. The only limitation is when doing so would introduce a cyclic dependency.
As an example the reason translate-c can be self hosted is that the self hosted compiler does not use the
@cImportfeature.Likewise, the zig code that gets compiled into stage1 does not need to be linked into an executable, only an object file or static library.
Hope that helps, happy to discuss more if you have any other questions.
andrewrk commentedon Sep 30, 2020
Landed in fe117d9.