Early work experimenting with zig as a cross-compiler for OCaml

Thank you for suggesting zig as a good choice for a C cross compiler!

I just checked that the cross-compiler support that was merged upstream (and that I backported to 5.3 if you want to give it a try on the stable release) is compatible with that and indeed it is! You can get a cross compiler with just:

$ ./configure --target=aarch64-linux-gnu \
    'CC=zig cc --target=aarch64-linux-gnu.2.34' \
    'PARTIALLD=zig cc --target=aarch64-linux-gnu.2.34 -r' \
    'AR=zig ar' STRIP=:
$ make crossopt -j

Here is the log for that configuration.

So I had to experiment with something more tricky, namely a Linux x86_64 to macOS aarch64 cross compiler. Building the cross compiler, using:

$ ./configure --target=aarch64-apple-darwin \
    'CC=zig cc --target=aarch64-macos' \
    'PARTIALLD=zig cc --target=aarch64-macos -r' \
    'AR=zig ar' STRIP=: --disable-shared

worked fine but then compiling a small program fails with a long list of linking errors:

error: symbol _caml_startup.code_end not attached to any (sub)section
    note: while parsing /tmp/camlstartup41b4bf.o
error: symbol _camlStd_exit.code_end not attached to any (sub)section
    note: while parsing /home/runner/cross/lib/ocaml/std_exit.o
error: symbol _camlExample.code_end not attached to any (sub)section
    note: while parsing example.o
[…]

You can see the full CI log for details. Do you have a clue about what is broken there?
(I’ve found this similar error, maybe it’s much more general than my simple attempt; so I hope it might be fixed in the next zig release).

2 Likes