Hacker News new | past | comments | ask | show | jobs | submit login
Cosmopolitan v3.1 (twitter.com/justinetunney)
136 points by sgammon on Nov 20, 2023 | hide | past | favorite | 37 comments



What’s the use case?

I have mad respect for cosmo & what technically it’s accomplished.

But I also haven’t figured out the problem per se it’s solving.

I’m genuinely curious to hear how others use cosmo.


Even without the syscall dispatch, it's a very well optimized standard C library that you can statically link.

Although personally, the lack of dynamic linking or GPU acceleration makes it a hard sell for my projects, unfortunately.


This release added cosmo_dlopen, which works on many platforms (but not all).

Should be enough to allow you to find the vulkan loader and dlopen that. I'm not sure what you would do on mac, statically link moltenvk? Or maybe it would be better to use OpenGL on all platforms, and be stuck with OpenGL 4.1 (which isn't too bad, but it would be nice to have image load/store).


Omg that's huge!


FWIW, there is ongoing work on dlopen; it was introduced 2 weeks ago (https://github.com/jart/cosmopolitan/commit/5e8c928f1a37349a...) and continued after that.


Build once against a universal libc layer, and produce universal binaries which run on a variety of different architectures and operating systems.

It’s like LLVM or JVM but even for C, and without the overhead of virtualization.

(Hope I did it justice I am merely a fan)


Yes, but who builds binaries this way and what do they use them for?


Even though GitHub Actions did wonders for people to be able to build their software in multiple platforms, you still have to run one build per platform and distribute one file per platform. If you could run a single build instead (and be confident that Cosmo guarantees that if it works on one, it works on the others, which may be difficult of course) and distribute a single file, that would make things much simpler and more efficient. You could save a lot of electricity if you run builds on premise (not to mention it's good for the environment). I can't believe people don't see a value in this.


Malware.

Most binaries that I have seen in the wild use cosmo/ape binary format to have "free obfuscation" that is hard to analyze by antivirus and EDR software due to its mutating self-extracting pkzip-like behavior.

Well, and of course CLI tools. I guess it's the same selling points that fit golang as well - aside from cosmo's binary format having a universal header.


>hard to analyze by antivirus

Isn't it just a matter of updating the AV to be aware of this format? It's not like APE is the only "weird" binary format that exists, since there's stuff like UPX (which is indeed flagged by many AVs).


I absolutely would use this for workshops I give, where users bring a variety of oddball hardware and want to do things like run FPGA synthesis or run software that pokes USB packets to communicate with debug endpoints.

In the past I've made sure to build for each platform in CI and distribute USB drives, and this just makes it one notch easier by letting me ship the same binaries to everyone.


Honestly - CLI apps that need to run on multiple platforms. I once built a version of https://github.com/lovebrew/lovebrew (back when it was written in Nim) using Cosmopolitan 2, and I got back a single binary that ran on all major operating systems.

This greatly reduces the time GitHub actions would need to run, as you just build and release for one OS. As others have mentioned, this does not really work for native GUI apps, that isn't supported by Cosmopolitan as far as I know. But for small CLI tools it works great!


Python wheels are one use-case I’m excited about.


And nuitka.


I imagine portable apps might be nice. It would be cool to be able to create a flash drive with universal PGP toolkit. We're limited to console apps, though.

It would be amusing to use it to create X servers – after all, we have sockets.


I've been dying to play with cosmopolitan for a while while working on a micro-Lisp and another interpreted language that I've been designing for a while.

Imagine writing an interpreter that's compiled with cosmopolitan, you bundle it with your program source code, and bam! your script runs pretty much everywhere, even on bare metal. How cool is that? I could distribute my apps written in my niche Lisp to anyone, without having to write a JIT, or incorporate LLVM, or asking them to download and compile my interpreter from github. Here's a binary, just run it (if you trust me :)

To me it's mind blowing, and I have enormous respect for the work of Justine and her collaborators.


> a micro-Lisp and another interpreted language that I've been designing for a while

> bundle it with your program source code, and bam! your script runs pretty much everywhere

> How cool is that?

Extremely cool! I've got a small lisp too and cosmopolitan inspired me to work on similar stuff. Seems I'm not alone.

While cosmopolitan's PKZIP support is impressive, I've been perfecting an alternative method to embedding source code inside the lisp interpreter executable that's more tightly integrated. Cosmopolitan libc opens the executable and reads the data from the filesystem. I want the data to already be mapped in before execution even starts.

I only target Linux so I get to take full advantage of the ELF format: concatenate the data to the ELF and add a PT_LOAD segment for it so that Linux loads it onto memory automatically. So far my work has resulted in a new feature being added to the mold linker and and a couple stackoverflow questions. Just submitted a pull request to the patchelf utility too.

Once it's working, I'll write an article about it and submit it here.


> concatenate the data to the ELF and add a PT_LOAD segment for it so that Linux loads it onto memory automatically

I was reading Justine's Github profile, and there was a mention of POSIX systems natively supporting shebang programs made of binary + appended data out of the box. I don't remember the specifics, might be worth investigating how that works exactly.


Yeah, she actually got that feature standardized. Apparently it's a binary version of the feature used in those self-extracting installer .run scripts.

I finished the embedded segment loading feature by the way. I'm writing that article as promised but if you'd like to check it out ahead of time:

https://github.com/lone-lang/lone/blob/master/source/tools/l...

https://github.com/lone-lang/lone/blob/master/source/lone/au...

https://github.com/lone-lang/lone/blob/master/source/lone/se...

https://github.com/lone-lang/lone/blob/master/source/lone/mo...


One thing I’ve found useful is that you can attach a zip, and the files in it that zip can be opened with open() as normal. This makes it easy to wrap multi-file Python apps (or other languages) as a single executable.


Sounds like a perfect use case for multiplatform Mirai, single binary.




Neat, they also launched a repo for these universal binaries [0]. It took a little digging, but the list of binaries are here [1]. Might be useful for a universal install script?

0: https://cosmo.zip/ 1: https://cosmo.zip/pub/cosmos/bin/


Does Cosmopolitan support Android yet? It would be nice to have an alternative to the NDK


If I am correct in my understanding of how it works, Linux versions should work on Android as well.


The Linux system calls used by cosmopolitan work fine on Android provided they aren't blocked by seccomp policy. Some of those blocks make sense, others not so much. Yesterday I discovered I could use all the stat variants but not statx.

I believe the features provided by standard C libraries are well covered by the set of allowed system calls.


Android is kind of a special child, it uses custom kernel modules like Binder (IPC framework) and Ashmem (Android's garbage collector/memory manager).


A few weeks ago I tried building cosmopolitan inside a Termux environment but the makefile didn't like it. At the time I gave up and used my laptop because I was focused on developing a feature. I wonder if I could get it to work now.


Using this, is it possible for live running application state on one device to be sent to another device, esp if running a different OS?


No, to my knowledge cosmopolitan doesn't provide any special provisions to support this, so you'd have to build it yourself.


Oops they did it again! Massive fan, and I use it!


Does this work for platform/architecture independent docker images? I tried a little with the python universal binary, but I think the CMD line would be platform specific?



That post is the release link on GitHub, while this is the announcement by @jart on X and a showing of performance gains in GitHub Actions CI

I found the performance gain to be significant enough to be interesting and so I posted.


Dang may correct me on this. But it isn't a Dupe if the other one hasn't reached front page.


It's a woolier 'significant attention' but things like 'two comments' or 'never on the front page' tend to count for undupeness.

https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: