On Sat Jul 17, 2021 at 7:30 AM CEST, Lutz Haseloff wrote:
both binaries work in my system. (Galaxy A50, Userland, Kali Linux)
On Sat Jul 17, 2021 at 10:47 AM CEST, jdh wrote:
Both binaries you provided ran successufully. I ran them both and they both exited with a 0 return code, when invoked with only the --help options.
System ran on: HW: Raspberry Pi 4 Model B Rev 1.4 CPU: ARM aarch64 RAM: 8GB SSD: 1TB
OS: aarch64 - Raspberry Pi 64 bit OS. Based on Debian/Linux 10
Lutz, jdh, thanks for testing, great to hear that it works! Although now it remains to apply this technique to LuaMetaTeX. Without access to source code I can't try anything, but the general ideas should apply: I used Zig for cross compiling. While Zig is a full fledged programming language in its own right, it also has the ability to compile C/C++ (with built-in Clang). The more interesting part is that it also bundles different C libraries for the different targets it supports for cross compilation. This is a great match for Lua(Meta)TeX, because standard C library is the only "external" dependency. Depending on the chosen target (CPU+OS+ABI triple), the binary can then be fully statically linked or dynamically linked against the target's system C library. Zig exposes the "C compiler" functionality with two interfaces: the Zig build system and the "zig cc" command. In theory "zig cc" should be a drop-in replacement for "clang" or "gcc" [1] and therefore should be usable with existing build systems used by LuaTeX/LuaMetaTeX. In practice it is not that easy, because some "compiler feature detections" of these build systems often try to run compiled results (and fail). But in the best case (like with Lua) cross compilation may be as easy as: # "bsd" is almost like "linux", but doesn't link "readline" make CC="zig cc -target aarch64-linux-musl" bsd The result is a fully statically linked executable, that can be used on all Linux distributions. But because it is statically linked, dynamic loading of external Lua libraries written in C is not possible. The following will result in a binary that is dynamically linked against (the target system) glibc and should be able to load even Lua libraries written in C: make CC="zig cc -target aarch64-linux-gnu.2.28" bsd (Note that Zig support all relevant glibc versions, that means that compiling for older Linux distributions can be done from any OS, not just ancient Debian or CentOS. Here "2.28" is old enough to support jdh's Raspberry Pi OS -- and anything newer.) Applying this to LuaMetaTeX may or may not be hard. Frankly I don't know much about CMake. But I have experience converting LuaTeX (or rather its subset) to another build systems: 1) https://github.com/vlasakm/mmtex/blob/ltex/build.zig This was used to produce the two binaries I sent previously. Usage (no setup required): wget 'https://github.com/vlasakm/mmtex/archive/refs/tags/cross-test2.zip' unzip cross-test2.zip cd mmtex-cross-test2/ wget 'https://ziglang.org/download/0.8.0/zig-linux-x86_64-0.8.0.tar.xz' tar xf zig-linux-x86_64-0.8.0.tar.xz zig-linux-x86_64-0.8.0/zig build -Dtarget=aarch64-linux-musl qemu-aarch64 zig-out/bin/mmtex --help Something similar should work on Windows/Mac and for other targets (see `zig targets`). 2) https://github.com/vlasakm/mmtex/blob/master/mmtex/files/meson.build This one compiles full LuaTeX, although it doesn't support cross compilation and links to system zlib, libpng and zzliplib. The Zig cross compilation is sadly limited (https://ziglang.org/download/0.8.0/release-notes.html#Tier-1-Support), but not because more exotic systems will never be supported, it's just that nobody did the required work, yet. The support for Linux (various architectures), macOS (aarch64+x86_64) + Windows (x86_64) should be very good. I don't think there is other cross compiler that is able to target the M1 Macs. The Zig build you download from their website [2] is kind of huge, but note that it includes LLVM+Clang+Zig in one single dependency free binary + (efficiently packed) C libraries for many targets. I.e. this is all you need for all your C/C++/Zig. Provided that you (as of now) don't need anything other than Linux/Mac/Windows. Hans, Mojca, is this something worth pursuing for LuaMetaTeX before "native" compilation is available? I am interested in trying. Michal Vlasák [1]: https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.h... [2]: https://ziglang.org/download/