FriCAS on Android with SBCL (on termux)

98 views
Skip to first unread message

Qian Yun

unread,
Nov 7, 2023, 6:49:12 AM11/7/23
to fricas-devel
Finally I can get FriCAS compiled on Android with SBCL.
The running speed is not bad.

The most important step is to get SBCL binary for Android from:
https://github.com/bohonghuang/sbcl-termux-build

Only one build error: "error: unknown type name 'fd_set'".

'fd_set' is defined in "sys/select.h", so it seems that it is implicitly
included by "sys/types.h" (via __USE_MISC macro).

Following patch fixes it.

- Qian

diff --git a/src/include/com.h b/src/include/com.h
index 470018b9..a5bc64c2 100644
--- a/src/include/com.h
+++ b/src/include/com.h
@@ -38,6 +38,7 @@
# include <winsock2.h>
#else
# include <sys/types.h>
+# include <sys/select.h>
# include <sys/socket.h>
# include <sys/un.h>
# include <netinet/in.h>

Ralf Hemmecke

unread,
Nov 7, 2023, 6:52:29 AM11/7/23
to fricas...@googlegroups.com
Qian,

you seem to be doing quite some valuable contribution to FriCAS!

Thanks!

Ralf

Waldek Hebisch

unread,
Nov 7, 2023, 8:27:55 AM11/7/23
to fricas...@googlegroups.com
On Tue, Nov 07, 2023 at 07:49:06PM +0800, Qian Yun wrote:
> Finally I can get FriCAS compiled on Android with SBCL.
> The running speed is not bad.
>
> The most important step is to get SBCL binary for Android from:
> https://github.com/bohonghuang/sbcl-termux-build
>
> Only one build error: "error: unknown type name 'fd_set'".
>
> 'fd_set' is defined in "sys/select.h", so it seems that it is implicitly
> included by "sys/types.h" (via __USE_MISC macro).

Old standard says that select should be defined in "unistd.h" and
releated types in "sys/types.h" and "sys/time.h". It probably
makes sense to switch to new standard and use "sys/select.h"
(as you propose).

Related thing is that select and related types seem to be used
only in 'sockio.c', so it would make sense to move all related
declarations to 'sockio.c'.

> Following patch fixes it.
>
> - Qian
>
> diff --git a/src/include/com.h b/src/include/com.h
> index 470018b9..a5bc64c2 100644
> --- a/src/include/com.h
> +++ b/src/include/com.h
> @@ -38,6 +38,7 @@
> # include <winsock2.h>
> #else
> # include <sys/types.h>
> +# include <sys/select.h>
> # include <sys/socket.h>
> # include <sys/un.h>
> # include <netinet/in.h>
>
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/2d19b339-ef4d-4bab-bc59-ff5bc3fdd8ef%40gmail.com.

--
Waldek Hebisch

Qian Yun

unread,
Nov 7, 2023, 8:34:19 AM11/7/23
to fricas...@googlegroups.com


On 11/7/23 21:27, Waldek Hebisch wrote:
> On Tue, Nov 07, 2023 at 07:49:06PM +0800, Qian Yun wrote:
>> Finally I can get FriCAS compiled on Android with SBCL.
>> The running speed is not bad.
>>
>> The most important step is to get SBCL binary for Android from:
>> https://github.com/bohonghuang/sbcl-termux-build
>>
>> Only one build error: "error: unknown type name 'fd_set'".
>>
>> 'fd_set' is defined in "sys/select.h", so it seems that it is implicitly
>> included by "sys/types.h" (via __USE_MISC macro).
>
> Old standard says that select should be defined in "unistd.h" and
> releated types in "sys/types.h" and "sys/time.h". It probably
> makes sense to switch to new standard and use "sys/select.h"
> (as you propose).
>
> Related thing is that select and related types seem to be used
> only in 'sockio.c', so it would make sense to move all related
> declarations to 'sockio.c'.

"select" is used by "sselect", which is used in various places.

So commit the original patch?

- Qian

Waldek Hebisch

