telescope-browser / telescope

browser for the small internet
https://telescope-browser.org
ISC License
43 stars 1 forks source link

Cross-compilation support #5

Closed sikmir closed 2 years ago

sikmir commented 2 years ago

I've tried to cross-compile telescope and build failed with:

telescope-aarch64-unknown-linux-gnu> aarch64-unknown-linux-gnu-gcc  -I/nix/store/2dvz4kwky6qxx75qlwjawa52ixpi0lb5-libevent-aarch64-unknown-linux-gnu-2.1.12-dev/include -g -O2 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter   -o pagebundler pagebundler.o compat/freezero.o compat/getdtablecount.o compat/getprogname.o compat/recallocarray.o compat/strlcat.o compat/strlc
py.o compat/strtonum.o compat/setproctitle.o compat/imsg.o compat/imsg-buffer.o compat/ohash.o compat/fmt_scaled.o -L/nix/store/mq7pij264yrh1piv55a4z5wzxrsyjc8b-libevent-aarch64-unknown-linux-gnu-2.1.12/lib -levent_core -ltls -lncursesw
telescope-aarch64-unknown-linux-gnu> echo > pages.c
telescope-aarch64-unknown-linux-gnu> echo "#include \"pages.h\"" >> pages.c
telescope-aarch64-unknown-linux-gnu> ./pagebundler -f ./pages/about_about.gmi   -v about_about   >> pages.c
telescope-aarch64-unknown-linux-gnu> /nix/store/l0wlqpbsvh1pgvhcdhw7qkka3d31si7k-bash-5.1-p8/bin/bash: line 1: ./pagebundler: cannot execute binary file: Exec format error
telescope-aarch64-unknown-linux-gnu> make: *** [Makefile:1181: pages.c] Error 126
error: builder for '/nix/store/n9ghpkkns8yfbr4xjgjv4y9dr9w759d8-telescope-aarch64-unknown-linux-gnu-0.5.2.drv' failed with exit code 2;
       last 10 log lines:
       >    72 |        __glibc_objsize (__s), __fmt,
       >       |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       >    73 |        __va_arg_pack ());
       >       |        ~~~~~~~~~~~~~~~~~
       > aarch64-unknown-linux-gnu-gcc  -I/nix/store/2dvz4kwky6qxx75qlwjawa52ixpi0lb5-libevent-aarch64-unknown-linux-gnu-2.1.12-dev/include -g -O2 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter   -o pagebundler pagebundler.o compat/freezero.o compat/getdtablecount.o compat/getprogname.o compat/recallocarray.o compat/strlcat.o compat/strlcpy.o compat/strtonum.o compat/setproctitle.o compat/imsg.o compat/imsg-buffer.o compat/ohash.o compat/fmt_scaled.o -L/nix/store/mq7pij264yrh1piv55a4z5wzxrsyjc8b-libevent-aarch64-unknown-linux-gnu-2.1.12/lib -levent_core -ltls -lncursesw
       > echo > pages.c
       > echo "#include \"pages.h\"" >> pages.c
       > ./pagebundler -f ./pages/about_about.gmi   -v about_about   >> pages.c
       > /nix/store/l0wlqpbsvh1pgvhcdhw7qkka3d31si7k-bash-5.1-p8/bin/bash: line 1: ./pagebundler: cannot execute binary file: Exec format error
       > make: *** [Makefile:1181: pages.c] Error 126

The reason is that pagebundler should be built with build-platform compiler, not with target-pllatform compiler.

sikmir commented 2 years ago

I guess it should be specified with some magic in Makefile.am, but I can't find in automake documentation how to do it.

omar-polo commented 2 years ago

sorry for the late reply, I saw the notification but was busy

I guess it should be specified with some magic in Makefile.am

Exactly. We need to build pagebundler with the host compiler,

but I can't find in automake documentation how to do it.

neither do I 🙈

I'll see what can be done. To be honest, pagebundler was just a way to avoid checking if the linker is able to bundle files in shared objects. If we don't find a good way to convince automake to use the correct compiler, we can just as well use the linker and ask folks who cross-compile to use a recent-ish linker :)

omar-polo commented 2 years ago

Could you please test #6?

I've added two configure variables:

% ./configure --help | grep HOSTC
  HOSTCC      The C compiler on the host.
  HOSTCFLAGS  CFLAGS for the host compiler

which should help for the cross-compile use case. ./autogen.sh now complains about:

Makefile.am:55: warning: user target 'pagebundler$(EXEEXT)' defined here ...
/usr/local/share/automake-1.16/am/program.am: ... overrides Automake target 'pagebundler$(EXEEXT)' defined here
Makefile.am:52:   while processing program 'pagebundler'

but I think is fine.

In theory only ./configure --target=... HOSTCC=cc should be needed, but I've added HOSTCFLAGS too in case it helps (it defaults to CFLAGS anyway.)

sikmir commented 2 years ago

Could you please test #6?

Build is OK now:

telescope-aarch64-unknown-linux-gnu> ====> hostcc     is /nix/store/da9l6ifizmh883j94gzx5n51h8lrrp00-gcc-wrapper-10.3.0/bin/cc
telescope-aarch64-unknown-linux-gnu> ====> hostcflags is $(CFLAGS)
omar-polo commented 2 years ago

Thanks!