Skip to content

Commit

Permalink
new package: bazel6
Browse files Browse the repository at this point in the history
  • Loading branch information
termux-pacman-bot committed May 26, 2024
1 parent 08b3ede commit 7e6cbe4
Show file tree
Hide file tree
Showing 18 changed files with 752 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tur-on-device/bazel6/0001-strerror_r.patch
Original file line number Diff line number Diff line change
@@ -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 {
14 changes: 14 additions & 0 deletions tur-on-device/bazel6/0002-impl-wait3.patch
Original file line number Diff line number Diff line change
@@ -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 {
12 changes: 12 additions & 0 deletions tur-on-device/bazel6/0003-disable-sandbox.patch
Original file line number Diff line number Diff line change
@@ -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",
10 changes: 10 additions & 0 deletions tur-on-device/bazel6/0004-spawn.patch
Original file line number Diff line number Diff line change
@@ -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 = [
55 changes: 55 additions & 0 deletions tur-on-device/bazel6/0005-import-termux-patches.patch
Original file line number Diff line number Diff line change
@@ -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",
14 changes: 14 additions & 0 deletions tur-on-device/bazel6/0006-force-use-external-patch_tools.patch
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions tur-on-device/bazel6/0007-disable-module_maps.patch
Original file line number Diff line number Diff line change
@@ -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(
236 changes: 236 additions & 0 deletions tur-on-device/bazel6/0008-run-elf-cleaner-for-bazel-tools.patch
Original file line number Diff line number Diff line change
@@ -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",
])
11 changes: 11 additions & 0 deletions tur-on-device/bazel6/0009-bazelrc-path.patch
Original file line number Diff line number Diff line change
@@ -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 = [
12 changes: 12 additions & 0 deletions tur-on-device/bazel6/0010-jdk-17.patch
Original file line number Diff line number Diff line change
@@ -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 \
Loading

0 comments on commit 7e6cbe4

Please sign in to comment.