rust-ape-example icon indicating copy to clipboard operation
rust-ape-example copied to clipboard

I made some progresses

Open crisidev opened this issue 7 months ago • 7 comments

Hello, First of all, thanks a lot for this repo! Without it, I wouldn't have known where to start.

I resurrected it in a fork and managed to compile a working version of ripgrep and dog.

All my findings are detailed here: https://blog.crisidev.org/tags/series-one-bin-to-rule-them-all/

After I have cleaned up a bunch of things, I'll release all the forks I needed to patch to make it work.

crisidev avatar May 04 '26 16:05 crisidev

Awesome work!

From previous experiments, I believe https://github.com/ahgamut/rust-ape-example/issues/3 is still a relevant issue (and the linked blog post agrees with that view). Is there a repo or CI result somewhere where we can see the APE binaries running on Windows / MacOS?

Also, submit a PR!

ahgamut avatar May 04 '26 17:05 ahgamut

In the first post of the serie, you can download the result executable (with a big disclaimer that you should run them in a VM and don't trust me 😉)

I had to fork a bunch of things and I still have to cleanup the libc and stdlib patches needed to reproduce this.

I hope to have some time to do this over the week and post the results here..

crisidev avatar May 04 '26 17:05 crisidev

And yes, I believe #3 stands correct because most of the patches are about making constants extern to allow the linker to fish them out of Cosmo libc.

crisidev avatar May 04 '26 17:05 crisidev

I have created a MR (#7) with the changes required to the example to work on recent rust nightly, while I cleanup the repo that is able to build dog and ripgrep

crisidev avatar May 05 '26 14:05 crisidev

Repository with the repro: https://github.com/crisidev/ape-rs

CI/CD is set to run on tags and generate releases with rg, dog, xh and probe.

crisidev avatar May 06 '26 14:05 crisidev

Nice! Have you gone through @io12's work here? That was the most recent attempt I knew of before this.

ahgamut avatar May 07 '26 01:05 ahgamut

Nice! Have you gone through @io12's work here? That was the most recent attempt I knew of before this.

I haven't, thanks a lot, it's so cool.

crisidev avatar May 07 '26 10:05 crisidev

Wonderful job! I also gave it a try a long time ago. I managed to make synchronous HTTPS requests using ureq + rustls (["ring", "std", "tls12"]) on Linux x86_64/aarch64, Windows and MacOS (Have not test on other platforms).

If I remember correctly, I only ran into two annoyances:

  1. ring compiles some code, and the editor would complain that the current toolchain is not a valid target triple. I had to rename the toolchain to an existing <arch>-unknown-linux-musl (which didn't seem to have any side effects).
  2. ring depends on libc, and you need to patch quite a few constants that differ across platforms (I saw this mentioned in your blog post as well).

Oh, one more thing — I also hit a nasty pitfall on aarch64 Linux. The program would occasionally crash at runtime. It turned out that cosmocc reserves the x28 register for TLS (thread-local storage), but the Rust compiler happily uses x28 as a general-purpose callee-saved register in the code it generates, so the value gets clobbered unexpectedly. In the end I had to tell the compiler to reserve that register. https://github.com/jart/cosmopolitan/issues/1416

starccy avatar Jun 19 '26 19:06 starccy