这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@robertkirkman
Copy link
Member

@robertkirkman robertkirkman commented Mar 3, 2025

clang++: error: no such file or directory: '/home/builder/.termux-build/_cache/android-r27c-api-24-v1/lib/clang/18/lib/linux/libclang_rt.builtins-aarch64-android.a'

@robertkirkman robertkirkman requested a review from Grimler91 as a code owner March 3, 2025 11:49
@robertkirkman
Copy link
Member Author

robertkirkman commented Mar 3, 2025

The reason why this has to stay as -isystem for the cross-compiler, and could not be replaced with -isysroot to match the argument that is automatically applied by the on-device compiler, is because the cross-compiler has a /home/builder/.termux-build/_cache/android-r27c-api-24-v1/sysroot/usr/include folder containing some necessary C headers separately, that the on-device compiler does not have, and adding -isysroot interferes with that when using the cross-compiler:

#21835 (comment)

@truboxl truboxl self-requested a review March 3, 2025 14:22
@licy183
Copy link
Member

licy183 commented Mar 3, 2025

Since #23513 breaks the on-device build, after python is rebuilt after it, the building process triggered by pip may also be broken. See #20464 (comment).

@robertkirkman robertkirkman marked this pull request as draft March 3, 2025 23:30
@robertkirkman robertkirkman force-pushed the disable-isystem-on-device branch from cb96518 to 43d23f1 Compare March 4, 2025 00:36
@robertkirkman robertkirkman changed the title fix(toolchain/{23c,27c}): disable the use of -isystem on-device fix(toolchain/{23c,27c}): add -isystem${TERMUX_PREFIX}/include/c++/v1 to $CPPFLAGS before -isystem${TERMUX_PREFIX}/include Mar 4, 2025
@robertkirkman
Copy link
Member Author

robertkirkman commented Mar 4, 2025

@licy183 Thank you for explaining, I do see that after you showed me. Python does store the $CPPFLAGS among other flags in $TERMUX_PREFIX/lib/python3.12/_sysconfigdata__linux_.py.

Do you know of a pip package that builds C++, rather than only C, that I could test, which I have not found yet, and do you think this other way I have pushed will solve the problem?

This other way passes these test cases while using the same $CPPFLAGS in both $TERMUX_ON_DEVICE_BUILD=true mode and $TERMUX_ON_DEVICE_BUILD=false mode:

and this change should do nothing for cross-compiling of all normal C or C++ packages, because the cross-compiler will continue to include the correct C++ headers, in the correct order, in its own way that has been successful so far, from /home/builder/.termux-build/_cache/android-r27c-api-24-v1/sysroot/usr/include/c++/v1, and since there is nothing in $TERMUX_PREFIX/include/c++/v1, this argument should always have no effect in cross-compilation mode.

I think that these two already-existing parts of the repository code save me from the frightening idea of ndk-sysroot ever getting into the $TERMUX_PREFIX in $TERMUX_ON_DEVICE_BUILD=false mode and adding headers from a too-new version of LLVM into the include path:

# llvm doesn't build if ndk-sysroot is installed:
if [ "$PKG" = "ndk-sysroot" ]; then continue; fi

