C89cc.sh – standalone C89/ELF64 compiler in pure portable shell

gist.github.com

201 points by gaigalas 5 days ago


gaigalas - 5 days ago

Single standalone file, no external tools used, PATH='' (empty), portable (bash, dash, ksh, zsh), produces x86 ELF executables, has mini-libc builtin.

Usage:

printf 'int main(){puts("hello");return 0;}' | sh c89cc.sh > hello

chmod +x hello

./hello

redoh - 3 days ago

Writing a C compiler in pure shell is one of those projects that sounds absurd until you think about bootstrapping. If you want to compile C on a system where you literally have nothing but a POSIX shell, this is exactly what you need. The fact that the parser itself is BNF-generated from shell modules makes it even more interesting as a study in how far you can push shell scripting before it breaks. Would love to see this evolve into a proper repo with tests so it can actually serve as a minimal bootstrapping tool.

kelsey98765431 - 3 days ago

Would be a lot better if it came with tests. Please do this justice and dont let it rot as a gist, make a real repo and add some docs and at least smoke tests or some kind. Thanks

uecker - 3 days ago

I am tempted to click the "report abuse" link ;-)

_ache_ - 3 days ago

I'm tempted to execute it, but it may as well be shellcode I couldn't tell.

jey - 3 days ago

It targets x86-64/ELF? I thought it would target `sh` to be portable?

cestith - 2 days ago

I love this as a novelty, and it could be useful for bootstrapping a system that’s had a shell cross-compiled to it.

Thinking about this in the context of a job I used to do, security on shared hosting environments, it gives me a bit of a shiver. There are reasons compilers aren’t available to normal users on those.

wengo314 - 3 days ago

if one could boostrap tcc with it, then it might be a viable tool.

dmitrygr - 3 days ago

Many parts of this are clearly autogenerated, but that in no way diminishes the sickening impressiveness of it!

dmead - 3 days ago

This is vibe coded right?

JackSmith_YC - 3 days ago

[dead]

self_awareness - 3 days ago

"Claude please generate me a C compiler in bash"

I mean, today it's possible to generate it in Tcl, Elisp, Windows BAT, Powershell.

The effort is just 1 prompt.

The WHY question is much more important today -- "because I can" no longer makes sense, because we all can do much, much more with minimum effort today than before LLMs.