unread,
Nov 7, 2023, 8:48:19 AM11/7/23
to fricas...@googlegroups.com
On Tue, Nov 07, 2023 at 09:34:15PM +0800, Qian Yun wrote:
>
>
> On 11/7/23 21:27, Waldek Hebisch wrote:
> > On Tue, Nov 07, 2023 at 07:49:06PM +0800, Qian Yun wrote:
> > > Finally I can get FriCAS compiled on Android with SBCL.
> > > The running speed is not bad.
> > >
> > > The most important step is to get SBCL binary for Android from:
> > > https://github.com/bohonghuang/sbcl-termux-build
> > >
> > > Only one build error: "error: unknown type name 'fd_set'".
> > >
> > > 'fd_set' is defined in "sys/select.h", so it seems that it is implicitly
> > > included by "sys/types.h" (via __USE_MISC macro).
> >
> > Old standard says that select should be defined in "unistd.h" and
> > releated types in "sys/types.h" and "sys/time.h". It probably
> > makes sense to switch to new standard and use "sys/select.h"
> > (as you propose).
> >
> > Related thing is that select and related types seem to be used
> > only in 'sockio.c', so it would make sense to move all related
> > declarations to 'sockio.c'.
>
> "select" is used by "sselect", which is used in various places.
>
> So commit the original patch?

Hmm, AFAICS 'sselect' is used only in 'sockio-c.c'.

--
Waldek Hebisch

Qian Yun

unread,
Nov 7, 2023, 9:00:10 AM11/7/23
to fricas...@googlegroups.com


On 11/7/23 21:48, Waldek Hebisch wrote:
>>> Old standard says that select should be defined in "unistd.h" and
>>> releated types in "sys/types.h" and "sys/time.h". It probably
>>> makes sense to switch to new standard and use "sys/select.h"
>>> (as you propose).
>>>
>>> Related thing is that select and related types seem to be used
>>> only in 'sockio.c', so it would make sense to move all related
>>> declarations to 'sockio.c'.
>>
>> "select" is used by "sselect", which is used in various places.
>>
>> So commit the original patch?
>
> Hmm, AFAICS 'sselect' is used only in 'sockio-c.c'.
>

sman.c also uses 'sselect', 'FD_SETSIZE' is from sys/select.h.

Also I tried to move parts from 'com.h' to 'sockio.c', but failed:
some other stuff depends on these headers, for example 'Sock'.

- Qian

Waldek Hebisch

unread,
Nov 7, 2023, 10:19:19 AM11/7/23
to fricas...@googlegroups.com
Yes, I see. So please commit original patch. And thanks for
Android port!

--
Waldek Hebisch

Andrey G. Grozin

unread,
Nov 26, 2023, 4:30:36 AM11/26/23
to fricas-devel
Hello *,

I've tried to install fricas trunk on my tablet in termux. sbcl-2.2.3 from
https://github.com/bohonghuang/sbcl-termux-build seems to work fine (newer
versions have not appeated for quite some time, the author seems to lose
interest). Then I've cloned the fricas git trunk. After ./configure
--with-lisp=sbcl, make worked for quite some time, and ended with

