Live data from Hacker News

Show HN: Redbean – Single-file distributable web server

justine.lol

171–180 of 264 posts

Re: Show HN: Redbean – Single-file distributable web server

#171
post #8

The short description is a bit too short; this is mind blowing! 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…

Is it that this binary does some tricks to run on Linux, Mac, Windows, FreeBSD, OpenBSD, NetBSD, BIOS or does it really work on all operating systems including something like Plan 9 or even TempleOS? And does it run on different architectures like ARMv6?

Native execution on x86_64 only. "Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS", where "BIOS" means that it will boot a machine and run on bare metal. On non x86_64 systems, the driver script will try to run the binary using QEMU (which has to be installed and on the path):

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.

Re: Show HN: Redbean – Single-file distributable web server

#172
post #161

Earlier quoted context omitted.

Sorry, wasn't meant as a criticism, just as an explanation because people were assuming magic... 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.

How hard could stdio/sockets on metal possibly be? 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 want to be able to have that power without schlepping in the entire Linux world. I believe it should be possible for programs to be able to boot on metal as just programs which are tiny and auditable. Especially considering everything run…

Its not the difficulty, but the scale.

Working 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.

Re: Show HN: Redbean – Single-file distributable web server

#173
post #149

Hmm, somehow I knew Justine is a 'transwoman' by this feat. Lucky guess I suppose... Question: if all the high achieving women in tech end up being 'transwomen', is that a step forward or backward for women in tech? Will 'transwomen' be able to take advantage of hiring privileges given to normal women? If so, won't this effectively shut normal women out of tech even more? I think trans/self identifying people should…

Sincerely: what the fuck is wrong with you?

Re: Show HN: Redbean – Single-file distributable web server

#174
post #9

.apk files and .ipa files are secretly zip files too. With the addition of a few manifest files and other crufty things embedded in the zip, I bet you could add Android and iOS to the list of supported platforms too.

Jars, rpms, whls, Microsoft Office, probably a bunch of other stuff I don’t even know about are actually zip files.

.epubs too!

Re: Show HN: Redbean – Single-file distributable web server

#175
post #161

Earlier quoted context omitted.

How hard could stdio/sockets on metal possibly be? 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 want to be able to have that power without schlepping in the entire Linux world. I believe it should be possible for programs to be able to boot on metal as just programs which are tiny and auditable. Especially considering everything run…

Its not the difficulty, but the scale. Working 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…

You're confusing portability with requirements. I'm aware that a long tail exists. Linux is a big tent for that sort of thing. I think that's great. I also want the freedom to live outside that tent during the times when all I need are the other 85% of use cases, which as I've shown, can be easily achieved by just one person. I don't believe that just because I ship actually portable executables that are able to do e1000/virtio that every hardware manufacturer is going to be kicking down my door eager to get support for their silicon merged. Linux is already doing a great job at that and I think Cosmopolitan is complementary.

Re: Show HN: Redbean – Single-file distributable web server

#176
post #42

Am I the only one having issues trying to get this working? The webserver starts just fine, but once I add the index.html with zip as in the example, it stops working. This is on Mac 10.15, CentOS 8 and Ubuntu 18.04 LTS. 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 Ja…

On Mac Big Sur it doesn't seem to work either:

    ▶ 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 terminated

EDIT: 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!

Re: Show HN: Redbean – Single-file distributable web server

#177
post #169
post #161

Earlier quoted context omitted.

How hard could stdio/sockets on metal possibly be? 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 want to be able to have that power without schlepping in the entire Linux world. I believe it should be possible for programs to be able to boot on metal as just programs which are tiny and auditable. Especially considering everything run…

As someone who knows programming in higher level languages well but has no experience with low level, bare metal, how can I get started with this stuff you're working with? > 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 audit…

And I would love to encourage you to do so! If you're working for Cosmopolitan then I'll be working hard to support you. There's a long history of depth to metal. Many people start off learning it by having fun with the old skool ibm pc boot process. Here's a gentle introduction: https://justine.lol/blinkenlights/realmode.html and https://github.com/jart/sectorlisp and http://reddit.com/r/osdev

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.com

Re: Show HN: Redbean – Single-file distributable web server

#178
post #13

I really like your view of the world, that programs should be portable, tiny, and just work. The slamming of so much functionality into a zip file is inspiring. 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?

Author here. Absolutely. I used to love Turbo Pascal and Delphi when I was younger. If Free Pascal uses GNU LD.BFD or LLVM LLD when it links programs, then all you'd need to do is is configure it to use cosmopolitan.a when linking system call functions like read(), write(), etc. See https://github.com/jart/cosmopolitan Another option is if Free Pascal wants to write all the system call support from scratch, then doin…

Now you can port Slashem to more platforms than Nethack 3.4.3 itself :D

Re: Show HN: Redbean – Single-file distributable web server

#180
post #173
post #149

Hmm, somehow I knew Justine is a 'transwoman' by this feat. Lucky guess I suppose... Question: if all the high achieving women in tech end up being 'transwomen', is that a step forward or backward for women in tech? Will 'transwomen' be able to take advantage of hiring privileges given to normal women? If so, won't this effectively shut normal women out of tech even more? I think trans/self identifying people should…

Sincerely: what the fuck is wrong with you?

Isn't it a legitimate question? We have special protection for under represented groups. So when the dominant group starts taking the identity of underrepresented groups and coopting their protections, they are no longer protected. The two things are at odds with each other.
Post reply on HN