diff --git a/tur-on-device/bazel6/0001-strerror_r.patch b/tur-on-device/bazel6/0001-strerror_r.patch new file mode 100644 index 0000000..023d4ee --- /dev/null +++ b/tur-on-device/bazel6/0001-strerror_r.patch @@ -0,0 +1,13 @@ +Bionic libc's `strerror_r` returns `char *`, which is the same as GNU libc. + +--- a/src/main/native/unix_jni_linux.cc ++++ b/src/main/native/unix_jni_linux.cc +@@ -31,7 +31,7 @@ + // functionality which is not compatible with not the + // SUSv3-conformant one which returns an error code; see DESCRIPTION + // at strerror(3). +-#if !__GLIBC__ || (_POSIX_C_SOURCE >= 200112L && !_GNU_SOURCE) ++#if (!__GLIBC__ && !defined(__ANDROID__)) || (_POSIX_C_SOURCE >= 200112L && !_GNU_SOURCE) + if (strerror_r(error_number, buf, sizeof buf) == -1) { + return std::string(""); + } else { diff --git a/tur-on-device/bazel6/0002-impl-wait3.patch b/tur-on-device/bazel6/0002-impl-wait3.patch new file mode 100644 index 0000000..3b16779 --- /dev/null +++ b/tur-on-device/bazel6/0002-impl-wait3.patch @@ -0,0 +1,14 @@ +--- a/src/main/tools/process-tools.cc ++++ b/src/main/tools/process-tools.cc +@@ -217,7 +217,11 @@ + // Discard any zombies that we may get when the child subreaper feature is + // enabled. + do { ++#ifndef __ANDROID__ + err = wait3(&status, 0, rusage); ++#else ++ err = wait4(-1, &status, 0, rusage); ++#endif + } while (err != pid || (err == -1 && errno == EINTR)); + } else { + do { diff --git a/tur-on-device/bazel6/0003-disable-sandbox.patch b/tur-on-device/bazel6/0003-disable-sandbox.patch new file mode 100644 index 0000000..b91bc05 --- /dev/null +++ b/tur-on-device/bazel6/0003-disable-sandbox.patch @@ -0,0 +1,12 @@ +`sandbox` will not work on Android due to SELinux rules + +--- a/src/main/tools/BUILD ++++ b/src/main/tools/BUILD +@@ -75,6 +75,7 @@ + "//src/conditions:freebsd": ["dummy-sandbox.c"], + "//src/conditions:openbsd": ["dummy-sandbox.c"], + "//src/conditions:windows": ["dummy-sandbox.c"], ++ "//src/conditions:linux": ["dummy-sandbox.c"], + "//conditions:default": [ + "linux-sandbox.cc", + "linux-sandbox.h", diff --git a/tur-on-device/bazel6/0004-spawn.patch b/tur-on-device/bazel6/0004-spawn.patch new file mode 100644 index 0000000..6564732 --- /dev/null +++ b/tur-on-device/bazel6/0004-spawn.patch @@ -0,0 +1,10 @@ +--- a/src/main/cpp/BUILD ++++ b/src/main/cpp/BUILD +@@ -54,6 +54,7 @@ + "//src/conditions:windows": WIN_LINK_OPTS, + "//conditions:default": [ + "-lrt", ++ "-l:libandroid-spawn.a", + ], + }), + deps = [ diff --git a/tur-on-device/bazel6/0005-import-termux-patches.patch b/tur-on-device/bazel6/0005-import-termux-patches.patch new file mode 100644 index 0000000..7a09d35 --- /dev/null +++ b/tur-on-device/bazel6/0005-import-termux-patches.patch @@ -0,0 +1,55 @@ +--- a/third_party/BUILD ++++ b/third_party/BUILD +@@ -46,6 +46,7 @@ + "//third_party/py/mock:srcs", + "//third_party/py/six:srcs", + "//third_party/rules_python:srcs", ++ "//third_party/termux-patches:srcs", + "//third_party/zlib:srcs", + "//third_party/upb:srcs", + "@googleapis//:srcs", +--- a/distdir_deps.bzl ++++ b/distdir_deps.bzl +@@ -105,7 +105,10 @@ + "https://github.com/protocolbuffers/protobuf/archive/v3.19.6.tar.gz", + ], + "patch_args": ["-p1"], +- "patches": ["//third_party/protobuf:3.19.6.patch"], ++ "patches": [ ++ "//third_party/protobuf:3.19.6.patch", ++ "//third_party/termux-patches:protobuf.patch", ++ ], + "used_in": [ + "additional_distfiles", + "test_WORKSPACE_files", +@@ -123,6 +126,8 @@ + "patches": [ + "//third_party/grpc:grpc_1.47.0.patch", + "//third_party/grpc:grpc_1.47.0.win_arm64.patch", ++ "//third_party/termux-patches:grpc.patch", ++ "//third_party/termux-patches:cares-config.patch", + ], + "used_in": [ + "additional_distfiles", +@@ -196,6 +200,10 @@ + "https://mirror.bazel.build/github.com/protocolbuffers/upb/archive/a5477045acaa34586420942098f5fecd3570f577.tar.gz", + "https://github.com/protocolbuffers/upb/archive/a5477045acaa34586420942098f5fecd3570f577.tar.gz", + ], ++ "patch_args": ["-p1"], ++ "patches": [ ++ "//third_party/termux-patches:upb-config.patch", ++ ], + "used_in": [ + "additional_distfiles", + "test_WORKSPACE_files", +@@ -211,6 +219,10 @@ + "https://mirror.bazel.build/github.com/c-ares/c-ares/archive/6654436a307a5a686b008c1d4c93b0085da6e6d8.tar.gz", + "https://github.com/c-ares/c-ares/archive/6654436a307a5a686b008c1d4c93b0085da6e6d8.tar.gz", + ], ++ "patch_args": ["-p1"], ++ "patches": [ ++ "//third_party/termux-patches:cares.patch", ++ ], + "used_in": [ + "additional_distfiles", + "test_WORKSPACE_files", diff --git a/tur-on-device/bazel6/0006-force-use-external-patch_tools.patch b/tur-on-device/bazel6/0006-force-use-external-patch_tools.patch new file mode 100644 index 0000000..2bd23ef --- /dev/null +++ b/tur-on-device/bazel6/0006-force-use-external-patch_tools.patch @@ -0,0 +1,14 @@ +Don't know why `grpc.patch` cannot be patched with builtin_patch_tool of bazel. +No matter what, force using the external patch_tool. + +--- a/tools/build_defs/repo/utils.bzl ++++ b/tools/build_defs/repo/utils.bzl +@@ -144,7 +144,7 @@ + patch_tool = ctx.attr.patch_tool + if not patch_tool: + patch_tool = "patch" +- native_patch = True ++ native_patch = False + else: + native_patch = False + diff --git a/tur-on-device/bazel6/0007-disable-module_maps.patch b/tur-on-device/bazel6/0007-disable-module_maps.patch new file mode 100644 index 0000000..ba9014b --- /dev/null +++ b/tur-on-device/bazel6/0007-disable-module_maps.patch @@ -0,0 +1,11 @@ +--- a/tools/cpp/unix_cc_toolchain_config.bzl ++++ b/tools/cpp/unix_cc_toolchain_config.bzl +@@ -37,7 +37,7 @@ + return xcode_config.minimum_os_for_platform_type(platform_type) + + def layering_check_features(compiler): +- if compiler != "clang": ++ if True: + return [] + return [ + feature( diff --git a/tur-on-device/bazel6/0008-run-elf-cleaner-for-bazel-tools.patch b/tur-on-device/bazel6/0008-run-elf-cleaner-for-bazel-tools.patch new file mode 100644 index 0000000..a7d8074 --- /dev/null +++ b/tur-on-device/bazel6/0008-run-elf-cleaner-for-bazel-tools.patch @@ -0,0 +1,236 @@ +For a `cc_binary` target that will be packaged, replace its name (`@ORIGIN_NAME@`) +with `@ORIGIN_NAME@_orig`, and add the following target after it. + +``` +genrule( + name = "@ORIGIN_NAME@_cleaner", + srcs = [ + ":@ORIGIN_NAME@_orig", + ], + outs = ["@ORIGIN_NAME@"], + cmd = "\n".join([ + "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", + "cp \"$(location :@ORIGIN_NAME@_orig)\" \"$${TEMP_FILE}\"", + "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", + "cp \"$${TEMP_FILE}\" \"$@\"", + "rm \"$${TEMP_FILE}\"", + ]), +) +``` +# TODO: Figure out why `ijar` cannot be patched +# --- a/third_party/ijar/BUILD +# +++ b/third_party/ijar/BUILD +# @@ -70,22 +70,66 @@ +# ) + +# cc_binary( +# - name = "zipper", +# + name = "zipper_orig", +# srcs = ["zip_main.cc"], +# - visibility = ["//visibility:public"], +# + visibility = ["//visibility:private"], +# deps = [":zip"], +# ) + +# +genrule( +# + name = "zipper_cleaner", +# + srcs = [ +# + ":zipper_orig", +# + ], +# + outs = ["zipper_"], +# + cmd = "\n".join([ +# + "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", +# + "cp \"$(location :zipper_orig)\" \"$${TEMP_FILE}\"", +# + "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", +# + "cp \"$${TEMP_FILE}\" \"$@\"", +# + "rm \"$${TEMP_FILE}\"", +# + ]), +# + visibility = ["//visibility:private"], +# +) +# + +# +alias( +# + name = "zipper", +# + actual = ":zipper_", +# + visibility = ["//visibility:public"], +# +) +# + +# cc_binary( +# - name = "ijar", +# + name = "ijar_orig", +# srcs = [ +# "classfile.cc", +# "ijar.cc", +# ], +# - visibility = ["//visibility:public"], +# + visibility = ["//visibility:private"], +# deps = [":zip"], +# ) + +# +genrule( +# + name = "ijar_cleaner", +# + srcs = [ +# + ":ijar_orig", +# + ], +# + outs = ["ijar_"], +# + cmd = "\n".join([ +# + "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", +# + "cp \"$(location :ijar_orig)\" \"$${TEMP_FILE}\"", +# + "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", +# + "cp \"$${TEMP_FILE}\" \"$@\"", +# + "rm \"$${TEMP_FILE}\"", +# + ]), +# + visibility = ["//visibility:private"], +# +) +# + +# +alias( +# + name = "ijar", +# + actual = ":ijar_", +# + visibility = ["//visibility:public"], +# +) +# + +# filegroup( +# name = "srcs", +# srcs = glob(["**"]) + ["//third_party/ijar/test:srcs"], +--- a/src/main/cpp/BUILD ++++ b/src/main/cpp/BUILD +@@ -88,7 +89,7 @@ + ) + + cc_binary( +- name = "client", ++ name = "client_orig", + srcs = [ + "blaze.cc", + "blaze.h", +@@ -138,6 +139,21 @@ + ], + ) + ++genrule( ++ name = "client_cleaner", ++ srcs = [ ++ ":client_orig", ++ ], ++ outs = ["client"], ++ cmd = "\n".join([ ++ "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", ++ "cp \"$(location :client_orig)\" \"$${TEMP_FILE}\"", ++ "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", ++ "cp \"$${TEMP_FILE}\" \"$@\"", ++ "rm \"$${TEMP_FILE}\"", ++ ]), ++) ++ + cc_library( + name = "option_processor", + srcs = ["option_processor.cc"], +--- a/src/main/tools/BUILD ++++ b/src/main/tools/BUILD +@@ -1,10 +1,25 @@ + package(default_visibility = ["//src:__subpackages__"]) + + cc_binary( +- name = "daemonize", ++ name = "daemonize_orig", + srcs = ["daemonize.c"], + ) + ++genrule( ++ name = "daemonize_cleaner", ++ srcs = [ ++ ":daemonize_orig", ++ ], ++ outs = ["daemonize"], ++ cmd = "\n".join([ ++ "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", ++ "cp \"$(location :daemonize_orig)\" \"$${TEMP_FILE}\"", ++ "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", ++ "cp \"$${TEMP_FILE}\" \"$@\"", ++ "rm \"$${TEMP_FILE}\"", ++ ]), ++) ++ + cc_library( + name = "logging", + srcs = ["logging.cc"], +@@ -26,7 +41,7 @@ + ) + + cc_binary( +- name = "process-wrapper", ++ name = "process-wrapper_orig", + srcs = select({ + "//src/conditions:windows": ["process-wrapper-windows.cc"], + "//conditions:default": [ +@@ -56,8 +71,23 @@ + }), + ) + ++genrule( ++ name = "process-wrapper_cleaner", ++ srcs = [ ++ ":process-wrapper_orig", ++ ], ++ outs = ["process-wrapper"], ++ cmd = "\n".join([ ++ "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", ++ "cp \"$(location :process-wrapper_orig)\" \"$${TEMP_FILE}\"", ++ "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", ++ "cp \"$${TEMP_FILE}\" \"$@\"", ++ "rm \"$${TEMP_FILE}\"", ++ ]), ++) ++ + cc_binary( +- name = "build-runfiles", ++ name = "build-runfiles_orig", + srcs = select({ + "//src/conditions:windows": ["build-runfiles-windows.cc"], + "//conditions:default": ["build-runfiles.cc"], +@@ -68,8 +98,23 @@ + }), + ) + ++genrule( ++ name = "build-runfiles_cleaner", ++ srcs = [ ++ ":build-runfiles_orig", ++ ], ++ outs = ["build-runfiles"], ++ cmd = "\n".join([ ++ "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", ++ "cp \"$(location :build-runfiles_orig)\" \"$${TEMP_FILE}\"", ++ "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", ++ "cp \"$${TEMP_FILE}\" \"$@\"", ++ "rm \"$${TEMP_FILE}\"", ++ ]), ++) ++ + cc_binary( +- name = "linux-sandbox", ++ name = "linux-sandbox_orig", + srcs = select({ + "//src/conditions:darwin": ["dummy-sandbox.c"], + "//src/conditions:freebsd": ["dummy-sandbox.c"], +@@ -108,6 +153,21 @@ + }), + ) + ++genrule( ++ name = "linux-sandbox_cleaner", ++ srcs = [ ++ ":linux-sandbox_orig", ++ ], ++ outs = ["linux-sandbox"], ++ cmd = "\n".join([ ++ "TEMP_FILE=\"$$(mktemp -t bazel.XXXXXXXX)\"", ++ "cp \"$(location :linux-sandbox_orig)\" \"$${TEMP_FILE}\"", ++ "termux-elf-cleaner --api-level=24 \"$${TEMP_FILE}\"", ++ "cp \"$${TEMP_FILE}\" \"$@\"", ++ "rm \"$${TEMP_FILE}\"", ++ ]), ++) ++ + exports_files([ + "build_interface_so", + ]) diff --git a/tur-on-device/bazel6/0009-bazelrc-path.patch b/tur-on-device/bazel6/0009-bazelrc-path.patch new file mode 100644 index 0000000..3c573ee --- /dev/null +++ b/tur-on-device/bazel6/0009-bazelrc-path.patch @@ -0,0 +1,11 @@ +--- a/src/main/cpp/BUILD ++++ b/src/main/cpp/BUILD +@@ -178,7 +161,7 @@ + # For posix platforms, this can include environment variables in the + # form ${var_name}. Braces are required. + "//conditions:default": [ +- "-DBAZEL_SYSTEM_BAZELRC_PATH=\\\"/etc/bazel.bazelrc\\\"", ++ "-DBAZEL_SYSTEM_BAZELRC_PATH=\\\"@TERMUX_PREFIX@/etc/bazel.bazelrc\\\"", + ], + }), + visibility = [ diff --git a/tur-on-device/bazel6/0010-jdk-17.patch b/tur-on-device/bazel6/0010-jdk-17.patch new file mode 100644 index 0000000..d248d89 --- /dev/null +++ b/tur-on-device/bazel6/0010-jdk-17.patch @@ -0,0 +1,12 @@ +https://github.com/bazelbuild/bazel/commit/af50ad37eda9173f6c1ffe50c8522b67f70baf79 + +--- a/scripts/bootstrap/compile.sh ++++ b/scripts/bootstrap/compile.sh +@@ -450,6 +450,7 @@ function run_bazel_jar() { + -XX:+HeapDumpOnOutOfMemoryError -Xverify:none -Dfile.encoding=ISO-8859-1 \ + -XX:HeapDumpPath=${OUTPUT_DIR} \ + -Djava.util.logging.config.file=${OUTPUT_DIR}/javalog.properties \ ++ --add-opens java.base/java.lang=ALL-UNNAMED \ + ${JNI_FLAGS} \ + -jar ${ARCHIVE_DIR}/libblaze.jar \ + --batch \ diff --git a/tur-on-device/bazel6/0011-fix-patch-eol.patch b/tur-on-device/bazel6/0011-fix-patch-eol.patch new file mode 100644 index 0000000..b8dfc31 --- /dev/null +++ b/tur-on-device/bazel6/0011-fix-patch-eol.patch @@ -0,0 +1,9 @@ +--- a/third_party/cncf_udpa/cncf_udpa_0.0.1.patch ++++ b/third_party/cncf_udpa/cncf_udpa_0.0.1.patch +@@ -155,4 +155,4 @@ + +# "//udpa/service/orca/v1:pkg_go_proto", + +# "//udpa/type/v1:pkg_go_proto", + +# ], +-+#) +\ No newline at end of file +++#) diff --git a/tur-on-device/bazel6/build.sh b/tur-on-device/bazel6/build.sh new file mode 100644 index 0000000..fd344af --- /dev/null +++ b/tur-on-device/bazel6/build.sh @@ -0,0 +1,124 @@ +TERMUX_PKG_HOMEPAGE=https://bazel.build/ +TERMUX_PKG_DESCRIPTION="Correct, reproducible, and fast builds for everyone" +TERMUX_PKG_LICENSE="Apache-2.0" +TERMUX_PKG_MAINTAINER="@termux-user-repository" +TERMUX_PKG_VERSION="6.5.0" +TERMUX_PKG_SRCURL=https://github.com/bazelbuild/bazel/releases/download/$TERMUX_PKG_VERSION/bazel-$TERMUX_PKG_VERSION-dist.zip +TERMUX_PKG_SHA256=fc89da919415289f29e4ff18a5e01270ece9a6fe83cb60967218bac4a3bb3ed2 +TERMUX_PKG_DEPENDS="libarchive, openjdk-17, patch, unzip, zip" +TERMUX_PKG_BUILD_DEPENDS="libandroid-spawn-static, which" +TERMUX_PKG_BREAKS="openjdk-11" +TERMUX_PKG_BUILD_IN_SRC=true +TERMUX_PKG_BLACKLISTED_ARCHES="arm, i686" + +__ensure_is_on_device_compile() { + if [ "${TERMUX_ON_DEVICE_BUILD}" = false ]; then + termux_error_exit "This package doesn't support cross-compiling." + fi +} + +__sed_verbose() { + local path=$1; shift; + sed --follow-symlinks -i".bak-nix" "$@" "$path" + diff -U0 "$path.bak-nix" "$path" | sed "s/^/ /" || true + rm -f "$path.bak-nix" +} + +__fix_harcoded_paths() { + # Ref: https://github.com/NixOS/nixpkgs/blob/release-23.11/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix + + # Unzip builtins_bzl.zip so the contents get patched + local builtins_bzl=src/main/java/com/google/devtools/build/lib/bazel/rules/builtins_bzl + unzip ${builtins_bzl}.zip -d ${builtins_bzl}_zip >/dev/null + rm ${builtins_bzl}.zip + builtins_bzl=''${builtins_bzl}_zip/builtins_bzl + + echo + echo "Substituting */bin/* hardcoded paths in src/main/java/com/google/devtools" + # Prefilter the files with grep for speed + grep -rlZ /bin/ \ + src/main/java/com/google/devtools \ + src/main/starlark/builtins_bzl/common/python \ + tools \ + | while IFS="" read -r -d "" path; do + # If you add more replacements here, you must change the grep above! + # Only files containing /bin are taken into account. + __sed_verbose "$path" \ + -e "s!/usr/local/bin/bash!${TERMUX_PREFIX}/bin/bash!g" \ + -e "s!/usr/bin/bash!${TERMUX_PREFIX}/bin/bash!g" \ + -e "s!/bin/bash!${TERMUX_PREFIX}/bin/bash!g" \ + -e "s!/usr/bin/env bash!${TERMUX_PREFIX}/bin/bash!g" \ + -e "s!/usr/bin/env python2!${TERMUX_PREFIX}/bin/python!g" \ + -e "s!/usr/bin/env python!${TERMUX_PREFIX}/bin/python!g" \ + -e "s!/usr/bin/env!${TERMUX_PREFIX}/bin/env!g" \ + -e "s!/bin/true!${TERMUX_PREFIX}/bin/true!g" + done + + # Fixup scripts that generate scripts. Not fixed up by patchShebangs below. + __sed_verbose scripts/bootstrap/compile.sh \ + -e "s!/bin/bash!${TERMUX_PREFIX}/bin/bash!g" + + # reconstruct the now patched builtins_bzl.zip + pushd src/main/java/com/google/devtools/build/lib/bazel/rules/builtins_bzl_zip &>/dev/null + zip ../builtins_bzl.zip $(find builtins_bzl -type f) >/dev/null + rm -rf builtins_bzl + popd &>/dev/null + rmdir src/main/java/com/google/devtools/build/lib/bazel/rules/builtins_bzl_zip + + # Fix shebangs + while IFS= read -r -d '' file; do + if head -c 100 "$file" | head -n 1 | grep -E "^#!.*/bin/.*" | grep -q -E -v "^#! ?$TERMUX_PREFIX"; then + __sed_verbose "$file" -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" + fi + done < <(find -L . -type f -print0) +} + +termux_step_get_source() { + local f="$(basename "${TERMUX_PKG_SRCURL}")" + termux_download \ + "${TERMUX_PKG_SRCURL}" \ + "$TERMUX_PKG_CACHEDIR/${f}" \ + "${TERMUX_PKG_SHA256}" + mkdir -p "$TERMUX_PKG_SRCDIR" + unzip -d "$TERMUX_PKG_SRCDIR" "$TERMUX_PKG_CACHEDIR/${f}" > /dev/null +} + +termux_step_post_get_source() { + # Fix hardcoded paths + __fix_harcoded_paths + + # Copy patches + rm -rf third_party/termux-patches/ + mkdir -p third_party/termux-patches/ + cp -Rfv $TERMUX_PKG_BUILDER_DIR/dep-patches/* third_party/termux-patches/ +} + +termux_step_pre_configure() { + __ensure_is_on_device_compile + + # Ensure openjdk-17 is installed + apt autoremove --purge openjdk* -y + apt install --reinstall openjdk-17 -y + + export JAVA_HOME="$TERMUX_PREFIX/lib/jvm/java-17-openjdk" +} + +termux_step_make() { + # Compile bazel + local EXTRA_BAZEL_ARGS="" + # EXTRA_BAZEL_ARGS+=" --keep_going" + EXTRA_BAZEL_ARGS+=" --verbose_failures" + EXTRA_BAZEL_ARGS+=" --action_env=ANDROID_DATA" + EXTRA_BAZEL_ARGS+=" --action_env=ANDROID_ROOT" + EXTRA_BAZEL_ARGS+=" --action_env=LD_PRELOAD" + EXTRA_BAZEL_ARGS+=" --tool_java_runtime_version=local_jdk" + EMBED_LABEL=$TERMUX_PKG_VERSION EXTRA_BAZEL_ARGS="$EXTRA_BAZEL_ARGS" VERBOSE=1 ./compile.sh +} + +termux_step_make_install() { + install -Dm700 ./output/bazel $TERMUX_PREFIX/bin/bazel-$TERMUX_PKG_VERSION +} + +termux_step_post_massage() { + rm -rf lib var share/doc/openjdk-17 +} diff --git a/tur-on-device/bazel6/dep-patches/BUILD b/tur-on-device/bazel6/dep-patches/BUILD new file mode 100644 index 0000000..20577ae --- /dev/null +++ b/tur-on-device/bazel6/dep-patches/BUILD @@ -0,0 +1,7 @@ +licenses(["notice"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), # glob everything to satisfy the compile.sh srcs test + visibility = ["//third_party:__pkg__"], +) diff --git a/tur-on-device/bazel6/dep-patches/cares-config.patch b/tur-on-device/bazel6/dep-patches/cares-config.patch new file mode 100644 index 0000000..5144464 --- /dev/null +++ b/tur-on-device/bazel6/dep-patches/cares-config.patch @@ -0,0 +1,11 @@ +--- a/third_party/cares/cares.BUILD ++++ b/third_party/cares/cares.BUILD +@@ -113,7 +113,7 @@ + ":darwin_arm64e": "@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h", + ":windows": "@com_github_grpc_grpc//third_party/cares:config_windows/ares_config.h", + ":android": "@com_github_grpc_grpc//third_party/cares:config_android/ares_config.h", +- "//conditions:default": "@com_github_grpc_grpc//third_party/cares:config_linux/ares_config.h", ++ "//conditions:default": "@com_github_grpc_grpc//third_party/cares:config_android/ares_config.h", + }), + out = "ares_config.h", + ) diff --git a/tur-on-device/bazel6/dep-patches/cares.patch b/tur-on-device/bazel6/dep-patches/cares.patch new file mode 100644 index 0000000..04296c9 --- /dev/null +++ b/tur-on-device/bazel6/dep-patches/cares.patch @@ -0,0 +1,98 @@ +https://github.com/termux/termux-packages/tree/88d3e0f154a40740a0a09822fac96450a360b01f/packages/c-ares + +diff -u -r ../c-ares-cares-1_15_0/ares_android.c ./ares_android.c +--- ../c-ares-cares-1_15_0/ares_android.c 2018-10-23 13:49:22.000000000 +0000 ++++ ./ares_android.c 2018-11-01 02:26:38.968483738 +0000 +@@ -12,7 +12,7 @@ + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ +-#if defined(ANDROID) || defined(__ANDROID__) ++#if defined(__DISABLED_IN_TERMUX__) + + #include + +diff -u -r ../c-ares-cares-1_15_0/ares_init.c ./ares_init.c +--- ../c-ares-cares-1_15_0/ares_init.c 2018-10-23 13:49:22.000000000 +0000 ++++ ./ares_init.c 2018-11-01 02:29:03.106824681 +0000 +@@ -44,7 +44,6 @@ + + #if defined(ANDROID) || defined(__ANDROID__) + #include +-#include "ares_android.h" + /* From the Bionic sources */ + #define DNS_PROP_NAME_PREFIX "net.dns" + #define MAX_DNS_PROPERTIES 8 +@@ -1549,35 +1548,6 @@ + char *domains; + size_t num_servers; + +- /* Use the Android connectivity manager to get a list +- * of DNS servers. As of Android 8 (Oreo) net.dns# +- * system properties are no longer available. Google claims this +- * improves privacy. Apps now need the ACCESS_NETWORK_STATE +- * permission and must use the ConnectivityManager which +- * is Java only. */ +- dns_servers = ares_get_android_server_list(MAX_DNS_PROPERTIES, &num_servers); +- if (dns_servers != NULL) +- { +- for (i = 0; i < num_servers; i++) +- { +- status = config_nameserver(&servers, &nservers, dns_servers[i]); +- if (status != ARES_SUCCESS) +- break; +- status = ARES_EOF; +- } +- for (i = 0; i < num_servers; i++) +- { +- ares_free(dns_servers[i]); +- } +- ares_free(dns_servers); +- } +- if (channel->ndomains == -1) +- { +- domains = ares_get_android_search_domains_list(); +- set_search(channel, domains); +- ares_free(domains); +- } +- + # ifdef HAVE___SYSTEM_PROPERTY_GET + /* Old way using the system property still in place as + * a fallback. Older android versions can still use this. +diff -u -r ../c-ares-cares-1_15_0/ares_library_init.c ./ares_library_init.c +--- ../c-ares-cares-1_15_0/ares_library_init.c 2018-10-23 13:49:22.000000000 +0000 ++++ ./ares_library_init.c 2018-11-01 02:26:38.972483691 +0000 +@@ -30,10 +30,6 @@ + fpGetBestRoute2_t ares_fpGetBestRoute2 = ZERO_NULL; + #endif + +-#if defined(ANDROID) || defined(__ANDROID__) +-#include "ares_android.h" +-#endif +- + /* library-private global vars with source visibility restricted to this file */ + + static unsigned int ares_initialized; +@@ -174,10 +170,6 @@ + if (ares_init_flags & ARES_LIB_INIT_WIN32) + ares_win32_cleanup(); + +-#if defined(ANDROID) || defined(__ANDROID__) +- ares_library_cleanup_android(); +-#endif +- + ares_init_flags = ARES_LIB_INIT_NONE; + ares_malloc = malloc; + ares_realloc = realloc; +diff -uNr c-ares-1.13.0/ares_private.h c-ares-1.13.0.mod/ares_private.h +--- c-ares-1.13.0/ares_private.h 2017-06-16 15:53:03.000000000 +0300 ++++ c-ares-1.13.0.mod/ares_private.h 2017-09-12 11:24:17.332992105 +0300 +@@ -84,7 +84,7 @@ + #ifdef ETC_INET + #define PATH_HOSTS "/etc/inet/hosts" + #else +-#define PATH_HOSTS "/etc/hosts" ++#define PATH_HOSTS "@TERMUX_PREFIX@/etc/hosts" + #endif + + #endif diff --git a/tur-on-device/bazel6/dep-patches/grpc.patch b/tur-on-device/bazel6/dep-patches/grpc.patch new file mode 100644 index 0000000..b772ee9 --- /dev/null +++ b/tur-on-device/bazel6/dep-patches/grpc.patch @@ -0,0 +1,77 @@ +diff --git a/src/core/lib/gpr/log_android.cc b/src/core/lib/gpr/log_android.cc +index 11ffd64..a1df434 100644 +--- a/src/core/lib/gpr/log_android.cc ++++ b/src/core/lib/gpr/log_android.cc +@@ -18,7 +18,7 @@ + + #include + +-#ifdef GPR_ANDROID ++#if defined(GPR_ANDROID) && !defined(__TERMUX__) + + #include + #include +diff --git a/src/core/lib/gpr/log_posix.cc b/src/core/lib/gpr/log_posix.cc +index 2c28bdd..c1b5d6e 100644 +--- a/src/core/lib/gpr/log_posix.cc ++++ b/src/core/lib/gpr/log_posix.cc +@@ -18,7 +18,7 @@ + + #include + +-#ifdef GPR_POSIX_LOG ++#if defined(GPR_POSIX_LOG) || defined(__TERMUX__) + + #include + #include +diff --git a/src/core/lib/gpr/tmpfile_posix.cc b/src/core/lib/gpr/tmpfile_posix.cc +index 166cdf6..ed77a76 100644 +--- a/src/core/lib/gpr/tmpfile_posix.cc ++++ b/src/core/lib/gpr/tmpfile_posix.cc +@@ -39,7 +39,7 @@ FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) { + + if (tmp_filename != nullptr) *tmp_filename = nullptr; + +- gpr_asprintf(&filename_template, "/tmp/%s_XXXXXX", prefix); ++ gpr_asprintf(&filename_template, "/data/data/com.termux/files/usr/tmp/%s_XXXXXX", prefix); + GPR_ASSERT(filename_template != nullptr); + + fd = mkstemp(filename_template); +diff --git a/src/core/lib/security/security_connector/load_system_roots_linux.cc b/src/core/lib/security/security_connector/load_system_roots_linux.cc +index 6b9c50b..52213b8 100644 +--- a/src/core/lib/security/security_connector/load_system_roots_linux.cc ++++ b/src/core/lib/security/security_connector/load_system_roots_linux.cc +@@ -52,12 +52,12 @@ namespace grpc_core { + namespace { + + const char* kLinuxCertFiles[] = { +- "/etc/ssl/certs/ca-certificates.crt", "/etc/pki/tls/certs/ca-bundle.crt", +- "/etc/ssl/ca-bundle.pem", "/etc/pki/tls/cacert.pem", +- "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"}; ++ "/data/data/com.termux/files/usr/etc/ssl/certs/ca-certificates.crt", "/data/data/com.termux/files/usr/etc/pki/tls/certs/ca-bundle.crt", ++ "/data/data/com.termux/files/usr/etc/ssl/ca-bundle.pem", "/data/data/com.termux/files/usr/etc/pki/tls/cacert.pem", ++ "/data/data/com.termux/files/usr/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"}; + const char* kLinuxCertDirectories[] = { +- "/etc/ssl/certs", "/system/etc/security/cacerts", "/usr/local/share/certs", +- "/etc/pki/tls/certs", "/etc/openssl/certs"}; ++ "/data/data/com.termux/files/usr/etc/ssl/certs", "/system/etc/security/cacerts", "/data/data/com.termux/files/usr/local/share/certs", ++ "/data/data/com.termux/files/usr/etc/pki/tls/certs", "/data/data/com.termux/files/usr/etc/openssl/certs"}; + + grpc_slice GetSystemRootCerts() { + grpc_slice valid_bundle_slice = grpc_empty_slice(); +diff --git a/src/core/lib/security/security_connector/ssl_utils.cc b/src/core/lib/security/security_connector/ssl_utils.cc +index 07983c3..706a5bd 100644 +--- a/src/core/lib/security/security_connector/ssl_utils.cc ++++ b/src/core/lib/security/security_connector/ssl_utils.cc +@@ -45,9 +45,9 @@ + static const char* installed_roots_path = GRPC_ROOT_PEM_PATH; + #elif defined(INSTALL_PREFIX) + static const char* installed_roots_path = +- INSTALL_PREFIX "/usr/share/grpc/roots.pem"; ++ "/data/data/com.termux/files/usr/share/grpc/roots.pem"; + #else +-static const char* installed_roots_path = "/usr/share/grpc/roots.pem"; ++static const char* installed_roots_path = "/data/data/com.termux/files/usr/share/grpc/roots.pem"; + #endif + + #ifndef TSI_OPENSSL_ALPN_SUPPORT diff --git a/tur-on-device/bazel6/dep-patches/protobuf.patch b/tur-on-device/bazel6/dep-patches/protobuf.patch new file mode 100644 index 0000000..1ecc0c9 --- /dev/null +++ b/tur-on-device/bazel6/dep-patches/protobuf.patch @@ -0,0 +1,20 @@ +--- a/src/google/protobuf/stubs/common.cc ++++ b/src/google/protobuf/stubs/common.cc +@@ -45,7 +45,7 @@ + #include + #define snprintf _snprintf // see comment in strutil.cc + #endif +-#if defined(__ANDROID__) ++#if defined(__ANDROID__) && !defined(__TERMUX__) + #include + #endif + +@@ -121,7 +121,7 @@ + + namespace internal { + +-#if defined(__ANDROID__) ++#if defined(__ANDROID__) && !defined(__TERMUX__) + inline void DefaultLogHandler(LogLevel level, const char* filename, int line, + const std::string& message) { + if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { diff --git a/tur-on-device/bazel6/dep-patches/upb-config.patch b/tur-on-device/bazel6/dep-patches/upb-config.patch new file mode 100644 index 0000000..3acc1f6 --- /dev/null +++ b/tur-on-device/bazel6/dep-patches/upb-config.patch @@ -0,0 +1,18 @@ +--- a/bazel/build_defs.bzl ++++ b/bazel/build_defs.bzl +@@ -36,6 +36,7 @@ + # "-Wshorten-64-to-32", # not in GCC (and my Kokoro images doesn't have Clang) + "-Werror", + "-Wno-long-long", ++ "-Wno-gnu-offsetof-extensions", + ]) + _DEFAULT_COPTS.extend([ + "-std=c99", +@@ -43,6 +44,7 @@ + "-Werror=pedantic", + "-Wall", + "-Wstrict-prototypes", ++ "-Wno-gnu-offsetof-extensions", + # GCC (at least) emits spurious warnings for this that cannot be fixed + # without introducing redundant initialization (with runtime cost): + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635