Skip to content

Commit

Permalink
ndk-sysroot-gcc-compact: bump to 26b
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 committed Oct 23, 2023
1 parent ef470ed commit eefa703
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 51 deletions.
18 changes: 10 additions & 8 deletions tur/ndk-sysroot-gcc-compact/0001-c++-v1-math-headers.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ This patch is one of the `ndk-sysroot` from termux main repo.
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/cmath
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/cmath
@@ -301,7 +301,7 @@
*/
#include <__type_traits/remove_cv.h>
#include "version"

#include <__config>
-#include <math.h>
+#include <c++/v1/math.h>
#include "version"
#include <type_traits>

#ifndef _LIBCPP_MATH_H
# error <cmath> tried including <math.h> but didn't find libc++'s <math.h> header. \
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/math.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/math.h
@@ -300,7 +300,7 @@
#define _LIBCPP_STDLIB_INCLUDE_NEXT
#include <stdlib.h>
@@ -297,9 +297,7 @@
# pragma GCC system_header
#endif

-#include_next <math.h>
-# if __has_include_next(<math.h>)
-# include_next <math.h>
-# endif
+#include "../../math.h"

#ifdef __cplusplus
Expand Down
7 changes: 4 additions & 3 deletions tur/ndk-sysroot-gcc-compact/0003-sys-cdefs.h.patch
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
This patch is based on the setup-scripts from its-pointless repo. It defines
some builtin functions which is available in clang but not available in gcc.
diff -uNr a/sys/cdefs.h b/sys/cdefs.h
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/cdefs.h 2022-08-06 14:48:49.633955200 +0800
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/cdefs.h 2022-08-06 15:10:18.821676800 +0800
@@ -42,6 +42,28 @@
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/cdefs.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/cdefs.h
@@ -42,6 +42,29 @@
*/
#define __BIONIC__ 1

Expand All @@ -27,6 +27,7 @@ diff -uNr a/sys/cdefs.h b/sys/cdefs.h
+// TODO: Replace all the functions use _Nonnull with __nonnull__
+#define _Nonnull
+#define _Nullable
+#define _Null_unspecified
+#endif
+
#if defined(__cplusplus)
Expand Down
30 changes: 15 additions & 15 deletions tur/ndk-sysroot-gcc-compact/0004-compact-with-clang-builtins.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
This patch is based on the setup-scripts from its-pointless repo. It reverts
some changes that makes the NDK headers support clang only.
diff -uNr a/bits/ioctl.h b/bits/ioctl.h
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/ioctl.h 2022-08-06 14:48:47.524999800 +0800
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/ioctl.h 2022-08-06 15:51:08.476122900 +0800
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/ioctl.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/ioctl.h
@@ -55,7 +55,8 @@
* - defining BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD, which will make the
* overloading go away.
Expand All @@ -14,8 +14,8 @@ diff -uNr a/bits/ioctl.h b/bits/ioctl.h
int ioctl(int __fd, unsigned __request, ...) __overloadable __enable_if(1, "") __RENAME(ioctl);
#endif
diff -uNr a/bits/stdatomic.h b/bits/stdatomic.h
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/stdatomic.h 2022-08-06 14:48:47.472671200 +0800
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/stdatomic.h 2022-08-06 16:35:43.342368000 +0800
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/stdatomic.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/stdatomic.h
@@ -41,7 +41,7 @@
*/

Expand Down Expand Up @@ -275,8 +275,8 @@ diff -uNr a/bits/stdatomic.h b/bits/stdatomic.h
}
+#endif /* !_KERNEL */
diff -uNr a/complex.h b/complex.h
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/complex.h 2022-08-06 14:48:52.639751200 +0800
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/complex.h 2022-08-06 15:55:58.240936500 +0800
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/complex.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/complex.h
@@ -44,9 +44,15 @@
#define I _Complex_I

Expand All @@ -294,8 +294,8 @@ diff -uNr a/complex.h b/complex.h

__BEGIN_DECLS
diff -uNr a/malloc.h b/malloc.h
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/malloc.h 2022-08-06 14:48:48.739114400 +0800
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/malloc.h 2022-08-06 16:00:29.648086400 +0800
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/malloc.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/malloc.h
@@ -31,7 +31,11 @@

