From 4609578f966a787b1f4f5dc1fa639c19b5a4d39d Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Sat, 25 May 2024 20:39:15 +0800 Subject: [PATCH] new package: bazel (#1039) --- tur-on-device/bazel/0001-strerror_r.patch | 13 + tur-on-device/bazel/0002-impl-wait3.patch | 14 ++ .../bazel/0003-disable-sandbox.patch | 12 + tur-on-device/bazel/0004-spawn.patch | 10 + .../bazel/0005-import-termux-patches.patch | 52 ++++ .../0006-force-use-external-patch_tools.patch | 14 ++ .../bazel/0007-disable-module_maps.patch | 11 + ...0008-run-elf-cleaner-for-bazel-tools.patch | 236 ++++++++++++++++++ tur-on-device/bazel/0009-bazelrc-path.patch | 11 + tur-on-device/bazel/bazel7.subpackage.sh | 5 + tur-on-device/bazel/build.sh | 127 ++++++++++ tur-on-device/bazel/dep-patches/BUILD | 7 + .../bazel/dep-patches/cares-config.patch | 11 + tur-on-device/bazel/dep-patches/cares.patch | 98 ++++++++ tur-on-device/bazel/dep-patches/grpc.patch | 69 +++++ .../bazel/dep-patches/protobuf.patch | 20 ++ .../bazel/dep-patches/upb-config.patch | 18 ++ 17 files changed, 728 insertions(+) create mode 100644 tur-on-device/bazel/0001-strerror_r.patch create mode 100644 tur-on-device/bazel/0002-impl-wait3.patch create mode 100644 tur-on-device/bazel/0003-disable-sandbox.patch create mode 100644 tur-on-device/bazel/0004-spawn.patch create mode 100644 tur-on-device/bazel/0005-import-termux-patches.patch create mode 100644 tur-on-device/bazel/0006-force-use-external-patch_tools.patch create mode 100644 tur-on-device/bazel/0007-disable-module_maps.patch create mode 100644 tur-on-device/bazel/0008-run-elf-cleaner-for-bazel-tools.patch create mode 100644 tur-on-device/bazel/0009-bazelrc-path.patch create mode 100644 tur-on-device/bazel/bazel7.subpackage.sh create mode 100644 tur-on-device/bazel/build.sh create mode 100644 tur-on-device/bazel/dep-patches/BUILD create mode 100644 tur-on-device/bazel/dep-patches/cares-config.patch create mode 100644 tur-on-device/bazel/dep-patches/cares.patch create mode 100644 tur-on-device/bazel/dep-patches/grpc.patch create mode 100644 tur-on-device/bazel/dep-patches/protobuf.patch create mode 100644 tur-on-device/bazel/dep-patches/upb-config.patch diff --git a/tur-on-device/bazel/0001-strerror_r.patch b/tur-on-device/bazel/0001-strerror_r.patch new file mode 100644 index 000000000..023d4ee6b --- /dev/null +++ b/tur-on-device/bazel/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/bazel/0002-impl-wait3.patch b/tur-on-device/bazel/0002-impl-wait3.patch new file mode 100644 index 000000000..3b16779ac --- /dev/null +++ b/tur-on-device/bazel/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/bazel/0003-disable-sandbox.patch b/tur-on-device/bazel/0003-disable-sandbox.patch new file mode 100644 index 000000000..b91bc0552 --- /dev/null +++ b/tur-on-device/bazel/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/bazel/0004-spawn.patch b/tur-on-device/bazel/0004-spawn.patch new file mode 100644 index 000000000..65647322f --- /dev/null +++ b/tur-on-device/bazel/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/bazel/0005-import-termux-patches.patch b/tur-on-device/bazel/0005-import-termux-patches.patch new file mode 100644 index 000000000..d4cb079a1 --- /dev/null +++ b/tur-on-device/bazel/0005-import-termux-patches.patch @@ -0,0 +1,52 @@ +--- a/third_party/BUILD ++++ b/third_party/BUILD +@@ -35,6 +35,7 @@ + "//third_party/py/mock:srcs", + "//third_party/py/six:srcs", + "//third_party/remoteapis:srcs", ++ "//third_party/termux-patches:srcs", + "//third_party/zlib:srcs", + ], + ) +--- a/MODULE.bazel ++++ b/MODULE.bazel +@@ -59,6 +59,39 @@ + bazel_dep(name = "rules_go", version = "0.39.1") + bazel_dep(name = "upb", version = "0.0.0-20220923-a547704") + ++single_version_override( ++ module_name = "c-ares", ++ patch_strip = 1, ++ patches = [ ++ "//third_party/termux-patches:cares.patch", ++ "//third_party/termux-patches:cares-config.patch", ++ ], ++) ++ ++single_version_override( ++ module_name = "upb", ++ patch_strip = 1, ++ patches = [ ++ "//third_party/termux-patches:upb-config.patch", ++ ], ++) ++ ++single_version_override( ++ module_name = "protobuf", ++ patch_strip = 1, ++ patches = [ ++ "//third_party/termux-patches:protobuf.patch", ++ ], ++) ++ ++single_version_override( ++ module_name = "grpc", ++ patch_strip = 1, ++ patches = [ ++ "//third_party/termux-patches:grpc.patch", ++ ], ++) ++ + # ========================================= + # Java dependencies + # ========================================= diff --git a/tur-on-device/bazel/0006-force-use-external-patch_tools.patch b/tur-on-device/bazel/0006-force-use-external-patch_tools.patch new file mode 100644 index 000000000..2bd23ef53 --- /dev/null +++ b/tur-on-device/bazel/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/bazel/0007-disable-module_maps.patch b/tur-on-device/bazel/0007-disable-module_maps.patch new file mode 100644 index 000000000..ba9014bb8 --- /dev/null +++ b/tur-on-device/bazel/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/bazel/0008-run-elf-cleaner-for-bazel-tools.patch b/tur-on-device/bazel/0008-run-elf-cleaner-for-bazel-tools.patch new file mode 100644 index 000000000..a7d8074d8 --- /dev/null +++ b/tur-on-device/bazel/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/bazel/0009-bazelrc-path.patch b/tur-on-device/bazel/0009-bazelrc-path.patch new file mode 100644 index 000000000..3c573ee1b --- /dev/null +++ b/tur-on-device/bazel/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/bazel/bazel7.subpackage.sh b/tur-on-device/bazel/bazel7.subpackage.sh new file mode 100644 index 000000000..7a3b922d9 --- /dev/null +++ b/tur-on-device/bazel/bazel7.subpackage.sh @@ -0,0 +1,5 @@ +TERMUX_SUBPKG_DESCRIPTION="Correct, reproducible, and fast builds for everyone (Version 7)" +TERMUX_SUBPKG_DEPEND_ON_PARENT=deps +TERMUX_SUBPKG_INCLUDE=" +bin/bazel-$TERMUX_PKG_VERSION +" diff --git a/tur-on-device/bazel/build.sh b/tur-on-device/bazel/build.sh new file mode 100644 index 000000000..4e224509e --- /dev/null +++ b/tur-on-device/bazel/build.sh @@ -0,0 +1,127 @@ +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="7.1.2" +TERMUX_PKG_SRCURL=https://github.com/bazelbuild/bazel/releases/download/$TERMUX_PKG_VERSION/bazel-$TERMUX_PKG_VERSION-dist.zip +TERMUX_PKG_SHA256=9cf6ed2319c816919d97015eef6d0c5942cd1aed48e03c73ba0815d953ed61ab +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" +TERMUX_PKG_NO_STRIP=true + +__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 ./scripts/packages/bazel.sh $TERMUX_PREFIX/bin/bazel + install -Dm700 ./output/bazel $TERMUX_PREFIX/bin/bazel-real + 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/bazel/dep-patches/BUILD b/tur-on-device/bazel/dep-patches/BUILD new file mode 100644 index 000000000..20577ae77 --- /dev/null +++ b/tur-on-device/bazel/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/bazel/dep-patches/cares-config.patch b/tur-on-device/bazel/dep-patches/cares-config.patch new file mode 100644 index 000000000..05c64090a --- /dev/null +++ b/tur-on-device/bazel/dep-patches/cares-config.patch @@ -0,0 +1,11 @@ +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -54,7 +54,7 @@ + ":darwin": "@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/bazel/dep-patches/cares.patch b/tur-on-device/bazel/dep-patches/cares.patch new file mode 100644 index 000000000..04296c9a8 --- /dev/null +++ b/tur-on-device/bazel/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/bazel/dep-patches/grpc.patch b/tur-on-device/bazel/dep-patches/grpc.patch new file mode 100644 index 000000000..a464d9c83 --- /dev/null +++ b/tur-on-device/bazel/dep-patches/grpc.patch @@ -0,0 +1,69 @@ +https://github.com/termux/termux-packages/tree/0a64a3ce5a61ac7b25ca937db82ec02f4e302689/packages/libgrpc + +--- a/src/core/lib/gpr/tmpfile_posix.cc ++++ b/src/core/lib/gpr/tmpfile_posix.cc +@@ -39,7 +39,7 @@ + + 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); +--- a/src/core/lib/security/security_connector/load_system_roots_supported.cc ++++ b/src/core/lib/security/security_connector/load_system_roots_supported.cc +@@ -52,12 +52,12 @@ + + #if defined(GPR_LINUX) || defined(GPR_ANDROID) + const char* kCertFiles[] = { +- "/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* kCertDirectories[] = { +- "/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", "/data/data/com.termux/files/usr/share/certs", ++ "/data/data/com.termux/files/usr/etc/pki/tls/certs", "/data/data/com.termux/files/usr/etc/openssl/certs"}; + #elif defined(GPR_FREEBSD) // endif GPR_LINUX || GPR_ANDROID + const char* kCertFiles[] = {"/etc/ssl/cert.pem", + "/usr/local/share/certs/ca-root-nss.crt"}; +--- a/src/core/lib/security/security_connector/ssl_utils.cc ++++ b/src/core/lib/security/security_connector/ssl_utils.cc +@@ -55,9 +55,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"; ++ INSTALL_PREFIX "/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 +--- 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 +--- 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/tur-on-device/bazel/dep-patches/protobuf.patch b/tur-on-device/bazel/dep-patches/protobuf.patch new file mode 100644 index 000000000..1ecc0c9af --- /dev/null +++ b/tur-on-device/bazel/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/bazel/dep-patches/upb-config.patch b/tur-on-device/bazel/dep-patches/upb-config.patch new file mode 100644 index 000000000..3acc1f618 --- /dev/null +++ b/tur-on-device/bazel/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