cp -Rf toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/* \
$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/include

and I am pretty sure that on-device, the headers in ${TERMUX_PREFIX}/include/c++/v1 are designed to be safe for being in the $CPPFLAGS of C-only programs, because they contain things like "#if defined(__cplusplus)" and "#if __has_include_next(<stdint.h>) # include_next <stdint.h>", but I hope that there is not a situation where a C-only program would be derailed and fail to build on-device if exposed to the addition of -isystem${TERMUX_PREFIX}/include/c++/v1. Do you know of any?

@robertkirkman robertkirkman marked this pull request as ready for review March 4, 2025 00:42
@robertkirkman robertkirkman force-pushed the disable-isystem-on-device branch from 43d23f1 to 3fd89bb Compare March 4, 2025 02:43
@robertkirkman robertkirkman requested a review from TomJo2000 as a code owner March 4, 2025 02:43
@robertkirkman robertkirkman force-pushed the disable-isystem-on-device branch from 3fd89bb to c874e7c Compare March 5, 2025 03:19
@robertkirkman
Copy link
Member Author

robertkirkman commented Mar 5, 2025

licy183 you are completely right, because, very unfortunately, after db889e1, it has already happened to octave, exactly as you predicted, and

pkg install octave
octave
pkg install https://sourceforge.net/projects/octave-ocl-extra/files/ocl-1.2.2-AMD-update.tar.gz/download

So it must be revision-bumped in this PR, to make that error go away. I am very sorry for causing the error.

  • This is a separate issue from [termux-apt] octave from TUR and other problematic unofficial packages are difficult to remove #23605 , which is just a different bug in the same package that has existed for much longer

    • (so, to get to the point where the newer error occurs, you must have an Android 9 or older device capable of bypassing that issue)
  • There is also a third error currently affecting the octave package, which I am pretty sure I did not cause, that you can see after bypassing the first two errors. The on-device linker arguments somewhere in the octave package have begun at some point to be polluted by linker arguments from the cross-compiler, not just the preprocessor arguments. I don't know how to fix the linker arguments error, which I am pretty sure was there before I did anything:

clang++: error: no such file or directory: '/home/builder/.termux-build/_cache/android-r27c-api-24-v1/lib/clang/18/lib/linux/libclang_rt.builtins-aarch64-android.a'
make: *** [Makefile:48: ocl_bin.oct] Error 1
~ $ for f in $(dpkg -L octave); do grep -d skip 'build/_cache' $f; done
grep: /data: Permission denied
grep: /data/data: Permission denied
grep: /data/data/com.termux/files/usr/bin/mkoctfile-9.4.0: binary file matches
grep: /data/data/com.termux/files/usr/lib/octave/9.4.0/liboctinterp.so: binary file matches
Libs.private: -lcurl -lcholmod -lumfpack -lamd -lcamd -lcolamd -lccolamd -lcxsparse -lsuitesparseconfig -lspqr -larpack -lqrupdate -lopenblas -lfftw3_threads -lfftw3 -lfftw3f_threads -lfftw3f  -lopenblas -L/data/data/com.termux/files/usr/lib -lreadline  -lpcre2-8  -lpthread  /home/builder/.termux-build/_cache/android-r27c-api-24-v1-flang-v0/sysroot/usr/lib/aarch64-linux-android/libFortranRuntime.a /home/builder/.termux-build/_cache/android-r27c-api-24-v1-flang-v0/sysroot/usr/lib/aarch64-linux-android/libFortranDecimal.a -lpthread -lm -landroid-complex-math      -lcrypto    -L/data/data/com.termux/files/usr/lib -liconv   
grep: /data/data/com.termux/files/usr/bin/mkoctfile: binary file matches

@robertkirkman robertkirkman force-pushed the disable-isystem-on-device branch 3 times, most recently from 3fc0d4d to 94ec9cc Compare March 5, 2025 08:59
@robertkirkman
Copy link
Member Author

robertkirkman commented Mar 5, 2025

I did something to Octave that made the third error, clang++: error: no such file or directory: '/home/builder/.termux-build/_cache/android-r27c-api-24-v1/lib/clang/18/lib/linux/libclang_rt.builtins-aarch64-android.a', go away on my Android 8 device.

After that, it turned into a fourth error, "error: octave's dynamic library loader reported an error while dynamically loading the OpenCL library",

which is a dlopen("libOpenCL.so") kind of error, so I think it is not directly related to compiling and running C++ inside of Octave.

The text of the fourth error itself, comes from inside of a C++ function, so I think it serves as proof that compiling C++ code inside of Octave started working. What is remaining is that OpenCL itself is not working, and possibly just not working on my particular device.

However, the patch I made is extremely weird looking and hard to explain. It is patching a feature --enable-relocate-all that is already in Octave, but which was designed for cross-compilers that have only 1 prefix. The problem here is that the termux-packages toolchain here is a cross-compiler with at least three different prefixes all at the same time, $TERMUX_PREFIX, $flang_toolchain_dir/sysroot/usr, and $TERMUX_STANDALONE_TOOLCHAIN, so to completely patch $TERMUX_TOPDIR out of the target package, it is necessary to modify the behavior of the --enable-relocate-all setting to handle the $flang_toolchain_dir/sysroot/usr and $TERMUX_STANDALONE_TOOLCHAIN that are not expected by the upstream code. I hope that it makes sense to someone.

Also I did not want to touch even more files in this PR, so I have not messed with it, but it looks to me like termux_setup_flang() will sometimes use cd and then not go back to the original directory that was active when termux_setup_flang() was called. I am not sure if that is intentional or not so I just used cd "$TERMUX_PKG_SRCDIR" to work around that safely.

@robertkirkman
Copy link
Member Author

Also, in the future version of Octave, they tested it on Windows and had some kind of a similar problem, so they modified the file adding a Windows block into the same spot, so the patch will fail and need to be rebased at that time. I hope I have explained it well enough that it will not be frustrating when that happens.

@robertkirkman robertkirkman marked this pull request as draft March 5, 2025 13:58
@robertkirkman robertkirkman force-pushed the disable-isystem-on-device branch 3 times, most recently from a35153e to 54dd2dc Compare March 5, 2025 15:55
@robertkirkman robertkirkman marked this pull request as ready for review March 5, 2025 16:54
@robertkirkman robertkirkman force-pushed the disable-isystem-on-device branch 2 times, most recently from 852ee6d to 562471c Compare March 6, 2025 02:22
@licy183
Copy link
Member

licy183 commented Mar 6, 2025

Please separate these changes into three commits. It is better to write a brief comment of each change in build.sh, and put more explanation in the commit msg. Other things LGTM.

@robertkirkman robertkirkman marked this pull request as draft March 6, 2025 16:23
@robertkirkman
Copy link
Member Author

robertkirkman commented Mar 6, 2025

Ok, I will reorganize the commit structure soon

… to $CPPFLAGS before -isystem${TERMUX_PREFIX}/include

- Fixes termux#23578

-isystem${TERMUX_PREFIX}/include/c++/v1 is necessary because, while ${TERMUX_PREFIX}/include/c++/v1
is never present in $TERMUX_ON_DEVICE_BUILD=false mode (because of this line:
https://github.com/termux/termux-packages/blob/fe7adf6ea2c7e5305c1213cbda919c17f251685d/scripts/build/termux_step_get_dependencies.sh#L28-L29
), it is present in $TERMUX_ON_DEVICE_BUILD=true
mode, and must be in the include path before ${TERMUX_PREFIX}/include, otherwise C++ programs will
fail to compile on-device (but not in the cross-compiler), and also python, ruby, octave and ecl
store the compiler arguments they were built with into their packages and reuse them when invoking
clang and clang++ on-device, so this ensures that on-device pip builds will have the correct include order.
…N_DEVICE_BUILD=true` support

this package's configure script checks only for $PKGCONFIG, but that variable
is currently only set globally in $TERMUX_ON_DEVICE_BUILD=false
mode. In $TERMUX_ON_DEVICE_BUILD=true mode, only $PKG_CONFIG is set globally.

ld.lld: error: undefined symbol: libiconv
many packages manually set this universally without comment,
but a pattern can be observed that reverse dependencies of libiconv
seem to always require this in $TERMUX_ON_DEVICE_BUILD=true mode,
and it gets set whenever someone creates $TERMUX_ON_DEVICE_BUILD=true support
for one of them.
see the commit message here:
termux@bab423c
revbump after termux@db889e1 to fix propagated $CPPFLAGS

using $TERMUX_PKG_TMPDIR/_deps to only have needed libraries in the search path prevents
ld.lld: error: duplicate symbol: tzalloc in $flang_libs_dir/libc.a

putting -l:$_libgcc_name only in $LIBS instead of $LDFLAGS prevents
ld.lld: error: unable to find library -l:libclang_rt.builtins-aarch64-android.a
on-device during the pkg function https://octave.sourceforge.io/octave/function/pkg.html

prevents this error: clang++: error: no such file or directory: '/home/builder/.termux-build/_cache/android-r27c-api-24-v1/lib/clang/18/lib/linux/libclang_rt.builtins-aarch64-android.a'
@robertkirkman robertkirkman force-pushed the disable-isystem-on-device branch from 562471c to 302f7f0 Compare March 7, 2025 00:21
@robertkirkman robertkirkman marked this pull request as ready for review March 7, 2025 00:24
@robertkirkman
Copy link
Member Author

I separated the commits, reduced the comments, and moved the information into the commit messages, I hope this makes it more organized and readable

Copy link
Member

@licy183 licy183 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robertkirkman
Copy link
Member Author

Ok I will merge this in 24 hours, if nothing else is found wrong with it. I have been testing the addition of -isystem${TERMUX_PREFIX}/include/c++/v1 on many packages in both cross-compilation and non-cross-compilation modes and I am pretty sure now that it will not break any builds.

@robertkirkman robertkirkman merged commit d9cb7f6 into termux:master Mar 8, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: building C++ packages on-device broken

5 participants