Show HN: Redbean – Single-file distributable web server
justine.lol
justine.lol
Justine has built a c library that allows you compile a binary once and have it run it on any os or baremetal. The SAME binary. Quite frankly, that sentence doesn't even make sense to me.
Check out https://storage.googleapis.com/justine/cosmopolitan/index.ht...
As far as I'm concerned, this is literal magic. Look at the magic numbers: https://github.com/jart/cosmopolitan/blob/37a4c70c3634862d8d...
I could go on, but there's no binary portability comparison with any other language. And she has made some pretty neat optimizations.
Back in the day, I saw some pretty neat stuff with the ELF format, but this takes the cake.
Wow.
Edit: I'm editing because this is just so bloody absurd.
https://storage.googleapis.com/justine/printimage.html
$ ./printimage.com someimage.jpg
Like wow. And also video.
https://storage.googleapis.com/justine/printvideo.html
I'm struggling to put my shock into words. I've been around.
There's engineering. There's academia.
But this falls into straight-up wizardry.
It's hard to grok cause there are no words to describe it.
When people say that something is cross-platform, they usually mean a) that the software will build on multiple platforms b) there is some sort of vm which runs the executable (jvm, beam, wasm)
This is the SAME binary. Running everywhere. Could be super-useful as an archival format for mission critical code. sqlite comes to mind.
Maybe it's late at night, but I'm struggling to find a suitable word for the project that is better than portable or cross-platform.
Literally, I can't find a better word than the project name - "actually portable executable."
@author - if you're reading this please set up something for a few bucks a month on your github sponsors. I don't think I have any use for the library, but this is so outrageous it deserves something more than imaginary internet points.
If interested, see previous discussions of APE:
Seems more likely to have installed programs on read-only media and a little tmpfs, instead of a writable binary and no tmpfs.
Do you have any information on some of the other strategies you researched?
I hope that Cosmopolitan becomes mainstream, so much more software could have that It Just Works quality.
FWIW, I like and agree with the things I was referencing, I didn't mean it in any way as a jab or provocation. I shall endeavor to do a better job staying on the topic of the article in question.
The coolest thing about this Actually Portable Executable is that once there's a compiler and linker built with it, I can play around with writing C on Windows without having to faff about with WSL or MinGW or learning what makes MSVC different from the C I learned in university and coded in my first job before I became a Java/JavaScript/Python/etc programmer. When I discovered Go I thought I had discovered the better C that just worked everywhere, but the idea of having plain old C that also just works everywhere is very appealing.
αcτµαlly pδrταblε εxεcµταblε has now piqued my interest, So I might actually indulge in C programming for fun again after all. Thanks Justine.
Maybe I have a blind spot or something or I've just been in Unix-land for too long.
But on Windows, trying to get open source software written in C to compile has been a pain for decades. There have been some attempts to make it work (notably Cygwin, and now MSYS2), but it can still be challenging, especially with programs that were never designed to be compiled for non-UNIX (or non-Linux!) targets.
Having a C library that is designed from the ground up to target multiple operating systems, and an executable format that means the first compile is the only compile, that takes away a lot of toil that programmers normally have when trying to build their own abstractions around each platform's C library. I guess from UNIX land you could see the benefit as removing the need for autoconf or platform ifdefs.
> I believe the best chance we have of doing that [writing software that stands the test of time with minimal toil], is by gluing together the binary interfaces that've already achieved a decades-long consensus, and ignoring the APIs.
...it's a kind of thought I don't think I could ever come up with. Mind blown.
but yea I agree
I wonder how it handles system calls. Let me check the source...
https://github.com/jart/cosmopolitan/blob/master/tool/build/...
https://github.com/jart/cosmopolitan/blob/master/tool/build/...
> void OpSyscall(struct Machine *, uint32_t);
Pretty interesting... Need some time to figure out how it works.
The system call entry points:
https://github.com/jart/cosmopolitan/blob/master/libc/sysv/s...
https://github.com/jart/cosmopolitan/blob/master/libc/sysv/s...
It uses a jump slot technique which is interesting:
https://github.com/jart/cosmopolitan/blob/master/libc/sysv/m...
System call numbers:
https://github.com/jart/cosmopolitan/blob/master/libc/sysv/c...
https://github.com/jart/cosmopolitan/blob/master/libc/sysv/s...
Looks like it packs the system call numbers of all operating systems into a single constant.
For some reason there are some dedicated implementations of Linux system calls using inline assembly rather than the entry point:
https://github.com/jart/cosmopolitan/tree/master/libc/linux
More related files:
https://github.com/jart/cosmopolitan/blob/master/libc/calls/...
https://github.com/jart/cosmopolitan/blob/master/libc/calls/...
Also funny how it calls Linux "GNU/Systemd"!
Yeah, it would have taken less bits to use GNU/POS instead, because it ain't Linux anymore.
Poettering Operating System.
So in the end, the difference is purely where the platform-differentiated compilation happens for VM & interpreted languages like Java & Python.
This would instead allow you to ship a single Python executable that simply works everywhere. Whether with a bundled-in script/program, or just the interpreter.
But, the paranoid in me is now curious/afraid if this approach can/will lead to multi-OS malware?
Every programmer occasionally, when nobody’s home, turns off the lights, pours a glass of scotch, puts on some light German electronica, and opens up a file on their computer. It’s a different file for every programmer. Sometimes they wrote it, sometimes they found it and knew they had to save it. They read over the lines, and weep at their beauty, then the tears turn bitter as they remember the rest of the files and the inevitable collapse of all that is good and true in the world.
This file is Good Code. It has sensible and consistent names for functions and variables. It’s concise. It doesn’t do anything obviously stupid. It has never had to live in the wild, or answer to a sales team. It does exactly one, mundane, specific thing, and it does it well. It was written by a single person, and never touched by another. It reads like poetry written by someone over thirty.
Her work is always just a little bit trippy in a good way haha.Redbean is a portable, single file executable webserver which also acts as a zip-file for the static content it hosts, and runs on Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS without any recompilation...
You can manage the static content using standard pkzip tooling! Now that's what I call thinking out of the box!
Edited: some rewording and breathing space
And does it run on different architectures like ARMv6?
https://github.com/jart/cosmopolitan/blob/40291c9db386d8a952...
If i have understood how the portability works, it would be pretty straightforward to add support for another OS which uses the same ABI as the unices and has a compatible system call table - just a matter of adding a column to consts.sh (system call numbers in the nr section, constants from system headers in their appropriate sections) and adding any OS-specific system call rituals to systemfive.S.
Note that all system calls will go through the syscall interface. If your OS has some other way to make system calls, like Linux's vDSO or io_uring, that won't be used.
If your OS had a different system call table, like Windows, then you would need to write more bespoke code for it, like all the Windows wrappers:
https://github.com/jart/cosmopolitan/tree/0e85b136ae1beb0d2b...
You would then need to go through the Cosmopolitan libc and add implementations of its functions on top of your wrappers.
Sure, there's server appliances like this, and I hope someone makes a neat services wrapper to abstract at least some platform's intricacies so you can do a "cosmo-service up redbean" on BSD/Linux/Windows.
But coming back to CP/M, there you had a lowest common denominator of terminal applications, too, but spread across different architectures. And you could still produce some quite intersting, if a bit business-like applications. These days you probably can even rely on more ANSI colors and maybe even unicode fonts (hopefull as an option, not mandatory).
The ZIP characteristics of the APE format make it even easier to distribute a whole application in a rather simple way. Yes, sure, you can do regular Unix-style servers and pipe-it-together CLI tools, but I wouldn't mind more self-contained "business" applications with a lo-fi aesthetic regarding interface and API usage. The PICO-8 of TUIs…
Would it be possible to do something similar with Free Pascal, allowing the recreation of something like Turbo Pascal, except really, really portable .com output?
Also hats off to you @jart!
Is this a one time thing or are you thinking of something bigger going with this project?
I had a quick look into doing this on your original thread[1], but got stuck pretty early on and just didn't have the time to get back into it.
If that's something you'd be willing to pursue I'd love to help any way I can. Feel free to DM me on Twitter[2] any time.
chibicc is a really fun idea! If I was in college, I would take a compiler course from you.
Taken from your README:
"chibicc is developed as the reference implementation for a book I'm currently writing about the C compiler and the low-level programming. The book covers the vast topic with an incremental approach; in the first chapter, readers will implement a "compiler" that accepts just a single number as a "language", which will then gain one feature at a time in each section of the book until the language that the compiler accepts matches what the C11 spec specifies. I took this incremental approach from the paper by Abdulaziz Ghuloum."
Github: https://github.com/rui314/chibicc
Previous HN: https://news.ycombinator.com/item?id=24676851
So I would edit my comment to say: I'd love to take a compiler course from Rui, and a systems course from jart.
That's what I get for browsing HN on my phone late at night.
As for holding off on UI for the time being is probably the right thing to do, keeping with the minimal style planning on going for raw-x11,etc.
However, as much as I personally love plain framebuffers (late 90s democoder myself), it'd be totally non-accessible for "plain" applications and totally lacking performance compared to anything accelerated when it comes to rendering. Graphics cards are just so many times faster that it's not really even the same kind of usage (only sad part is Apple punting on OpenGL driver updates even if Intel on the low end has become so much better).
That said, having looked for a minimal UI framework and sadly they seem to be far inbetween these days (libUI is fairly compact on win/osX but required GTK on *nix but they've lost a bit of steam since 2018)
Best of luck on it all (hopefully I can snatch out some time to contribute)
As for GUIs I'm still open to merging raw x11 support. One tricky issue is that we'd need to define a new API that veneers framebuffers, and so far Cosmopolitan has mostly refrained from defining novel interfaces, since the focus has been twiddling with low level magic numbers in order to make the textbook interfaces we already have work everywhere!
Considered making some way to add "portable" modules yet(generic APE code with plat-specific impls) to avoid adding stuff to the core? I know the default calling-conv is slightly different but maybe by smth like defining virtual ports? (ie "send" structs since alignment rules should be mostly the same?)
Centos: [centos@test ~]$ ./redbean.com -vv
error: Uncaught SIGSEGV on test.novalocal
./redbean.com
EINVAL/err=22/errno:2/GetLastError:0
Linux test.novalocal 4.18.0-240.10.1.el8_3.x86_64 #1 SMP
Mon Jan 18 17:05:51 UTC 2021
On the mac:
~ my-Maccie$./redbean.com -vv
Killed: 9On Ubuntu: ubuntu@localhost:~$ ./redbean.com -vv
error: Uncaught SIGSEGV on localhost
./redbean.com
EINVAL/err=22/errno:2/GetLastError:0
Linux localhost 4.15.0-136-generic #140-Ubuntu SMP Thu Jan
28 05:20:47 UTC 2021EINVAL/err=87/errno:2/GetLastError:203 The parameter is incorrect.
Probably the ZIP needs to be saved in a certain format.
This is on Windows 10 19042 build.
7-Zip doesn't even see the folders for that matter.
$ bash -c './redbean.com -vv'
W2021-02-26T01:50:12.665277:tool/net/redbean.c:1144:redbean:3302] setsockopt(server, IPPROTO_TCP, TCP_FASTOPEN, &yes, sizeof(yes)) → EINVAL/err=22/errno:22/GetLastError:0
W--------------------000015:tool/net/redbean.c:1145:redbean:3302] setsockopt(server, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes)) → ENOPROTOOPT/err=42/errno:42/GetLastError:0
V--------------------000022:tool/net/redbean.c:1166:redbean:3302] 0.0.0.0:8080 listen
Visiting http://127.0.0.1:8080/ in my web browser shows a nice redbean page with lobster graphic at http://127.0.0.1:8080/tool/net/redbean.html
but then following usage instructions in another shell: $ echo '<b>hello</b>' >index.html
$ zip redbean.com index.html
adding: index.html (stored 0%)
$ ./redbean.com -vv
Killed: 9
I blame my zip $ zip -v
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
Currently maintained by E. Gordon.
Addition of index.html shrinks(!) redbean.com from size 204800 to size 204348, with changes starting from char 172938. That clearly corrupts the portable executable format. $ bash -c './redbean.com -vv'
W2021-02-26T02:06:29.162953:tool/net/redbean.c:1144:redbean:83621] setsockopt(server, IPPROTO_TCP, TCP_FASTOPEN, &yes, sizeof(yes)) → EINVAL/err=22/errno:22/GetLastError:0
W--------------------000026:tool/net/redbean.c:1145:redbean:83621] setsockopt(server, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes)) → ENOPROTOOPT/err=42/errno:42/GetLastError:0
error:./redbean.com: check failed: 0xffffffffffffffff != 0xffffffffffffffff (48)
6fffffffff70 0000004034cf UNKNOWN
6fffffffff80 000000403225 UNKNOWN
6fffffffffc0 0000004027f3 UNKNOWN
6fffffffffe0 000000402a21 UNKNOWN
7ffeefbff870 00000040227b UNKNOWNThe binary didn't work on Ubuntu 18.04 nor CentOS8 either, but I'll report a issue later on today.
This will also prevent distribution from outside of their appstore giving it will prevent updates.
So as anything Apple, the world security here is being used as code for personal machines remotely controlled by the mothership.
You trade privacy and freedoms for a little convenience.
I think that if an app is correctly codesigned, Gatekeeper has no issue with it. Also if it's not correctly codesigned but you've ticked "allow unsigned binaries", you can still run them.
> the mothership knows everything you run on your machine
I can't remember the details from the last time this came up but IIRC it only sends a hash and possibly even then only the first time you launch it. Either way, they're not going to block out-of-appstore distribution except if you're a known malicious actor.
`sudo spctl --master-disable`
▶ zsh -c './redbean.com -vv'
W2021-02-26T12:12:24.019387:tool/net/redbean.c:1144:redbean:56779] setsockopt(server, IPPROTO_TCP, TCP_FASTOPEN, &yes, sizeof(yes)) → EINVAL/err=22/errno:22/GetLastError:0
W--------------------000028:tool/net/redbean.c:1145:redbean:56779] setsockopt(server, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes)) → ENOPROTOOPT/err=42/errno:42/GetLastError:0
V--------------------000023:tool/net/redbean.c:1166:redbean:56779] 0.0.0.0:8080 listen
^CV2021-02-26T12:12:27.012972:tool/net/redbean.c:1183:redbean:56779] 0.0.0.0:8080 terminatedEDIT: I am an idiot: it's working just fine... the messages looked like an error to me, but visiting https://localhost:8080/ does show a nice HTML page!
sudo spctl --master-disableSince it's a .com file, after downloading, win 10 also claims 'this dangerous file comes from the internet and is blocked' which you have to check a box to unblock it. I did, but still get the errors trying to add to it.
[1] https://github.com/jart/cosmopolitan/commit/218ef491476f15ab...
"This file, pocorgtfo19.pdf, is valid as a PDF document, a ZIP archive, and a HTML page. It is also available as a Windows PE executable, a PNG image and an MP4 video, all of which have the same MD5 as this PDF."
Even if Redbean here doesn't end up taking over the world, I hope that more ecosystems and toolchains sit up and take notice. We need more tools that look like this.
I have been thinking about portable web apps with embedded SQLite for some time. I do not have the technical chops at C level to pull this off. I am really inspired by this project. I hope Redbean leads a way to distribute self-hosted apps in today's era of the cloud.
But having the similar solution with the SQLite, would be a perfect combination.
You have a real talent for distilling the complex into something simple. It’s apparent in the purpose of your programs, in your writing, and in your source code. Thank you so much!
Basics of computing architecture that I didn’t especially think were too complex for me to learn, but we’re too abstracted for me to become interested in, are laid bare in each one of these programs and their source. This is all incredibly exciting.
I had syncthing running and kept getting some error whenever I tried to run redbean. The error didn't make much sense, but eventually I realised that this was the casue of the error.
I'm really impressed how portable this is. The only improvement I can see is if it auto-opened your browser to :8080. That way it would be easy to distribute the binary and have people run your application and just interact with it through their browser. No need to ship electron then!
Oh and listen on 127.0.0.1, not 0.0.0.0. That way your app is not needlessly exposed to the network.
While neat, its not the "best of all worlds" due to the lack of native code on anything other than x86/x64. Also, claiming "bare metal" is supported is a stretch as you are limited to having no I/O of any form (as there is no platform code).
I'm sure the FP zealots will love it :-)
Taking on bare-metal is a significant job much greater than your original task and you may be better targeting something like buildroot instead, after all what is the Linux kernel but a hardware abstraction layer.
> So far bare metal has been a walk in the park. I love the fact that PML4T lets me do things like move memory without copying it.
> I believe it should be possible for programs to be able to boot on metal as just programs which are tiny and auditable.
I would love to be able to learn more about this. Maybe even contribute to your project :) perhaps a good way to start would be to address some small tasks you might have laying around?!
Those concepts are implemented in the Cosmopolitan codebase here: https://github.com/jart/cosmopolitan/blob/master/ape/ape.S
That file runs a few hundred lines of old school assembly in order to bring us into the modern era. Towards the end of the file you'll notice it starts calling functions that are written in C which configure memory: https://github.com/jart/cosmopolitan/blob/master/libc/runtim...
After it configures memory, the ape.S file is able to call _start(). It also sets a bit in __hostos so that functions like write() know to use the serial port instead of issuing system calls: https://github.com/jart/cosmopolitan/blob/master/libc/calls/... That's the simplest possible example of a driver with spin locks which uses the x86 IN/OUT instructions.
If you want to take a dive off the deep end right now with Cosmopolitan on metal -- simulated -- then try the following build commands on your Linux terminal:
git clone https://github.com/jart/cosmopolitan
cd cosmopolitan
make -j8 o//examples/hello2.com
qemu-system-x86_64 -m 16 -nographic -fda o//examples/hello2.com
sed -i -e 's/USE_SYMBOL_HACK 0/USE_SYMBOL_HACK 1/' ape/ape.S
make -j8 o//examples/hello2.com o//tool/build/blinkenlights.com
o//tool/build/blinkenlights.com -rt o//examples/hello2.comWorking on one bare metal system is relatively easy as long as you're willing to dive into drivers. Getting 1001 I2C drivers or maybe writing a drivers for tens of different types of flash devices is a different matter.
Your project will quickly become overrun with drivers for literally tens of thousands of devices... then comes maintenance.
Look at the Linux source tree... Good drivers are not trivial either. Simple ones are of course.
Basically, its a time-sink and it doesn't become useful for claiming "portability" until you're approaching the scale of something like Linux.
Wonder how far something like that could go, could be really interesting for replacing bash for me with something easier to write like JS.
A single executable, that doubles as a valid ZIP file, that you can put a complete website into, also doubles as a valid executable on Windows, Mac, Linux.
The build infrastructure is a complete reworking of C to make it far more portable than even K&R thought possible.
I probably wouldn't have believed it possible, but here it is!
This is a zip file, like any other... you can add and remove things from it. However, this ZIP file has a superpower, it can display the contents on the web... it has a web server built into it.
You can take this file, run it on a Windows, Linux, Macintosh, and it will work. You don't need separate versions for each different system... this just works on all three systems, unlike almost every program ever written.
This is one of the most impressive feats of programming things I've seen in my 40+ years of programming. The web serving is clever, but the superpower that it can run on anything really took a huge amount of work, which the author built into a tool called "ape", and has shared with the world, so other people can use it, and help her make it better.
Don't ELF need "0x7F ELF" header? Don't Windows executable need "MZ" header? How is it fulfilling both requirements simultaneously?
anyone else had luck with adding stuff to it? is it just me? or is it like "it works with openbsd zip command only"?
I would highly recommend using chibicc. Bellard's work on tcc was fantastic when it came out. However it didn't age well. Its GNU extension support is roughly equivalent to GCC 2.x. The x86_64 support that got bolted on later isn't very good. It was much more elegant back when it was only doing i386. Hackability was also laid low by merging a lot of external contributions. The TCC design, while amazingly fast, also carries the tradeoff of making things like inline assembly hacks really hard because it generates the x86 binary content directly, rather than going through the intermediate step of generating an assembly file and running it through a proper assembler -- which chibicc now has!
W2021-02-26T05:00:59.959364:tool/net/redbean.c:1141:redbean-2021-02-25:49336] setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) → ENOPROTOOPT/err=10042/errno:10042/GetLastError:0
W--------------------000674:tool/net/redbean.c:1145:redbean-2021-02-25:49336] setsockopt(server, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes)) → ENOPROTOOPT/err=10042/errno:10042/GetLastError:0
Its amazing if works though, i can put my static site in an exe. That is so cool.EDIT: Runs on without modifying even with this message.
EDIT: Cannot modify zip on windows. "File not found or no read permission" using explorer. With 7-zip "Operation is not supported."
EDIT: Used WSL to update zip which then results in SIGSEGV
this is delightful
Will I be able to write apps in a single language and have then run truly native on any OS or what else will we be able to do?
The more interesting thing I think is the mapping of C library functionality between Linux, BSD and Windows. There have been other attempts to do this, but they never seem to get much traction. I think it's because C programmers tend to get wedded to their OS of choice and then invest time in improving that platform's C libraries. The problem with trying to remain portable with everything is that you tend to be stuck working with the lowest common denominator functionality, which can be frustrating when doing OS-specific stuff would open up so many more options.
All that said, the cleverness of this project is inspirational in a way that might encourage other programmers to also focus more on building against simple functionality that is truly portable. It shows that you don't need all the bells and whistles to build cool stuff. That feels aligned with early UNIX philosophy and (more broadly) the hacker ethic, which is why it's neat to see, even if never gets adopted as a mainstream thing.
I've been banging my head against the wall of trying to make a micro KVM guest and the glibc startup code uses inline SYSCALL everywhere, I assume to make things faster. It does seem to call CPUID a lot too, but I guess it's not as expensive as having to make full-blown system calls.
Can you blog a bit of the career/cognitive/skill evolutionary history behind this? Did the cosmo stuff come out of this or something else?
Learned this in X level school, found out about Y, read about Y, learned this, got this job doing this, learned this from Z, got experience of AA... etc.
Of course, assuming this exists, and you exist. And blogs "exist".
1. <https://wiki.triplescripts.org/wiki/The_why_and_how_of_tripl...>
2. E.g., <https://www.youtube.com/watch?v=TUpd70Mu0Ek>
Can someone elaborate on the relationship between gzip and kernel space copies?
Good lord this is cool
I love the reference to the Swedish Rhapsody numbers station at the end of consts.sh
Can somebody, please, explain if allowing code morphing will increase security risks?
> Is the Cosmopolitan Runtime lean and mean like Go's 2mb Hello World executables?
:-)
run-detectors: unable to find an interpreter for ./printimage.com
sudo sh -c "echo ':APE:M::MZqFpD::/bin/sh:' >/proc/sys/fs/binfmt_misc/register"
I intend to upstream a patch with the Linux kernel so it can do this automatically. If any kernel devs are reading, please email me!I think that's because I have WINE installed in the Archlinux VMs, since that's what gets started when I run ./redbean.com. But even after I remove WINE, it still doesn't work, I probably have to restart (i.e. remove WINE from the TemplateVM, not the AppVM) for it to work.
In any case, incredible work, I am in awe!
From the same person I think
> We're software producers of a different kind. Rather than market software the usual way, we openly deny its existence, and challenge our customers to do the same.
But if some least common denominator was found to be able to create window, add some input fields and buttons using the native UI elements of the OS?
Does the Win32 and Cocoa APIs for example, also have "magic numbers" that are kept stable?
This is a cross platform web server, not a cross platform web browser.
I know this is x86_64, and have an am64 system. Does this only run on intel and arm architectures?
Does this use the same exploit in memory that spectre used for intel processors?
The webserver is novel but I am just wondering, how would it compare to something like Apache/ISS in terms on security/config/etc, or is this mostly just to move small sites around?
Congrats on reading my mind and making what was supposed to be impossible?
I get bash: ./redbean.com: No such file or directory
after chmod-ing.
Maybe I am dumb but yeah.
The idea also reminds me of (executable) self-extracting ZIP archives that were common once upon a time.
6ffffffffe30 0000004025db UNKNOWN
6ffffffffe40 0000004023a7 UNKNOWN
6fffffffffb0 000000401862 UNKNOWN
6ffffffffff0 000000401ed1 UNKNOWN
Run on ubuntu 14? There's nothing running on :8080. Not sure what I'm going wrong.
Nope... it's native code, that runs on multiple platforms, all in one small executable.
How? Lots of very clever hacking, and trimming all the accumulated dreck out of the normal C runtime, while making it work across all the supported platforms. (Polyfill is the term she uses)
This is the most amazing thing I've seen in a decade or so. It is right up there with GIT in terms of the possibility space it opens up.
Admittedly they solve different usecases, where Redbean seems to want to serve a whole static site as a single file, which isn't currently possible with Caddy, (but you can run `caddy file-server` to serve the current directory as a static site), but it may become possible in the future with Golang's new embed package https://golang.org/pkg/embed/
All this would be roughly 15 lines of code.
Thanks for sharing.
You are affiliated with Caddy and ought to mention that when you promote your own software. https://news.ycombinator.com/item?id=16687686
This is not a competition. Caddy is not even in the same realm as Redbean.
Redbean is a multi-platform binary that doubles as a ZIP. It's roughly 1500 times smaller than Caddy too.
> different usecases
Right. :)
What? Of course not! You're reading way too much into that. It's simply enthusiasm. I read about Redbean and it being a single file webserver and the first thing to come to mind is Caddy, as "prior art".
Like I said, different usecases; Caddy is a general purpose webserver which has automatic certificate management, H2/H3 support, reverse proxy, file server, a strong plugin system, the list goes on. Of course it'll be bigger in size. Redbean is super cool and does have the advantage in file size and portability, clearly, but it is essentially a single-purpose tool. And there's nothing wrong with that.
I see a lot of people making the comparison between this and the OG Linux tools. I absolutely don’t think this qualifies as one, most old Linux tools are irreplaceable or at least were when they first came out and there were no alternatives. Serving a bundled zip file on a web server across many different platforms is not something people are dying to do. You can run a web server like nginx or Apache to index your files or if you really hate those why not a single line command which is supported on almost any platform:
python -m http.server 8080
[0] https://github.com/llamasoft/polyshellThis zip file is an executable webserver, you just add files to it and it will serve them when you run it.
If you can't understand what is cool about that maybe just don't speak.