containers / bubblewrap

Low-level unprivileged sandboxing tool used by Flatpak and similar projects
Other
3.97k stars 237 forks source link

Build fails on Android using Clang 16 (termux) #579

Open orowith2os opened 1 year ago

orowith2os commented 1 year ago

I installed all of the appropriate dependencies for building, save for libselinux. Everything goes well until I get to building bubblewrap. Here is the output:

~/oro/bubblewrap $ meson compile -C _builddir
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /data/data/com.termux/files/usr/bin/ninja -C /data/data/com.termux/files/home/oro/bubblewrap/_builddir
ninja: Entering directory `/data/data/com.termux/files/home/oro/bubblewrap/_builddir'
[7/10] Compiling C object bwrap.p/bubblewrap.c.o
FAILED: bwrap.p/bubblewrap.c.o
cc -Ibwrap.p -I. -I.. -I/data/data/com.termux/files/usr/include -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -O0 -g -D_GNU_SOURCE -Werror=shadow -Werror=empty-body -Werror=strict-prototypes -Werror=missing-prototypes -Werror=implicit-function-declaration -Werror=pointer-arith -Werror=init-self -Werror=missing-declarations -Werror=return-type -Werror=overflow -Werror=int-conversion -Werror=incompatible-pointer-types -Werror=misleading-indentation -Werror=missing-include-dirs -Werror=aggregate-return -Werror=switch-default -Wswitch-enum -Wno-sign-compare -Wno-error=sign-compare -Wno-missing-field-initializers -Wno-error=missing-field-initializers -Werror=format=2 -Werror=format-security -Werror=format-nonliteral -MD -MQ bwrap.p/bubblewrap.c.o -MF bwrap.p/bubblewrap.c.o.d -o bwrap.p/bubblewrap.c.o -c ../bubblewrap.c
../bubblewrap.c:3062:13: error: call to undeclared function 'get_current_dir_name'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  old_cwd = get_current_dir_name ();
            ^
../bubblewrap.c:3062:11: error: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
  old_cwd = get_current_dir_name ();
          ^ ~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
[9/10] Linking target tests/test-utils
ninja: build stopped: subcommand failed.

This is using Termux from F-Droid.

orowith2os commented 1 year ago

I am currently unable to test this on Fedora or another normal Linux distribution, Android is all I have at the moment.

smcv commented 1 year ago

bubblewrap is primarily intended for, and tested on, GNU/Linux (Linux with GNU libc). Android uses bionic libc, which is lacking many GNU functions.

I'd (eventually, when time permits...) review a pull request adding a feature-check for "do we have get_current_dir_name()?", and if not, a fallback implementation in terms of calling getcwd() with an increasingly large buffer.

orowith2os commented 1 year ago

bubblewrap is primarily intended for, and tested on, GNU/Linux (Linux with GNU libc). Android uses bionic libc, which is lacking many GNU functions.

I know, I was building it on Android mainly because I could. Would musl work here? I don't know if it implements the functions bwrap needs. Worst case I try to install glibc inside of Termux. Will give that a try and see if it works.

I know bwrap likely wouldn't work on Android in the first place, so again, pretty much just because I could.

I'd (eventually, when time permits...) review a pull request adding a feature-check for "do we have get_current_dir_name()?",

Would be appreciated, I'll keep an eye out for that.

smcv commented 1 year ago

Would be appreciated, I'll keep an eye out for that

To be more clear, I meant "if you write it, I'll try to review it". I'm very unlikely to have time to implement fallback code for non-GNU operating system environments myself.

smcv commented 1 year ago

Would musl work here?

musl is in the same situation as bionic libc: probably nobody is routinely building/testing bubblewrap for that environment, but if people (maybe you?) contribute portability improvements then I'll try to review them.

orowith2os commented 1 year ago

To be more clear, I meant "if you write it, I'll try to review it".

Understood that, meant I'll be watching the PRs for any that might be relevant. I don't think I have the knowledge needed to implement a fallback, but who knows, could be worth a shot.

orowith2os commented 1 year ago

Interesting, Alpine Linux has bubblewrap in their repos, no dependency on glibc. Maybe musl implements the gnu functions needed here?

orowith2os commented 1 year ago

Very interesting: https://git.musl-libc.org/cgit/musl/tree/src/misc/get_current_dir_name.c

Seems the work is already done here. Shouldn't be too hard to get it going in bwrap.