yihong0618 和朋友们的频道 头像

消息来源频道

yihong0618 和朋友们的频道

@hyi0618

频道8,612 位成员公开可见0 人在线

yihong0618 和朋友们的频道

成员规模8,612 位成员
在线情况0 人在线
消息总数10,129 条消息
浏览量总数3,281,861 次浏览

在这个频道里搜索消息……

t.me/hyi0618

TIL:
Link: https://github.com/simonw/til/blob/main/cosmopolitan/ecosystem.md
📌 Catching up with the Cosmopolitan ecosystem
I caught up with some of the latest developments in the ecosystem around Justine Tunney's cosmopolitan and Actually Portable Executable (APE) projects this week. They are absolutely fascinating.
An Actually Portable is a wildly clever hack. It's a single binary file which can run as an executable on multiple platforms - on x86-64 Linux, macOS, Windows and various BSDs, and for ARM-64 on Linux and macOS too (macOS ARM-64 is a recent addition).
Some posts that help explain how this works:
⦁ αcτµαlly pδrταblε from August 24th 2020 explains the initial hack
⦁ APE Loader from June 11th, 2022 explains some of the more recent internals
Pretty much anything written in standard C can be turned into one of these things, using the cosmocc compiler something like this:
./configure CC=cosmocc
make
make install
cosmocc -o executable.com hello.c
Then run ./executable.com on any of the above platforms to run the program!
There are a whole bunch of components to this.
Cosmopolitan is probably the most important. It describes itself as a "build-once run-anywhere C library" - it includes both the cosmocc compiler and implements a bewildering array of system call wrappers to get everything to work cross-platform.
✏️ Trying out redbean
redbean is one of the most interesting applications built on top of Cosmopolitan. It's a "single-file distributable web server" - you download redbean-2.2.com and run it to start a server (on any of the supported operating systems), but it also acts as a zip file - so you can load your own files into that archive for it to serve, or provide it with Lua code that it can execute as well. And it bundles SQLite. It's really cool!
To use it on macOS you have to dance around the security settings a little bit. Here's how I got it working:
# Download the redbean binary
curl -O https://redbean.dev/redbean-2.2.com
# Make it executable
chmod +x redbean-2.2.com
# Try to run it the first time
./redbean-2.2.com
This triggers a security warning:
<img width="284" alt="redbean-2.2.com cannot be opened because the developer cannot be verified. macOS cannot verify that this app is free from malware. Firefox downloaded this file today at 4:44 PM. Move to Trash" src="https://github.com/simonw/til/assets/9599/c4004948-6aba-4a3e-b916-d9f39c0627f7">
To work around this, go to System Preferences > Security & Privacy > General and click "Allow Anyway" next to the warning about the redbean binary:
🖼Screenshot of the
Now try ./redbean-2.2.com again and it should show this:
<img width="285" alt="macOS cannot verify the developer of redbean-2.2.com. Are you sure you want to open it? By opening this app, you will be overriding system security which can expose your computer and personal information to malware that may harm your Mac or compromise your privacy. Firefox downloaded this file today at" src="https://github.com/simonw/til/assets/9599/9b446b99-6f42-4da1-8a5d-bc309cb3b1d4">
Click "Open" and it will run. Then visit http://localhost:8080/ to see it in a browser:
<img width="536" alt="redbean/2.2.0 and a file listing in a browser" src="https://github.com/simonw/til/assets/9599/5738cb24-6e15-435f-a721-4926e0d61edf">
✏️ redbean.systems - an online compiler
One of the latest additions to the ecosystem - in the last couple of months - is redbean.systems - which offers an online compiler that can accept C code and turn it into a downloadable APE executable fil