__BEGIN_DECLS
Expand All @@ -309,8 +309,8 @@ diff -uNr a/malloc.h b/malloc.h
/**
* [malloc(3)](http://man7.org/linux/man-pages/man3/malloc.3.html) allocates
diff -uNr a/stdatomic.h b/stdatomic.h
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdatomic.h 2022-08-06 14:48:49.278954700 +0800
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdatomic.h 2022-08-06 16:32:05.634401300 +0800
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdatomic.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdatomic.h
@@ -32,8 +32,12 @@

#include <sys/cdefs.h>
Expand Down Expand Up @@ -339,14 +339,14 @@ diff -uNr a/string.h b/string.h
* Use two enable_ifs so these overloads don't conflict with + are preferred over libcxx's. This can
* be reduced to 1 after libcxx recognizes that we have const-correct overloads.
diff -uNr a/sys/mman.h b/sys/mman.h
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/mman.h 2022-08-06 14:48:49.466955000 +0800
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/mman.h 2022-08-06 16:38:31.091859400 +0800
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/mman.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/mman.h
@@ -50,7 +50,14 @@
* and returns `MAP_FAILED` and sets `errno` on failure.
*/
#if defined(__USE_FILE_OFFSET64)
-void* mmap(void* __addr, size_t __size, int __prot, int __flags, int __fd, off_t __offset) __RENAME(mmap64);
+void* mmap(void* __addr, size_t __size, int __prot, int __flags, int __fd, off_t __offset)
-void* _Nonnull mmap(void* _Nullable __addr, size_t __size, int __prot, int __flags, int __fd, off_t __offset) __RENAME(mmap64);
+void* _Nonnull mmap(void* _Nullable __addr, size_t __size, int __prot, int __flags, int __fd, off_t __offset)
+# if !defined(__clang__) && __ANDROID_API__ < 21
+ __attribute__((error("mmap is not available with _FILE_OFFSET_BITS=64 when using GCC until "
+ "android-21. Either raise your minSdkVersion, disable "
Expand All @@ -355,5 +355,5 @@ diff -uNr a/sys/mman.h b/sys/mman.h
+ __RENAME(mmap64);
+# endif
#else
void* mmap(void* __addr, size_t __size, int __prot, int __flags, int __fd, off_t __offset);
void* _Nonnull mmap(void* _Nullable __addr, size_t __size, int __prot, int __flags, int __fd, off_t __offset);
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ Since g++ 13, `__is_convertible` is a builtin function.

[1] https://github.com/llvm/llvm-project/commit/484e64f7e7b2c0494d7b2dbfdd528bcd707ee652

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/type_traits
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/type_traits
@@ -1733,7 +1733,12 @@
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_convertible.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_convertible.h
@@ -24,7 +24,12 @@

// is_convertible
_LIBCPP_BEGIN_NAMESPACE_STD

-#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
-#if __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
+#if __has_builtin(__is_convertible) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
+
+template <class _T1, class _T2>
+struct _LIBCPP_TEMPLATE_VIS is_convertible : public integral_constant<bool, __is_convertible(_T1, _T2)> {};
+
+#elif __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
+#elif __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)

template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
: public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Since commit [1], libcxx has dropped the workaround for C11 features on
compilers that don't support attribute `using_if_exists`. They assume that
the underlying platform supports a C11 standard library, but that's not
true when targetting Android API 24.

[1]: https://github.com/llvm/llvm-project/commit/21f73d5826fb5024a27eaacafadfa316f58949c5

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__config
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__config
@@ -409,6 +409,18 @@
# define _LIBCPP_NO_CFI
# endif

+#if __has_attribute(using_if_exists)
+# define _LIBCPP_HAS_TIMESPEC_GET
+# define _LIBCPP_HAS_ALIGNED_ALLOC
+#elif defined(__BIONIC__)
+# if __ANDROID_API__ >= 28
+# define _LIBCPP_HAS_ALIGNED_ALLOC
+# endif
+# if __ANDROID_API__ >= 29
+# define _LIBCPP_HAS_TIMESPEC_GET
+# endif
+#endif
+
# ifndef _LIBCPP_CXX03_LANG

# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/cstdlib
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/cstdlib
@@ -144,7 +144,7 @@
using ::at_quick_exit _LIBCPP_USING_IF_EXISTS;
using ::quick_exit _LIBCPP_USING_IF_EXISTS;
#endif
-#if _LIBCPP_STD_VER > 14
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
using ::aligned_alloc _LIBCPP_USING_IF_EXISTS;
#endif

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ctime
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ctime
@@ -66,7 +66,7 @@
using ::size_t _LIBCPP_USING_IF_EXISTS;
using ::time_t _LIBCPP_USING_IF_EXISTS;
using ::tm _LIBCPP_USING_IF_EXISTS;
-#if _LIBCPP_STD_VER > 14
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
using ::timespec _LIBCPP_USING_IF_EXISTS;
#endif
using ::clock _LIBCPP_USING_IF_EXISTS;
@@ -78,7 +78,7 @@
using ::gmtime _LIBCPP_USING_IF_EXISTS;
using ::localtime _LIBCPP_USING_IF_EXISTS;
using ::strftime _LIBCPP_USING_IF_EXISTS;
-#if _LIBCPP_STD_VER > 14
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
using ::timespec_get _LIBCPP_USING_IF_EXISTS;
#endif

28 changes: 9 additions & 19 deletions tur/ndk-sysroot-gcc-compact/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ TERMUX_PKG_LICENSE="NCSA"
TERMUX_PKG_MAINTAINER="@licy183"
# Version should be equal to TERMUX_NDK_{VERSION_NUM,REVISION} in
# scripts/properties.sh
TERMUX_PKG_VERSION=25c
TERMUX_PKG_REVISION=1
TERMUX_PKG_VERSION=26b
TERMUX_PKG_SRCURL=https://dl.google.com/android/repository/android-ndk-r${TERMUX_PKG_VERSION}-linux.zip
TERMUX_PKG_SHA256=769ee342ea75f80619d985c2da990c48b3d8eaf45f48783a2d48870d04b46108
TERMUX_PKG_SHA256=ad73c0370f0b0a87d1671ed2fd5a9ac9acfd1eb5c43a7fbfbd330f85d19dd632
# This package has taken over <pty.h> from the previous libutil-dev
# and iconv.h from libandroid-support-dev:
TERMUX_PKG_CONFLICTS="libutil-dev, libandroid-support-dev, ndk-sysroot"
Expand Down Expand Up @@ -66,29 +65,20 @@ termux_step_make_install() {
cp toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$TERMUX_HOST_PLATFORM/$TERMUX_PKG_API_LEVEL/*.o \
$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/lib

if [ $TERMUX_ARCH == "i686" ]; then
LIBATOMIC=toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/*/lib/linux/i386
elif [ $TERMUX_ARCH == "arm64" ]; then
LIBATOMIC=toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/*/lib/linux/aarch64
else
LIBATOMIC=toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/*/lib/linux/$TERMUX_ARCH
fi

cp $LIBATOMIC/libatomic.a $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/lib/

cp toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$TERMUX_HOST_PLATFORM/libcompiler_rt-extras.a \
$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/lib/
# librt and libpthread are built into libc on android, so setup them as symlinks
# to libc for compatibility with programs that users try to build:
local _SYSTEM_LIBDIR=/system/lib64
if [ $TERMUX_ARCH_BITS = 32 ]; then _SYSTEM_LIBDIR=/system/lib; fi

NDK_ARCH=$TERMUX_ARCH
test $NDK_ARCH == 'i686' && NDK_ARCH='i386'

mkdir -p $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/lib
# clang 13 requires libunwind on Android.
cp toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/$NDK_ARCH/libunwind.a \
cp toolchains/llvm/prebuilt/linux-x86_64/lib/clang/*/lib/linux/$NDK_ARCH/libatomic.a \
$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/lib
cp toolchains/llvm/prebuilt/linux-x86_64/lib/clang/*/lib/linux/$NDK_ARCH/libunwind.a \
$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/lib

# librt and libpthread are built into libc on android, so setup them as symlinks
# to libc for compatibility with programs that users try to build:
for lib in librt.so libpthread.so libutil.so; do
echo 'INPUT(-lc)' > $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/lib/$lib
done
Expand Down

0 comments on commit eefa703

Please sign in to comment.