Building Racket 8.2 on Termux/Android

156 views
Skip to first unread message

Wesley Bitomski

unread,
Oct 19, 2021, 7:25:33 PM10/19/21
to Racket Developers
OK. I'm pretty deep in this rabbithole, but forgive me if I'm skipping some details.

I've spent a good portion of yesterday, and a unreasonable chunk of today, trying to build Racket for aarch64 on Android using Termux for the build environment (yes, I'm building this on the target (a phone), so no cross-compilation shenanigans). Recently, I've been able to reliably produce a working `racket` binary, but `raco` fails to build on account of `ffi-lib` not being able to find where the system libraries are (this is what I think is happening).

So, question: how to I point out where the system libs live in such that ffi-lib can find them?

Steps to reproduce:
0. download source bundle with prebuilt packages (downloads.racket-lang.org).
1. run configure from tarball root: `src/configure --enable-csonly --enable-sysroot=$PREFIX --prefix=$PREFIX --exec-prefix=$PREFIX`
2. `make` -- works flawlessly
3. `make install` -- errors:
make[4]: Entering directory '/data/data/com.termux/files/home/racket-8.2/cs/c'
/data/data/com.termux/files/usr/bin/racket -Z ../../../../../build/config -X "/data/data/com.termux/files/usr/share/racket/collects" -G "/data/data/com.termux/files/usr/etc/racket"  -Z ../../../../../build/config  -N "raco" -l- setup --no-user                                                                                                                    
ffi-lib: could not load foreign library
  path: [all opened]
  system error: unknown error
  context...:                                                                                                              body of "/data/data/com.termux/files/usr/share/racket/collects/openssl/mzssl.rkt"                                       body of "/data/data/com.termux/files/usr/share/racket/collects/setup/main.rkt"
4. Hypothesis: ffi-lib can't find libssl, located in $PREFIX/lib. `raco` needs this to securely communicate with package catalogs.
5. Result: no `raco`, but `racket` works just fine.

Matthew Flatt

unread,
Oct 19, 2021, 7:37:08 PM10/19/21
to Wesley Bitomski, Racket Developers
At Tue, 19 Oct 2021 16:25:33 -0700 (PDT), Wesley Bitomski wrote:
> ffi-lib: could not load foreign library
> path: [all opened]
> system error: unknown error

The "[all opened]" here means that

(define libmz (ffi-lib #f))

failed in "racket/collects/openssl/mzssl.rkt".

That line, plus

(define-ffi-definer define-mzscheme libmz)

are leftovers that can just be removed, and I'll get rid of them.

If deleting those lines is not an option for some reason, or in case
you run into the same problem somewhere else: I think the cause of the
underlying error is a `dlopen` call with `NULL` as its first argument.
Unless that's just disallowed on Android, you might be able to work
around the problem with a linker flag like `-rdynamic`.

wesley bitomski

unread,
Oct 19, 2021, 9:06:16 PM10/19/21
to Matthew Flatt, Racket Developers
Thanks! The Termux docs did mention that dlopen was "different":

> Symbol visibility when opening shared libraries using dlopen() works differently. On a normal linker, when an executable linking against a shared library libA dlopen():s another shared library libB, the symbols of libA are exposed to libB without libB needing to link against libA explicitly. This does not work with the Android linker, which can break plug-in systems where the main executable dlopen():s a plug-in which does not explicitly link against some shared libraries already linked to by the executable. See the relevant NDK issue for more information.

I have no qualms about digging around in the sources. I was sort of hoping I'd have to do that. 

Anyway, removing the noted vesdigital code just caused a failure in ffi/unsafe, specifically in the body of get-ffi-obj*. I'll start messing around with linker flags tomorrow.
Reply all
Reply to author
Forward
0 new messages