Skip to content

Commit

Permalink
new package: bazel (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 authored May 25, 2024
1 parent 110e817 commit 4609578
Show file tree
Hide file tree
Showing 17 changed files with 728 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tur-on-device/bazel/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/bazel/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/bazel/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/bazel/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 = [
52 changes: 52 additions & 0 deletions tur-on-device/bazel/0005-import-termux-patches.patch
Original file line number Diff line number Diff line change
@@ -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
# =========================================
14 changes: 14 additions & 0 deletions tur-on-device/bazel/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/bazel/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/bazel/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/bazel/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 = [
5 changes: 5 additions & 0 deletions tur-on-device/bazel/bazel7.subpackage.sh
Original file line number Diff line number Diff line change
@@ -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
"
Loading

0 comments on commit 4609578

Please sign in to comment.