>> System error:
Failed to find the TRUENAME of
/data/data/com.termux/files/home/fricas/src/algebra/libdb.text:
No such file or directory
(1) -> cp ../algebra/*.daase
/data/data/com.termux/files/home/fricas/target/aarch64-linux-gnu/algebra
cp: cannot stat '../algebra/*.daase': No such file or directory
make[3]: *** [Makefile:228: do-stamp-databases] Error 1
make[3]: Leaving directory
'/data/data/com.termux/files/home/fricas/src/etc'
make[2]: *** [Makefile:208: stamp-databases] Error 2
make[2]: Leaving directory
'/data/data/com.termux/files/home/fricas/src/etc'
make[1]: *** [Makefile:250: all-etc] Error 2
make[1]: Leaving directory '/data/data/com.termux/files/home/fricas/src'
make: *** [Makefile:250: all-src] Error 2

Any ideas how to proceed?

Andrey

Andrey G. Grozin

unread,
Nov 26, 2023, 4:35:01 AM11/26/23
to fricas-devel
By the way, termux maxima is built with ecl-23.9.9. Would be good to
re-build it with sbcl, it would become faster.

I also have reduce in termux. It builds (almost) straightforwardly. fricas
will become the 3-rd CAS in termux!

Andrey

Qian Yun

unread,
Nov 26, 2023, 5:55:07 AM11/26/23
to fricas...@googlegroups.com
I can confirm your error. I was building successfully with
1.3.9 tarball.

The problem happens in "OBEY" in "buildLibdb", the problem
is the underlying SBCL call
(SB-EXT:RUN-PROGRAM "/bin/sh" '("-c" "ls") :INPUT T :OUTPUT T :ERROR T)
get SIGNALED and with return code 31.

So looks like the sbcl-android port has a bug.

- Qian

Andrey G. Grozin

unread,
Nov 28, 2023, 11:20:24 AM11/28/23
to fricas...@googlegroups.com
On Sun, 26 Nov 2023, Qian Yun wrote:
> I can confirm your error. I was building
> successfully with
> 1.3.9 tarball.
Thanks. Indeed, 1.3.9 with your 1-line fix builds successfully:

./comfigure --prefix=$PREFIX --with-lisp=sbcl
make
make install

succeeds. Then

~ $ fricas
...
sh: can't create /tmp/socks.11257: No such file or directory
...
Fatal error opening I/O socket

Indeed, there is no /tmp. Is it possible to convince fricas to use
$PREFIX/tmp instead of /tmp?

Andrey

Waldek Hebisch

unread,
Nov 28, 2023, 6:16:06 PM11/28/23
to fricas...@googlegroups.com
ATM no way, '/tmp' is hardcoded. IIUC standard way is to use
value of $TMPDIR as directory for temporary files. We can implement
this. Does Android set TMPDIR to sensible value? Or can you set it?

--
Waldek Hebisch

Dima Pasechnik

unread,
Nov 28, 2023, 7:03:03 PM11/28/23
to fricas...@googlegroups.com
maybe calling mkdtemp(3) to get a unique temporary directory is better?
Probably some lisps have it implemented.


Qian Yun

unread,
Nov 28, 2023, 7:10:16 PM11/28/23
to fricas...@googlegroups.com
You can run with "fricas -nosman" so that /tmp is not required.

Termux has TMPDIR=/data/data/com.termux/files/usr/tmp

$PREFIX/tmp is generally not writable on other systems.

- Qian

Waldek Hebisch

unread,
Nov 28, 2023, 8:18:58 PM11/28/23
to fricas...@googlegroups.com
Well, this directory is needed to start communication between
cooperating processes. So it must be either fixed or passed
via environment variables or maybe passed via command line
(but this is problematic due to Lisp command line handling).

For our purposes TMPDIR looks good enough, I am not sure if
mkdtemp gives us any gain. If used we would call it in single
place in C code.

--
Waldek Hebisch

Andrey G. Grozin

unread,
Nov 29, 2023, 5:20:58 AM11/29/23
to fricas...@googlegroups.com
On Wed, 29 Nov 2023, Qian Yun wrote:
> You can run with "fricas -nosman" so that /tmp is not required.
Yes! Thank you very much.

fricas -nosman

works fine. And this is all what's needed in command-line termux (I never
tried to run X programs in termux, it is possible, but requires some work;
I think on a phone or tablet it's not really useful).

termux predefines several env variables for user's convenience.
$PREFIX = /data/data/com.termux/files/usr
should be used instead of /usr everywhere.
$TMPDIR = $PREFIX/tmp
should be used instead of /tmp. termux is a single-user system, its user
is always root, so, all directories are writable.

I think it would be good to use $TMPDIR if it's defined, otherwise to fall
back to /tmp. This may be useful in various situations (like prefix Linux
installations inside another OS).

Many thanks to Qian for such a wonderful thing as FriCAS running in one's
phone or tablet!

Andrey
Reply all
Reply to author
Forward
0 new messages