这是indexloc提供的服务,不要输入任何密码
Skip to content

addpkg(packages/bear): 3.1.6 #24237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

JesusChapman
Copy link
Contributor

Close #24235

@robertkirkman
Copy link
Contributor

robertkirkman commented Apr 10, 2025

@JesusChapman

/bin/sh: 1: /data/data/com.termux/files/usr/bin/protoc: Exec format error

Basically, unless I am also incorrect this time, unfortunately there is no such thing currently as termux_setup_protoc_cross_pkg_config_wrapper for softwares which are "trying to run" $PREFIX/bin/protoc during cross-compilation.

Therefore, this time it really is necessary to apply a patch and/or other kind of termux_step_pre_configure() build.sh workaround for protoc, to make it use termux_setup_protobuf followed by export PROTOC=$(command -v protoc) OR other kind of directive to the build system of the software (varies between different softwares) instead of there being a single universal uniformly applicable workaround.

SOME currently preexisting examples:

termux_setup_protobuf
export PROTOC=$(command -v protoc)

termux_setup_protobuf
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
# By default cmake will pick $TERMUX_PREFIX/bin/protoc, we should avoid it on CI
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -Dprotobuf_generate_PROTOC_EXE=$(command -v protoc)"
fi

termux_setup_protobuf
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
# By default cmake will pick $TERMUX_PREFIX/bin/protoc, we should avoid it on CI
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -Dprotobuf_generate_PROTOC_EXE=$(command -v protoc)"
fi

termux_setup_protobuf
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+="
-DPython_EXECUTABLE=$(command -v python3)
-DPROTOBUF_PROTOC_EXECUTABLE=$(command -v protoc)
-DCAFFE2_CUSTOM_PROTOC_EXECUTABLE=$(command -v protoc)
"

in this case, it can be observed that the bear software is using find_program() in CMake to try to detect the protoc executable.

This means that its CMake log is going to contain this:

-- Looking for protoc ... /data/data/com.termux/files/usr/bin/protoc

until you get it to successfully change to a different protoc that is executable during cross-compilation.

Additionally, once you resolve that problem, you would next encounter another error, like this:

/data/data/com.termux/files/usr/bin/grpc_cpp_plugin: program not found or is not executable

because, the bear software not only requires protoc at build-time, but also requires another program, grpc_cpp_plugin. Because of that, it's also necessary to set up a host grpc_cpp_plugin executable for cross-compiling and apply a similar CMake workaround patch to bear for it.

I have made an example of doing these steps successfully for you, here it is:

packages/bear/build.sh

TERMUX_PKG_HOMEPAGE=https://github.com/rizsotto/Bear
TERMUX_PKG_DESCRIPTION="Bear is a tool that generates a compilation database for clang tooling."
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_MAINTAINER="@JesusChapman <jesuschapmandev@outlook.com>"
TERMUX_PKG_VERSION=3.1.6
TERMUX_PKG_SRCURL=https://github.com/rizsotto/Bear/archive/refs/tags/${TERMUX_PKG_VERSION}.zip
TERMUX_PKG_SHA256=efadb159f0d8ebab529ced6ba9f78d23754fbc1e484d169e6d92a88f92f44279
TERMUX_PKG_DEPENDS="libgrpc, fmt, libspdlog, jsoncpp, libandroid-spawn"
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DENABLE_UNIT_TESTS=OFF
-DENABLE_FUNC_TESTS=OFF
"

termux_step_host_build() {
	if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
		return
	fi

	# build and install grpc_cpp_plugin binary for using during cross-compilation
	local _GRPC_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/libgrpc/build.sh; echo \${TERMUX_PKG_VERSION#*:}")
	local _GRPC_SRCURL=https://github.com/grpc/grpc.git
	local _GRPC_SRCDIR=${TERMUX_PKG_TMPDIR}/grpc-${_GRPC_VERSION}

	git clone --recursive --branch "v$_GRPC_VERSION" "$_GRPC_SRCURL" "$_GRPC_SRCDIR"

	termux_setup_cmake
	termux_setup_ninja

	cmake -G Ninja "$_GRPC_SRCDIR"

	ninja grpc_cpp_plugin
	# grpc_cpp_plugin host binary is now directly in the root of $TERMUX_PKG_HOSTBUILD_DIR
}

_setup_grpc() {
	if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
		export PATH="$TERMUX_PKG_HOSTBUILD_DIR:$PATH"
	fi
}

termux_step_pre_configure() {
	termux_setup_protobuf
	_setup_grpc
	export PROTOC_PATH="$(dirname $(command -v protoc))"
	export GRPC_CPP_PLUGIN_PATH="$(dirname $(command -v grpc_cpp_plugin))"
	export LDFLAGS+=" -landroid-spawn"
}

packages/bear/cmake-find_program-search-paths.patch

--- a/source/intercept/proto/CMakeLists.txt
+++ b/source/intercept/proto/CMakeLists.txt
@@ -1,6 +1,6 @@
-find_program(_PROTOBUF_PROTOC protoc HINTS ${gRPC_BINDIR})
+find_program(_PROTOBUF_PROTOC protoc PATHS ENV PROTOC_PATH NO_DEFAULT_PATH)
 message(STATUS "Looking for protoc ... ${_PROTOBUF_PROTOC}")
-find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin HINTS ${gRPC_BINDIR})
+find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin PATHS ENV GRPC_CPP_PLUGIN_PATH NO_DEFAULT_PATH)
 message(STATUS "Looking for grpc_cpp_plugin ... ${_GRPC_CPP_PLUGIN_EXECUTABLE}")
 
 get_filename_component(SUPERVISE_PROTO "supervise.proto" ABSOLUTE)
--- a/third_party/grpc/CMakeLists.txt
+++ b/third_party/grpc/CMakeLists.txt
@@ -5,7 +5,7 @@ if (gRPC_FOUND)
     message(STATUS "Looking for gRPC::grpc++ dependency -- found")
 
     message(STATUS "Looking for protoc")
-    find_program(PROTOC protoc)
+    find_program(PROTOC protoc PATHS ENV PROTOC_PATH NO_DEFAULT_PATH)
     if (PROTOC)
         message(STATUS "Looking for protoc -- found")
     else()
@@ -13,7 +13,7 @@ if (gRPC_FOUND)
     endif()
 
     message(STATUS "Looking for grpc_cpp_plugin")
-    find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
+    find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin PATHS ENV GRPC_CPP_PLUGIN_PATH NO_DEFAULT_PATH)
     if (GRPC_CPP_PLUGIN)
         message(STATUS "Looking for grpc_cpp_plugin -- found")
     else()

@robertkirkman
Copy link
Contributor

@JesusChapman and if my message is too long and confusing I am sorry, basically if you see this, the short explanation is I made a cross-compilable version for you and put the files in code blocks at the bottom of the message, but I did not force push them into your branch. If you would like me to, I can do that as well.

@JesusChapman
Copy link
Contributor Author

@JesusChapman and if my message is too long and confusing I am sorry, basically if you see this, the short explanation is I made a cross-compilable version for you and put the files in code blocks at the bottom of the message, but I did not force push them into your branch. If you would like me to, I can do that as well.

Don't worry, I have no problem, I was thinking of doing it later, I'm in the army and I've just walked a long distance 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Package]: Bear
2 participants