I tried zig build-obj to complie a simple Hello World into a main.o ELF (both amd64 and aarch64) file and then called Cosmo linker to glue things together but it did not work.
I could share my code and commands but I know so little of zig that I’m pretty sure they don’t won’t add much. My end goal is to write a tiny wrapper for a cli tool. This wrapper runs on any OS, it downloads the correct CLI from GitHub, unpacks and runs it.
I would start with understanding what cosmocc does under the hood (e.g. which target-triple it is using):
…and then try to replicate those exact compilation settings in the Zig compiler (my uneducated guess is that it’s mainly about making sure that the Zig-compiled code uses the same target triple expected by the cosmo-linker).
PS: also this ‘fixupobj’ command in the link above seems kinda important…, don’t know what this does though.
Sounds cool. @flooh linked to the only thread on APE and Zig I’ve seen, I suspect you’re pretty far off the beaten path with this one.
I’d suggest getting to know the language and build system a bit better first, link in some C libraries, call them from Zig, and then take another crack at adding the more exotic Cosmopolitan build.
Be sure to tell us how it works once you figure it out