Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building against cosmopolitan libc #837

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

jjsullivan5196
Copy link
Contributor

@jjsullivan5196 jjsullivan5196 commented May 29, 2024

Accompanies the same changes in the racket repo racket/racket#5004

This was originally a patch just to get racket to build on cosmopolitan libc, which unfortunately would require more heavy lifting in the main distribution to work. I took what I had there and made it so that at least Chez will work more or less as advertised, a single binary that can hit many common operating systems on amd64 and aarch64, with no installation required.

See the cosmopolitan project page for more information https://github.com/jart/cosmopolitan

@mflatt
Copy link
Contributor

mflatt commented May 30, 2024

These changes seem ok to me. The change in c/prim5.c is a general improvement and correction, and the defined(__COSMOPOLITAN__) tests seem like a low maintenance burden.

With these changes and a small adjustment to lz4/lib/Makefile (expand the command that uses -c $^ to four separate commands), I was able to build with

./configure --pb CC=/path/to/cosmocc CFLAGS=-O2 AR=/path/to/cosmoar --disable-curses

or specifically for x86_64 with

./configure CC=/path/to/x86_64-unknown-cosmo-cc CFLAGS=-O2 AR=/path/to/x86_64-unknown-cosmo-ar --disable-curses --disable-x11

Leaving out --pb and using plain cosmocc/cosmoar leads to an error about x64_64 inline assembly when trying to compile for Arm64. I imagine that's expected and that the cosmo tools need to be used in a different way to support both x86_64 and Arm64 at the same time.

@jjsullivan5196
Copy link
Contributor Author

jjsullivan5196 commented May 30, 2024

Hi @mflatt ! Actually that change to the makefile wouldn't be necessary, cosmocc's platform specific compilers already work with Chez's existing cross compilation pipeline. The bit about compiling the 4 objects at once is only a problem with the cosmocc wrapper script, which can't be used to do the cross compile anyway.

I have a different branch that includes building for CI, I just haven't had a chance to clean it up yet. The build script works and creates an image that runs on amd64 and aarch64

@jjsullivan5196
Copy link
Contributor Author

jjsullivan5196 commented May 30, 2024

@mflatt I pulled the CI scripts into this PR. If it would be too much hassle to maintain I understand, but I thought it would be illustrative at least.

The build artifact is scheme.com, which bundles the amd64+aarch64 ELF images, the Chez boot and the rest of the release files. These all load from the executable file itself.

The name is a convention in the cosmo community, since .com is the conventional file extension for MZ executable wrappers on windows, but the name can be changed here if needed.

To note, I did test scheme.com and a small REPL session with SLIB on linux-amd64, linux-aarch64 thru qemu-aarch64-static /opt/cosmocc/bin/ape-aarch64.elf scheme.com and windows10-amd64. This should also work the same on the other supported platforms https://github.com/jart/cosmopolitan?tab=readme-ov-file#support-vector

@jjsullivan5196 jjsullivan5196 marked this pull request as ready for review May 30, 2024 16:46
@jjsullivan5196 jjsullivan5196 force-pushed the cosmolibc branch 3 times, most recently from c2bdd7a to 95977aa Compare May 30, 2024 18:02
@jjsullivan5196
Copy link
Contributor Author

jjsullivan5196 commented May 30, 2024

One last change, since dynamic linking thru dlopen is only in experimental support in cosmopolitan, I disabled it explicitly for the platform. This only takes effect when building with cosmopolitan.

@mflatt
Copy link
Contributor

mflatt commented Jun 12, 2024

@jjsullivan5196 — Thank you for the updates, and sorry for the long delay!

As you anticipated, the CI scripts seem like more than we'd want to take on right now. But they do seem usefully illustrative, and I wonder how we can keep them in the record for future reference. I'd like to merge the rest, and we normally merge changes using "Squash and merge" and keep the PR number in the commit message. So, whatever would keep them in this PR (and not in the result) would be good. Attaching the scripts as files to a comment?

@jjsullivan5196
Copy link
Contributor Author

Hi @mflatt

No worries on the wait, this was more a hobby interest than anything, but always happy to get a really great scheme more places! I force pushed out the CI scripts, but kept them in a separate branch here jjsullivan5196@4b87fe2

Also as for properly preserving these, there's a software distribution that was made by one of the cosmo maintainers, I think that might be the most appropriate place to keep that information permanently. I'll work on a patch and send it to them, and update this thread if it gets accepted https://github.com/ahgamut/superconfigure

@mflatt mflatt merged commit 089a481 into cisco:main Jun 13, 2024
@mflatt
Copy link
Contributor

mflatt commented Jun 13, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants