TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Zig cc: A drop-in replacement for GCC/Clang

831 点作者 hazebooth大约 5 年前

30 条评论

airstrike大约 5 年前
&gt; Take a moment to appreciate what just happened here - I downloaded a Windows build of Zig, ran it in Wine, using it to cross compile for Linux, and then ran the binary natively. Computers are fun!<p>&gt; Compare this to downloading Clang, which has 380 MiB Linux-distribution-specific tarballs. Zig&#x27;s Linux tarballs are fully statically linked, and therefore work correctly on all Linux distributions. The size difference here comes because the Clang tarball ships with more utilities than a C compiler, as well as pre-compiled static libraries for both LLVM and Clang. Zig does not ship with any pre-compiled libraries; instead it ships with source code, and builds what it needs on-the-fly.<p>Hot damn! You had me at Hello, World!
评论 #22681433 未加载
评论 #22680879 未加载
评论 #22680577 未加载
评论 #22681579 未加载
Shoop大约 5 年前
Really incredible work and it&#x27;s been very fun to follow along. The streams where Andrew did the last part of this work can be seen here: [1], [2].<p>I am really happy that someone is making the effort to steadily simplify systems programming rather than make it more complicated. Linux goes to such incredible lengths to be bug-for-bug backwards compatible, but then the complexities of all of our layers of libcs, shared libraries, libsystemd, dbus, etc cause unnecessary pain and breakage at every level. Furthermore, cross-compiling C code across different architectures on Linux is far harder than it needs to be. I have a feeling that there wouldn&#x27;t be as much interest in the steady stream of sandboxes and virtual machines (JVM, NaCl, PNaCl, flatpak, docker, WebAssembly) if we could just simplify the layers and layers of cruft and abstractions in compiler toolchains, libc implementations, and shared libraries. Practically every laptop and server processor use the exact same amd64 architecture, but we have squandered this opportunity by adding leaky abstractions at so many levels. I can&#x27;t wait until installing a program on linux is as simple as downloading a static executable and just running it and I hope zig brings this future.<p>[1] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=2u2lEJv7Ukw" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=2u2lEJv7Ukw</a> [2] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=5S2YArCx6vU" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=5S2YArCx6vU</a>
评论 #22679728 未加载
评论 #22684169 未加载
emmanueloga_大约 5 年前
The cross compiling features of Zig look fantastic! Installation is so easy, just downloading and extracting a single file.<p>Should every compiler stack have prioritized cross compilation over other features? (I vote: YES). Cross compiling programs has always been a PITA for most languages.<p>It would be great if Zig cc could be paired with vcpkg [1] for a nice cross-compiling development environment. Looks like vckpg requires a C++ compiler though.<p>1: <a href="https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;vcpkg" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;vcpkg</a>
评论 #22681444 未加载
评论 #22679620 未加载
评论 #22680160 未加载
评论 #22679640 未加载
hardwaregeek大约 5 年前
I&#x27;d love for a hotlist or even prize for programmers doing awesome stuff like this. Off the top of my head, Andrew, Andreas Kling of Serenity OS, whoever ffwff is (<a href="https:&#x2F;&#x2F;github.com&#x2F;ffwff&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ffwff&#x2F;</a>), Niko Matsakis of Rust, and so on. It&#x27;d be very awesome to have a roundtable with some of these people. They could discuss different approaches to design, their own histories and plans for the future. I loved reading Coders at Work, but I felt that there was a missed opportunity by not having the subjects interact with each other. So many of them had similar and very dissimilar ideas&#x2F;approaches, which would have made for a wonderful discussion.<p>If someone could do the same but for a younger generation, I think it&#x27;d be very valuable.
drfuchs大约 5 年前
Zig (the language) is very appealing as a &quot;better C than C&quot;. Check out <a href="https:&#x2F;&#x2F;ziglang.org" rel="nofollow">https:&#x2F;&#x2F;ziglang.org</a> (dis-disclaimer: I&#x27;m unaffiliated.)
评论 #22679395 未加载
评论 #22679782 未加载
评论 #22682485 未加载
评论 #22679610 未加载
评论 #22681037 未加载
评论 #22680970 未加载
AndyKelley大约 5 年前
Thanks everyone for the kind words! It&#x27;s been a lot of work to get this far, and the Zig project has further to go still.<p>If you have a few bucks per month to spare, consider chipping in. I&#x27;m hoping to have enough funds soon to hire a second full time developer.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;users&#x2F;andrewrk&#x2F;sponsorship" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;users&#x2F;andrewrk&#x2F;sponsorship</a>
评论 #22680204 未加载
评论 #22679885 未加载
评论 #22680109 未加载
评论 #22681833 未加载
评论 #22679811 未加载
评论 #22690690 未加载
评论 #22679943 未加载
评论 #22686726 未加载
评论 #22680766 未加载
JyB大约 5 年前
I&#x27;m so glad we are seeing a shift towards language simplicity in all aspects (control flows, keywords, feature-set, ...). It&#x27;so important in ensuring reliable codebases in general.
评论 #22685181 未加载
mncharity大约 5 年前
&gt; uses a sophisticated caching system to avoid needlessly rebuilding artifacts<p>Reminded me of the Stanford Builder gg[1], which does highly parallel gcc compilation on aws lambda. make -j2000.<p>So with a zig cc drop-in, you might get highly-parallel cross-compilation?<p>Though the two caching systems might be a bit redundant.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;StanfordSNR&#x2F;gg" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;StanfordSNR&#x2F;gg</a>
peter_d_sherman大约 5 年前
&quot;In order to provide libc on these targets, Zig ships with a subset of the source files for these projects:<p>musl v1.2.0<p>mingw-w64 v7.0.0<p>glibc 2.31&quot;<p>These are super-important... (Otherwise, someone will be very limited in what they can compile -- the simplest of programs only...).<p>It&#x27;s great that you included these, and as source, not as precompiled binaries!<p>(Also, a well-selected subset is probably the right balance of functionality vs. complexity...)<p>Anyway, very excited about the future of Zig as a drop-in Clang&#x2F;gcc replacement!
chronogram大约 5 年前
Perhaps I missed this from the blog post since it&#x27;s unfamiliar to me. Can you compile Linux with this? Like, could you really straight up use this is a drop-in replacement for a whole Gentoo system?
评论 #22679725 未加载
评论 #22679691 未加载
eatonphil大约 5 年前
Wow, that&#x27;s one of the easiest ways I&#x27;ve seen to get a C compiler for RISC-V. Going on my list for when I&#x27;m playing around with emulators again.
speps大约 5 年前
Zig is great and I can&#x27;t wait to try cc! However, Andrew if you&#x27;re reading this, the std is very confusingly named. It&#x27;s not a hash map, it&#x27;s AutoHashMap, it&#x27;s not a list, it&#x27;s a ArrayList, etc. I had a lot of trouble finding idiomatic code without having to search through the std sources, like an example with each struct&#x2F;fun doc would help a ton.
评论 #22680146 未加载
评论 #22685500 未加载
nrclark大约 5 年前
Zig looks super cool. I&#x27;ve been wanting to experiment with it for some system software.<p>Are there any guides anywhere for calling libc functions from zig? I&#x27;m interested in fork&#x2F;join, chmod, fcntl, and that kind of thing. Do I just import the C headers manually? Or is there some kind of built-in libc binding?
评论 #22680493 未加载
评论 #22680596 未加载
saagarjha大约 5 年前
I read through the post but I&#x27;m still a bit confused as to what parts of this is Zig and what parts are coming from other dependencies. What exactly is zig cc doing, and what does it rely on existing? Where are the savings coming from? Some people are mentioning that this is a clang frontend, so is the novelty here that zig cc 1. passes the the correct options to clang and 2. ships with recompilable support libraries (written in Zig, with a C ABI) to statically link these correctly (or, in the case of glibc, it seems to have some reduced fileset that it compiles into a stub libc to link against)? Where is the clang that the options are being passed to coming from? Is this a libclang or something that Zig ships with? Does this rely on the existence of a &quot;dumb&quot; cross compiler in the back at all?
评论 #22681957 未加载
pierrebai大约 5 年前
In the Zig main page, there is a claim that making overflow undefined on unsigned can allow more optimization... but the example given is extremely dependent on the constant chosen. Try to change the 3&#x2F;6 used in C++ to 2&#x2F;4, 3&#x2F;8 and 4&#x2F;8 for example... It is very strange how the clang code generation changes for each pair of constants!<p>(Also, having undefined behaviour on unsigned overflow can make some bit twiddling code harder to write. Then again, maybe Zig has a bit-twiddling unsigned-like type without overflow check? Zip allow turning off checks, but then it turns off checks for everything...)
ojosilva大约 5 年前
I really love Zig, it can apparently replace our C toolchain with brilliant, static cross-compilation, including s390 Linux support (mainframe Linux!).<p>My only gripe is that the syntax and stdlib, although practical and to the point, seem to suffer from some strange choices that somewhat clash with its own, albeit early, &quot;zen&quot; of simplicity.<p>- &#x27;@&#x27; prefix for builtin functions, a little strange and macro-looking for my eyes. Why not just plain keywords? And cleanup some of it: `@cos`, `@sin`, also feel like too much when they are already in the stdlib I believe.<p>- |x| for&#x2F;while list bind var, why not just for(x in y)? Surrounding pipes are really annoying to type in some foreign keyboards and feel totally needless in 99% of the places.<p>- inconsistent required parenthesis predicates in block statements in &quot;test STR {}&quot; vs. &quot;if() {}&quot;. Either require parenthesis or don&#x27;t, I don&#x27;t really care which one.<p>- prefixed type signatures, `?[]u32` feels a little off &#x2F; harder to read.<p>- comment-looking, noisy prefixed multi-line slashes `\\`.<p>- the need to dig deep into &quot;std&quot; to get your everyday lib functions out &quot;std.io.getStdOut().outStream().print()&quot;. `@import(&quot;std&quot;)` repeated many times.<p>- consider implementing destructuring syntax early-on to deal with so much struct member depth ie `const { x, y } = p` or `const { math: { add, mul } } = @import(&quot;std&quot;)`.<p>- anonymous list syntax with `.{}` is eye catching as the dot implies &quot;struct member&quot; in Zig, but then the dot is everywhere, specially when you do anonymous structs `.{.x=123}`, maybe consider `[1,2,3]` and `[x=123]` given brackets are being used for array length annotation anyways ie `array[]`.<p>- `.<i>` suffix for lvalue and rvalue pointer deref. Also `&quot;str&quot;.</i>` is a byte array unroll if I understood correctly. Here `f.* = Foo{ .float = 12.34 };` looks like it&#x27;s doing something with `.` to get to the struct members but it&#x27;s actually just a pointer deref. Also looks like a file or import lib wildcard (`file.*`) to my eyes.<p>- field access by string clunky `@field(p, &quot;x&quot;) = 123;`, with an odd function as lvalue.<p>Sorry for the criticism, we&#x27;re seriously checking out Zig for migrating a large C codebase and replacing future C projects. Although we can live with these quirks, they just make the language look a little random and NIH and that worries me and the team. For instance, Golang has great syntax and semantic consistency which is a boost on project steering quality and assured, life-long onboarding for newbees. Please consider widening the spec peer-review process, maybe in a separate Github repo with markdown proposal writeups. Discussing syntax seems superficial given many project and compiler feats under the hood, but it can become sorta &quot;genetic disease&quot; and a deal-breaker for the project on the long run!<p>This is a pre-release version I know, but it&#x27;s just that my hopes are really up for Zig as Golang, C++ and Rust never really did it for us as a multi-target sw toochain for various reasons.
评论 #22687110 未加载
评论 #22685750 未加载
Ericson2314大约 5 年前
Because you are using nixpkgs...<p>~~Does `zig cc` cross compiler libgcc&#x2F;compiler-rt on the fly? Does it compile libc on the fly?~~ Nevermind I did not scroll enough, it does compile on the fly. Whew!<p>As someone who also cares greatly about cross compilation, compilers definitely should step up their game, but `-target x86_64-windows-gnu` elides many details, unless you are confined to a fix set of platforms.
naasking大约 5 年前
This looks impressive. Cross-compilation is sorely underserved. I will definitely be checking this out.
rustybolt大约 5 年前
I&#x27;m normally not an &#x27;oh my god&#x27;-kind-of-guy, but... Oh my god!<p>Zig looks like a nice language for kernel development as well: <a href="https:&#x2F;&#x2F;github.com&#x2F;jzck&#x2F;kernel-zig" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jzck&#x2F;kernel-zig</a>
fwsgonzo大约 5 年前
Looks very cool! Did not see 32-bit RISC-V on the list though, so wondering about that. I would have liked to use Zig cc to build 32-bit RISC-V binaries fast, if that is possible. Doesn&#x27;t matter if they are freestanding.
评论 #22680654 未加载
SaxonRobber大约 5 年前
How does Zig compare with Nim and Rust? (putting aside the differences in adoption)
评论 #22684466 未加载
presiozo大约 5 年前
Damn, what an awesome project! That&#x27;s a lot of hard work, and now I want to try Zig. One more oh god save me from programming languages.
Y_Y大约 5 年前
What are the limitations? Speed? External libraries?
评论 #22679499 未加载
评论 #22679501 未加载
cbmuser大约 5 年前
Why is there a sparc backend but no sparc64 backend? sparc64 is what Debian uses these days, so having support for it in Zig would be nice.
keithnz大约 5 年前
can zig compile to C? so many languages would be very useful if they could compile to C for embedded systems as native compilers are very unlikely for new ( or even old ) languages
评论 #22680539 未加载
评论 #22680759 未加载
jedisct1大约 5 年前
Can `zig cc` also compile to WebAssembly&#x2F;WASI?
评论 #22685529 未加载
评论 #22682898 未加载
fizixer大约 5 年前
llvm is a bloated hot-mess of a compilation framework, built on a bloated hot-mess of a language (C++).<p>Folks who have achieved great things with llvm (and C++) have done so &#x27;despite&#x27; what they used, not &#x27;because of&#x27; it.<p>This has been my conviction for the past 10 years, and I&#x27;m glad I never had to touch llvm with a ten foot pole.<p>I had no doubts it&#x27;ll soon be surpassed by a common-sense no-bullshit tool-chain.<p>Has Zig cc achieved that? Great. No? It will or someone (or I) will develop an alternative that will.
评论 #22681818 未加载
评论 #22682187 未加载
评论 #22685702 未加载
ngcc_hk大约 5 年前
Wonder whether one can include this in iOS ...
spiritplumber大约 5 年前
You know what you doing! Take off every zig!
throwaway_pdp09大约 5 年前
I don&#x27;t want to be negative as there&#x27;s too much of that about but gcc and similar can do some pretty hefty optimisations, and for any real work I suspect those count for a great deal. Just because zigcc can compile C, neat as it is, doesn&#x27;t make it a drop-in replacement for gcc.<p>Does yours do loop unrolling, code hoisting, optimise array accesses to pointer increments, common expression elimination etc?
评论 #22680038 未加载
评论 #22681163 未加载
评论 #22680041 未加载