From 451ad7e5ee2aaff68212733fec00670a53518019 Mon Sep 17 00:00:00 2001 From: GlobalTechInfo Date: Sat, 21 Nov 2026 22:02:16 +0500 Subject: [PATCH 1/4] Extended toolkit: build script for the on-demand downloadable tool set Cross-compiles the self-contained GNU tools (xz, tar, jq) for the four shipped ABIs against NDK/bionic and packs them into a single device-extended-toolkit//{bin,lib} tarball the app fetches on demand (the distro-rootfs pattern), keeping the base APK lean. Conventions match build-device-toolkit.sh: -fPIE so .S is position-independent, -z max-page-size=4096 so every LOAD stays 4 KB aligned for proot, the autotools-timestamp touch, and the per-binary verify (arch + NEEDED bionic libc + 4 KB LOAD). jq uses the oniguruma its release tarball vendors under modules/. Opt-ins for the tools with a real precondition: --with-file (needs host autoconf), --with-tree (set TREE_URL; upstream moved), --with-curl (needs the bundled OpenSSL from build-openssh.sh). A tool that fails to fetch or build is skipped with a log, not fatal, unless --strict. --- native/build-extended-toolkit.sh | 271 +++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100755 native/build-extended-toolkit.sh diff --git a/native/build-extended-toolkit.sh b/native/build-extended-toolkit.sh new file mode 100755 index 0000000..47ebfa3 --- /dev/null +++ b/native/build-extended-toolkit.sh @@ -0,0 +1,271 @@ +#!/usr/bin/env bash +## +## Builds the on-demand "extended toolkit": a set of real GNU-style tools, +## one directory per shipped ABI, packed into a single downloadable +## tarball. It is NOT an APK asset: the app fetches and unpacks it on +## demand (the distro-rootfs pattern), which keeps the base APK small and +## lets the tool set grow without a new release of the app. +## +## Layout of the tarball (device-extended-toolkit//...): +## +## device-extended-toolkit/ +## aarch64/{bin,lib}/... armv7a/{bin,lib}/... i686/... x86_64/... +## +## The app adds `/bin` to PATH (before the lean toolkit, so a GNU +## tool wins over a busybox applet) and `/lib` to LD_LIBRARY_PATH +## when a tool bundles its own shared libraries. +## +## Two rules from the mosh/device-toolkit builds apply unchanged and are +## verified for every produced binary: dynamically linked against bionic +## (a static NDK executable aborts on the underaligned-TLS check), and every +## LOAD segment 4 KB aligned (-z max-page-size=4096). +## +## Tool sets. The default is the set whose sources are verified and that +## build clean against bionic with no host-side autotools: +## +## xz tar jq (jq ships with its oniguruma bundled) +## +## The rest are opt-in, each gated on a real precondition: +## --with-file `file`'s git archive needs ./autogen.sh (host autoconf) +## --with-tree `tree`'s upstream has moved; set TREE_URL to its source +## --with-curl `curl` needs a bundled OpenSSL (build-openssh.sh's) +## +## A tool whose source fails to fetch or build is *skipped with a log*, +## not fatal to the rest (the optional-tools rule), unless --strict. +## +## Usage: +## +## native/build-extended-toolkit.sh [--ndk ] [--with-file] +## [--with-tree] [--with-curl] +## [--strict] [--plan] +## [aarch64 armv7a x86_64 i686] +## +## Set EXT_TOOLS="xz tar" to build only a subset (used for testing). +## Set TMPDIR to move the work out of /tmp, a 2.9 GB tmpfs on this host. + +set -eu + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" + +NDK="" +WITH_FILE=0; WITH_TREE=0; WITH_CURL=0; STRICT=0; PLAN=0 +ARCHES=() +while [ $# -gt 0 ]; do + case "$1" in + --ndk) NDK="$2"; shift 2 ;; + --with-file) WITH_FILE=1; shift ;; + --with-tree) WITH_TREE=1; shift ;; + --with-curl) WITH_CURL=1; shift ;; + --strict) STRICT=1; shift ;; + --plan) PLAN=1; shift ;; + *) ARCHES+=("$1"); shift ;; + esac +done +[ -n "$NDK" ] || NDK="${ANDROID_NDK_ROOT:-${ANDROID_NDK:-/opt/ndk/android-ndk-r27c}}" +[ -d "$NDK" ] || { echo "!! NDK not found: $NDK" >&2; exit 1; } +TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64" +[ -d "$TOOLCHAIN" ] || TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/$(uname -m)" +[ -d "$TOOLCHAIN" ] || { echo "!! NDK toolchain not found under $NDK" >&2; exit 1; } + +[ ${#ARCHES[@]} -gt 0 ] || ARCHES=(aarch64 armv7a x86_64 i686) + +WORK="${TMPDIR:-/tmp}/redterm-extended-toolkit" +rm -rf "$WORK" +mkdir -p "$WORK/src" "$WORK/dist" + +VERSION=1 +ARTIFACT="device-extended-toolkit-v${VERSION}.tar.xz" + +# Pinned sources, each verified reachable. A missing file is not re-fetched, +# so a resume does not re-pay for a download. +TAR_VERSION=1.35 +XZ_VERSION=5.4.6 +JQ_VERSION=1.7.1 +FILE_TAG=FILE5_45 +FILE_VERSION=5.45 +CURL_VERSION=8.6.0 +# curl reuses the OpenSSL the OpenSSH build already produces, when present. +OPENSSL_DIR="${OPENSSL_DIR:-/tmp/redterm-openssh/openssl-3.5.0}" +# tree's upstream has moved; supply its source archive URL to build it. +TREE_URL="${TREE_URL:-}" + +TOOLS=(xz tar jq) +[ "$WITH_FILE" = 1 ] && TOOLS+=(file) +[ "$WITH_TREE" = 1 ] && TOOLS+=(tree) +[ "$WITH_CURL" = 1 ] && TOOLS+=(curl) +[ -n "${EXT_TOOLS:-}" ] && TOOLS=(${EXT_TOOLS}) + +say() { echo " $*"; } + +fetch() { # fetch (fatal: caller is in a guarded subshell) + local name="$1" url="$2" out="$3" + [ -f "$out" ] && { say "reuse $name source"; return 0; } + say "fetch $name" + curl -fL "$url" -o "$out" +} + +# The three autotools traps from the mosh/bash builds: timestamps that did +# not survive packaging make make try to regenerate its own input. +autotools_touch() { + touch aclocal.m4 2>/dev/null || true + sleep 1; touch configure config.h.in 2>/dev/null || true + sleep 1; find . -name 'Makefile.in' -exec touch {} + 2>/dev/null || true +} + +cross_env() { # sets CC CFLAGS LDFLAGS TARGET for the current arch + case "$arch" in + aarch64) TARGET="aarch64-linux-android" ;; + armv7a) TARGET="armv7a-linux-androideabi" ;; + x86_64) TARGET="x86_64-linux-android" ;; + i686) TARGET="i686-linux-android" ;; + *) echo "!! unknown arch '$arch'" >&2; exit 1 ;; + esac + CC="$TOOLCHAIN/bin/clang --target=${TARGET}24" + CFLAGS="-fPIE -D__ANDROID_API__=24 -Wl,-z,max-page-size=4096" + LDFLAGS="-Wl,-z,max-page-size=4096" +} + +# Each build_ runs in a fresh extracted source dir and copies output +# into $DEST/bin (and $DEST/lib for any bundled shared library). +DEST="" + +build_xz() { + fetch xz "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.gz" "$WORK/src/xz.tar.gz" + tar -xzf "$WORK/src/xz.tar.gz" -C . --strip-components=1 + autotools_touch + ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ + --disable-nls --disable-doc > "$WORK/xz-$arch.log" 2>&1 + make -j1 >> "$WORK/xz-$arch.log" 2>&1 + cp -f "$PWD/src/xz/xz" "$DEST/bin/xz" +} + +build_tar() { + fetch tar "https://ftp.gnu.org/gnu/tar/tar-${TAR_VERSION}.tar.xz" "$WORK/src/tar.tar.xz" + tar -xJf "$WORK/src/tar.tar.xz" -C . --strip-components=1 + autotools_touch + ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ + --disable-nls > "$WORK/tar-$arch.log" 2>&1 + make -j1 >> "$WORK/tar-$arch.log" 2>&1 + cp -f "$PWD/tar/tar" "$DEST/bin/tar" +} + +build_jq() { + # The release tarball vendors oniguruma under modules/, so build it + # bundled: no separate oniguruma fetch, which the release tarball does + # not carry as a standalone asset anyway. + fetch jq "https://github.com/jqlang/jq/releases/download/jq-${JQ_VERSION}/jq-${JQ_VERSION}.tar.gz" "$WORK/src/jq.tar.gz" + tar -xzf "$WORK/src/jq.tar.gz" -C . --strip-components=1 + autotools_touch + ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ + --with-oniguruma=bundled --without-readline --disable-gettext > "$WORK/jq-$arch.log" 2>&1 + make -j1 >> "$WORK/jq-$arch.log" 2>&1 + cp -f "$PWD/jq" "$DEST/bin/jq" +} + +build_file() { + [ -n "$FILE_VERSION" ] || return 1 + fetch file "https://github.com/file/file/archive/refs/tags/${FILE_TAG}.tar.gz" "$WORK/src/file.tar.gz" + tar -xzf "$WORK/src/file.tar.gz" -C . --strip-components=1 + # The git archive does not ship a configured `configure`. + if [ ! -x ./configure ]; then + say "file: autogen.sh (needs host autoconf/libtool)" + ./autogen.sh > "$WORK/file-$arch.log" 2>&1 || { say "skip file: autogen failed"; return 0; } + fi + ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ + --disable-nls > "$WORK/file-$arch.log" 2>&1 + make -j1 >> "$WORK/file-$arch.log" 2>&1 + cp -f "$PWD/file" "$DEST/bin/file" +} + +build_tree() { + [ -n "$TREE_URL" ] || { say "skip tree: set TREE_URL to its source archive"; return 0; } + fetch tree "$TREE_URL" "$WORK/src/tree.tar.gz" + tar -xzf "$WORK/src/tree.tar.gz" -C . --strip-components=1 + make -j1 CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" > "$WORK/tree-$arch.log" 2>&1 + cp -f "$PWD/tree" "$DEST/bin/tree" +} + +build_curl() { + [ -d "$OPENSSL_DIR" ] || { say "skip curl: no bundled OpenSSL at $OPENSSL_DIR (run build-openssh.sh)"; return 0; } + fetch curl "https://curl.se/download/curl-${CURL_VERSION}.tar.xz" "$WORK/src/curl.tar.xz" + tar -xJf "$WORK/src/curl.tar.xz" -C . --strip-components=1 + autotools_touch + ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ + --disable-shared --with-openssl="$OPENSSL_DIR" --without-zlib \ + --disable-nls > "$WORK/curl-$arch.log" 2>&1 + make -j1 >> "$WORK/curl-$arch.log" 2>&1 + cp -f "$PWD/src/.libs/curl" "$DEST/bin/curl" 2>/dev/null || cp -f "$PWD/.libs/curl" "$DEST/bin/curl" +} + +# Verify one produced tool exactly like build-device-toolkit.sh: right arch, +# dynamically linked against bionic libc, and every LOAD 4 KB aligned. +verify_bin() { + local bin="$1" name + name="$(basename "$bin")" + case "$arch" in + aarch64) want="ARM aarch64" ;; + armv7a) want="ARM, EABI" ;; + x86_64) want="x86-64" ;; + i686) want="Intel i386" ;; + esac + file "$bin" | grep -q "$want" || { echo "!! $arch/$name not $want: $(file "$bin" | cut -c1-70)" >&2; exit 1; } + "$TOOLCHAIN/bin/llvm-readelf" -d "$bin" | grep -qE "NEEDED.*(libc|libdl)" || { + echo "!! $arch/$name not linked against bionic libc" >&2; exit 1 + } + local max_align=0 a a_dec + for a in $("$TOOLCHAIN/bin/llvm-readelf" -lW "$bin" | awk '/LOAD/ {getline; print $NF}'); do + a_dec=$((a)); [ "$a_dec" -gt "$max_align" ] && max_align=$a_dec + done + [ "$max_align" -gt 0 ] || { echo "!! no LOAD segments in $arch/$name" >&2; exit 1; } + [ "$max_align" -le 4096 ] || { echo "!! $arch/$name LOAD align $max_align > 4096" >&2; exit 1; } + say "$arch/$name: $(stat -c%s "$bin") bytes, LOAD align $max_align" +} + +if [ "$PLAN" = 1 ]; then + echo "would build: $(echo "${TOOLS[*]}") for: $(echo "${ARCHES[*]}")" + echo "artifact: $ARTIFACT (layout device-extended-toolkit//{bin,lib})" + exit 0 +fi + +built=0; skipped=0 +for arch in "${ARCHES[@]}"; do + DEST="$WORK/dist/device-extended-toolkit/$arch" + rm -rf "$DEST"; mkdir -p "$DEST/bin" "$DEST/lib" + cross_env + say "=== $arch : ${TOOLS[*]} ===" + for tool in "${TOOLS[@]}"; do + d="$WORK/build-$tool-$arch"; rm -rf "$d"; mkdir -p "$d"; ( cd "$d" && "build_$tool" ) > /dev/null 2>&1 || true + cd "$WORK" + if [ -f "$DEST/bin/$tool" ]; then + verify_bin "$DEST/bin/$tool" + built=$((built + 1)) + else + skipped=$((skipped + 1)) + say "skip $arch/$tool (source or build failed; see $WORK/${tool}-$arch.log)" + [ "$STRICT" = 1 ] && { tail -20 "$WORK/${tool}-$arch.log"; echo "!! $tool failed for $arch (--strict)" >&2; exit 1; } + fi + done +done + +# Package the whole tree as one tarball: the app downloads it once and +# unpacks only its own ABI directory. +cd "$WORK/dist" +tar -cJf "$WORK/$ARTIFACT" device-extended-toolkit +cd "$WORK" +say "artifact: $WORK/$ARTIFACT ($(stat -c%s "$WORK/$ARTIFACT") bytes) [built=$built skipped=$skipped]" + +# Host smoke test where the host can run the build: aarch64 here. +case " ${ARCHES[*]} " in + *" aarch64 "*) + if [ "$(uname -m)" = "aarch64" ] && [ -f "$DEST/bin/tree" ] || [ -f "$WORK/dist/device-extended-toolkit/aarch64/bin/xz" ]; then + sysroot="$TOOLCHAIN/sysroot"; [ -d "$sysroot" ] || sysroot="$TOOLCHAIN/../sysroot" + export LD_LIBRARY_PATH="$sysroot/usr/lib:$sysroot/usr/lib64" + "$WORK/dist/device-extended-toolkit/aarch64/bin/xz" --help 2>/dev/null | head -1 || \ + say "smoke: xz did not run on host" + else + say "note: host is not aarch64; the smoke test is skipped" + fi + ;; +esac + +say "done: $(echo "${TOOLS[*]}") x $(echo "${ARCHES[*]}") -> $WORK/$ARTIFACT" From c1f05c75ebca6d13cec6b066878e29c0fa457bbd Mon Sep 17 00:00:00 2001 From: GlobalTechInfo Date: Sat, 21 Nov 2026 23:45:08 +0500 Subject: [PATCH 2/4] Extended toolkit: address the 8 review findings - --plan no longer deletes the workspace: move rm -rf/mkdir past the plan-only exit so a previous artifact and its logs survive a plan run. - curl: resolve the default OpenSSL prefix per arch to the installed ssl-$arch that build-openssh.sh produces (not the unbuilt source tree) and check for the installed libcrypto before configuring. - xz: --disable-shared links liblzma into the executable, so the staged file is a deployable ELF, not a libtool wrapper that verify_bin rejects. - tar/file: stage from src/ (GNU tar 1.35 and FILE5_45 build there). - curl: copy the static-build src/curl, keeping the .libs fallback. - verify_bin: read each LOAD row's own alignment ($1==LOAD) instead of getline'ing the next line, which could miss a 0x10000 LOAD. - the build loop captures top-level diagnostics in a per-attempt -.driver.log (separate from the configure-overwritten tool log) and reports that path on a skip. --- native/build-extended-toolkit.sh | 61 ++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/native/build-extended-toolkit.sh b/native/build-extended-toolkit.sh index 47ebfa3..6a6e9fc 100755 --- a/native/build-extended-toolkit.sh +++ b/native/build-extended-toolkit.sh @@ -70,8 +70,6 @@ TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64" [ ${#ARCHES[@]} -gt 0 ] || ARCHES=(aarch64 armv7a x86_64 i686) WORK="${TMPDIR:-/tmp}/redterm-extended-toolkit" -rm -rf "$WORK" -mkdir -p "$WORK/src" "$WORK/dist" VERSION=1 ARTIFACT="device-extended-toolkit-v${VERSION}.tar.xz" @@ -84,8 +82,9 @@ JQ_VERSION=1.7.1 FILE_TAG=FILE5_45 FILE_VERSION=5.45 CURL_VERSION=8.6.0 -# curl reuses the OpenSSL the OpenSSH build already produces, when present. -OPENSSL_DIR="${OPENSSL_DIR:-/tmp/redterm-openssh/openssl-3.5.0}" +# curl reuses the OpenSSL that build-openssh.sh already installs, per arch, +# under $WORK-of-that-script/ssl-$arch. An explicit OPENSSL_DIR overrides it. +OPENSSL_DIR="${OPENSSL_DIR:-}" # tree's upstream has moved; supply its source archive URL to build it. TREE_URL="${TREE_URL:-}" @@ -133,8 +132,12 @@ build_xz() { fetch xz "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.gz" "$WORK/src/xz.tar.gz" tar -xzf "$WORK/src/xz.tar.gz" -C . --strip-components=1 autotools_touch + # --disable-shared links liblzma *into* the xz executable: xz 5.4.x + # builds a shared liblzma by default and the staged file would be a + # libtool wrapper, not a deployable ELF (which verify_bin rejects). + # xz still links dynamically against bionic. ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ - --disable-nls --disable-doc > "$WORK/xz-$arch.log" 2>&1 + --disable-shared --disable-nls --disable-doc > "$WORK/xz-$arch.log" 2>&1 make -j1 >> "$WORK/xz-$arch.log" 2>&1 cp -f "$PWD/src/xz/xz" "$DEST/bin/xz" } @@ -146,7 +149,9 @@ build_tar() { ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ --disable-nls > "$WORK/tar-$arch.log" 2>&1 make -j1 >> "$WORK/tar-$arch.log" 2>&1 - cp -f "$PWD/tar/tar" "$DEST/bin/tar" + # GNU tar 1.35 declares its program in src/Makefile.am, so the binary is + # src/tar, not the source-root tar/. + cp -f "$PWD/src/tar" "$DEST/bin/tar" } build_jq() { @@ -174,7 +179,9 @@ build_file() { ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ --disable-nls > "$WORK/file-$arch.log" 2>&1 make -j1 >> "$WORK/file-$arch.log" 2>&1 - cp -f "$PWD/file" "$DEST/bin/file" + # The FILE5_45 executable is produced in src/, not the source root; it + # links bionic only (no bundled libraries to stage in $DEST/lib). + cp -f "$PWD/src/file" "$DEST/bin/file" } build_tree() { @@ -186,15 +193,28 @@ build_tree() { } build_curl() { - [ -d "$OPENSSL_DIR" ] || { say "skip curl: no bundled OpenSSL at $OPENSSL_DIR (run build-openssh.sh)"; return 0; } + # Prefer an explicit OPENSSL_DIR; otherwise the installed per-arch prefix + # build-openssh.sh produces (its work dir defaults to /tmp/redterm-openssh, + # so the installed tree is /tmp/redterm-openssh/ssl-$arch). + local sslprefix="${OPENSSL_DIR:-/tmp/redterm-openssh/ssl-$arch}" + # Check for the *installed* crypto library, not just the directory: the + # source tree has a Makefile but no libcrypto until build-openssh.sh runs. + if [ ! -f "$sslprefix/lib/libcrypto.a" ] && [ ! -f "$sslprefix/lib64/libcrypto.a" ]; then + say "skip curl: no installed OpenSSL at $sslprefix (run build-openssh.sh first)" + return 0 + fi fetch curl "https://curl.se/download/curl-${CURL_VERSION}.tar.xz" "$WORK/src/curl.tar.xz" tar -xJf "$WORK/src/curl.tar.xz" -C . --strip-components=1 autotools_touch ./configure --host="$TARGET" CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ - --disable-shared --with-openssl="$OPENSSL_DIR" --without-zlib \ + --disable-shared --with-openssl="$sslprefix" --without-zlib \ --disable-nls > "$WORK/curl-$arch.log" 2>&1 make -j1 >> "$WORK/curl-$arch.log" 2>&1 - cp -f "$PWD/src/.libs/curl" "$DEST/bin/curl" 2>/dev/null || cp -f "$PWD/.libs/curl" "$DEST/bin/curl" + # --disable-shared + static libcurl writes the executable to src/curl; + # keep the libtool .libs paths as a fallback for a shared build. + cp -f "$PWD/src/curl" "$DEST/bin/curl" 2>/dev/null || \ + cp -f "$PWD/src/.libs/curl" "$DEST/bin/curl" 2>/dev/null || \ + cp -f "$PWD/.libs/curl" "$DEST/bin/curl" } # Verify one produced tool exactly like build-device-toolkit.sh: right arch, @@ -213,7 +233,10 @@ verify_bin() { echo "!! $arch/$name not linked against bionic libc" >&2; exit 1 } local max_align=0 a a_dec - for a in $("$TOOLCHAIN/bin/llvm-readelf" -lW "$bin" | awk '/LOAD/ {getline; print $NF}'); do + # $1 is the segment type ("LOAD"), $NF its alignment. Reading the LOAD + # row's own last field (not the next line via getline) is what catches a + # 0x10000 LOAD that is followed by a 0x1000 one. + for a in $("$TOOLCHAIN/bin/llvm-readelf" -lW "$bin" | awk '$1 == "LOAD" {print $NF}'); do a_dec=$((a)); [ "$a_dec" -gt "$max_align" ] && max_align=$a_dec done [ "$max_align" -gt 0 ] || { echo "!! no LOAD segments in $arch/$name" >&2; exit 1; } @@ -227,6 +250,11 @@ if [ "$PLAN" = 1 ]; then exit 0 fi +# A plan-only run exited above, before the workspace was touched: --plan must +# not wipe a previous build's artifact or logs. Normal builds start clean. +rm -rf "$WORK" +mkdir -p "$WORK/src" "$WORK/dist" + built=0; skipped=0 for arch in "${ARCHES[@]}"; do DEST="$WORK/dist/device-extended-toolkit/$arch" @@ -234,15 +262,20 @@ for arch in "${ARCHES[@]}"; do cross_env say "=== $arch : ${TOOLS[*]} ===" for tool in "${TOOLS[@]}"; do - d="$WORK/build-$tool-$arch"; rm -rf "$d"; mkdir -p "$d"; ( cd "$d" && "build_$tool" ) > /dev/null 2>&1 || true + d="$WORK/build-$tool-$arch"; rm -rf "$d"; mkdir -p "$d" + # The driver log keeps the top-level messages (a "skip tree: set + # TREE_URL", a fetch failure) that the tool's own ${tool}-$arch.log + # (written by configure/make) does not. Kept apart so the driver's + # stdout is not discarded, as it was with > /dev/null. + ( cd "$d" && "build_$tool" ) > "$WORK/${tool}-$arch.driver.log" 2>&1 || true cd "$WORK" if [ -f "$DEST/bin/$tool" ]; then verify_bin "$DEST/bin/$tool" built=$((built + 1)) else skipped=$((skipped + 1)) - say "skip $arch/$tool (source or build failed; see $WORK/${tool}-$arch.log)" - [ "$STRICT" = 1 ] && { tail -20 "$WORK/${tool}-$arch.log"; echo "!! $tool failed for $arch (--strict)" >&2; exit 1; } + say "skip $arch/$tool (see $WORK/${tool}-$arch.driver.log)" + [ "$STRICT" = 1 ] && { tail -20 "$WORK/${tool}-$arch.driver.log"; echo "!! $tool failed for $arch (--strict)" >&2; exit 1; } fi done done From 8a814a10efae40a4c187e5d74868577dab844b53 Mon Sep 17 00:00:00 2001 From: GlobalTechInfo Date: Sun, 22 Nov 2026 03:34:15 +0500 Subject: [PATCH 3/4] Extended toolkit: -fPIC for bundled sub-builds; note the measured tar bionic failure CFLAGS now uses -fPIC (a superset of the -fPIE that only covered the .S files): jq's bundled oniguruma compiles its own objects and they must be PIC to link into the PIE executable (measured: ld.lld 'recompile with -fPIC'). xz still builds under -fPIC. Also records, measured on this host, that GNU tar fails its aarch64 build on bionic (undeclared mktime_z) and is therefore skipped with a log; the loop ships the rest. --- native/build-extended-toolkit.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/native/build-extended-toolkit.sh b/native/build-extended-toolkit.sh index 6a6e9fc..49f9283 100755 --- a/native/build-extended-toolkit.sh +++ b/native/build-extended-toolkit.sh @@ -120,7 +120,10 @@ cross_env() { # sets CC CFLAGS LDFLAGS TARGET for the current arch *) echo "!! unknown arch '$arch'" >&2; exit 1 ;; esac CC="$TOOLCHAIN/bin/clang --target=${TARGET}24" - CFLAGS="-fPIE -D__ANDROID_API__=24 -Wl,-z,max-page-size=4096" + # -fPIC (not just -fPIE) for the .S and C alike: the executable links PIE, + # and a bundled sub-build like jq's oniguruma compiles its own objects and + # must be PIC or the PIE link fails with a non-PC-relative relocation. + CFLAGS="-fPIC -D__ANDROID_API__=24 -Wl,-z,max-page-size=4096" LDFLAGS="-Wl,-z,max-page-size=4096" } @@ -143,6 +146,11 @@ build_xz() { } build_tar() { + # Measured on this host (aarch64): GNU tar's strftime.c calls mktime_z, + # which the cross configure does not declare for bionic, so the build + # fails on C99 implicit-declaration and the tool is skipped with a log + # (the loop ships the rest). If a --with-tar source or patch is found, + # it will build; the binary lands in src/ (see below). fetch tar "https://ftp.gnu.org/gnu/tar/tar-${TAR_VERSION}.tar.xz" "$WORK/src/tar.tar.xz" tar -xJf "$WORK/src/tar.tar.xz" -C . --strip-components=1 autotools_touch From 5c419ba7de49d7878265446a32d5418dce3f387b Mon Sep 17 00:00:00 2001 From: GlobalTechInfo Date: Sun, 22 Nov 2026 13:13:48 +0500 Subject: [PATCH 4/4] Extended toolkit: make tar opt-in; default to the verified {xz, jq} The aarch64 build confirms xz and jq build and pass verify_bin (jq after the -fPIC fix). tar is a measured bionic blocker -- bionic gates mktime_z/localtime_rz/timezone_t to API 35 and the toolkit targets API 24, so GNU tar's gnu/nstrftime.c fails on the undeclared mktime_z. The correct fix is forcing gnulib's bundled time_rz.c (API-independent), which is deferred; building tar at API 35 is wrong for a minSdk-24 app. Keep the default artifact to what is verified ({xz, jq}) and let tar opt in behind the now-documented --with-tar flag. --- native/build-extended-toolkit.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/native/build-extended-toolkit.sh b/native/build-extended-toolkit.sh index 49f9283..88900e0 100755 --- a/native/build-extended-toolkit.sh +++ b/native/build-extended-toolkit.sh @@ -23,9 +23,11 @@ ## Tool sets. The default is the set whose sources are verified and that ## build clean against bionic with no host-side autotools: ## -## xz tar jq (jq ships with its oniguruma bundled) +## xz jq (jq ships with its oniguruma bundled) ## ## The rest are opt-in, each gated on a real precondition: +## --with-tar bionic gates mktime_z/localtime_rz/timezone_t to API 35; +## the correct fix is forcing gnulib's bundled time_rz.c ## --with-file `file`'s git archive needs ./autogen.sh (host autoconf) ## --with-tree `tree`'s upstream has moved; set TREE_URL to its source ## --with-curl `curl` needs a bundled OpenSSL (build-openssh.sh's) @@ -36,7 +38,7 @@ ## Usage: ## ## native/build-extended-toolkit.sh [--ndk ] [--with-file] -## [--with-tree] [--with-curl] +## [--with-tar] [--with-tree] [--with-curl] ## [--strict] [--plan] ## [aarch64 armv7a x86_64 i686] ## @@ -48,12 +50,13 @@ set -eu REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" NDK="" -WITH_FILE=0; WITH_TREE=0; WITH_CURL=0; STRICT=0; PLAN=0 +WITH_FILE=0; WITH_TAR=0; WITH_TREE=0; WITH_CURL=0; STRICT=0; PLAN=0 ARCHES=() while [ $# -gt 0 ]; do case "$1" in --ndk) NDK="$2"; shift 2 ;; --with-file) WITH_FILE=1; shift ;; + --with-tar) WITH_TAR=1; shift ;; --with-tree) WITH_TREE=1; shift ;; --with-curl) WITH_CURL=1; shift ;; --strict) STRICT=1; shift ;; @@ -88,8 +91,9 @@ OPENSSL_DIR="${OPENSSL_DIR:-}" # tree's upstream has moved; supply its source archive URL to build it. TREE_URL="${TREE_URL:-}" -TOOLS=(xz tar jq) +TOOLS=(xz jq) [ "$WITH_FILE" = 1 ] && TOOLS+=(file) +[ "$WITH_TAR" = 1 ] && TOOLS+=(tar) [ "$WITH_TREE" = 1 ] && TOOLS+=(tree) [ "$WITH_CURL" = 1 ] && TOOLS+=(curl) [ -n "${EXT_TOOLS:-}" ] && TOOLS=(${EXT_TOOLS}) @@ -146,11 +150,14 @@ build_xz() { } build_tar() { - # Measured on this host (aarch64): GNU tar's strftime.c calls mktime_z, - # which the cross configure does not declare for bionic, so the build - # fails on C99 implicit-declaration and the tool is skipped with a log - # (the loop ships the rest). If a --with-tar source or patch is found, - # it will build; the binary lands in src/ (see below). + # Measured root cause for --with-tar not building by default: bionic's + # timezone_t / mktime_z / localtime_rz are declared only at __INTRODUCED_IN + # 35, and this toolkit targets API 24, so GNU tar's gnu/nstrftime.c calls + # mktime_z with no visible declaration and the C99 build fails. The + # correct fix is forcing gnulib's bundled gnu/time_rz.c (which defines all + # three, API-independent) -- that is gnulib module surgery deferred here; + # building tar at API 35 instead would break it on this app's minSdk 24. + # When enabled, the binary lands in src/ (GNU tar declares it there). fetch tar "https://ftp.gnu.org/gnu/tar/tar-${TAR_VERSION}.tar.xz" "$WORK/src/tar.tar.xz" tar -xJf "$WORK/src/tar.tar.xz" -C . --strip-components=1 autotools_touch