From: "Michal Vlasák" <lahcim8@gmail.com>
To: "mailing list for ConTeXt users" <ntg-context@ntg.nl>,
"jdh" <dhenman@gmail.com>
Subject: Re: Problem getting lmtx version up
Date: Sat, 17 Jul 2021 14:16:09 +0200 [thread overview]
Message-ID: <CCVEP44OWV8Y.A40NZT9TX9JU@phobos> (raw)
In-Reply-To: <20210717014720.8365@binki>
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.html
[2]: https://ziglang.org/download/
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next parent reply other threads:[~2021-07-17 12:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210717014720.8365@binki>
2021-07-17 12:16 ` Michal Vlasák [this message]
2021-07-18 19:54 jdh
-- strict thread matches above, loose matches on Subject: below --
2021-07-15 22:46 jdh
2021-07-16 10:24 ` George N. White III
2021-07-16 11:39 ` Mojca Miklavec
2021-07-16 19:47 ` Hans Hagen
2021-07-16 20:15 ` Alan Braslau
2021-07-18 18:00 ` Mojca Miklavec
2021-07-17 0:21 ` Michal Vlasák
2021-07-17 5:30 ` Lutz Haseloff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CCVEP44OWV8Y.A40NZT9TX9JU@phobos \
--to=lahcim8@gmail.com \
--cc=dhenman@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).