-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
build.sh
137 lines (121 loc) · 3.87 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
TERMUX_PKG_HOMEPAGE=https://github.com/Tencent/ncnn
TERMUX_PKG_DESCRIPTION="A high-performance neural network inference framework optimized for the mobile platform"
TERMUX_PKG_LICENSE="BSD 3-Clause"
TERMUX_PKG_MAINTAINER="@termux"
_COMMIT=4b97730b0d033b4dc2a790e5c35745e0dbf51569
TERMUX_PKG_VERSION="20230627"
TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=git+https://github.com/Tencent/ncnn
TERMUX_PKG_GIT_BRANCH=master
TERMUX_PKG_SHA256=a81ee5b6df97830919f8ed8554c99a4f223976ed82eee0cc9f214de0ce53dd2a
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_DEPENDS="abseil-cpp, glslang, libc++, vulkan-loader"
TERMUX_PKG_BUILD_DEPENDS="protobuf-static, python, vulkan-headers, vulkan-loader-android"
TERMUX_PKG_PYTHON_COMMON_DEPS="wheel, pybind11"
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DNCNN_BUILD_BENCHMARK=OFF
-DNCNN_BUILD_EXAMPLES=OFF
-DNCNN_BUILD_TESTS=OFF
-DNCNN_BUILD_TOOLS=OFF
-DNCNN_DISABLE_EXCEPTION=OFF
-DNCNN_DISABLE_RTTI=OFF
-DNCNN_ENABLE_LTO=ON
-DNCNN_OPENMP=ON
-DNCNN_PYTHON=ON
-DNCNN_SHARED_LIB=OFF
-DNCNN_SIMPLEOCV=ON
-DNCNN_SIMPLEOMP=ON
-DNCNN_SIMPLESTL=OFF
-DNCNN_SYSTEM_GLSLANG=ON
-DNCNN_VULKAN=ON
-DVulkan_LIBRARY=${TERMUX_PREFIX}/lib/libvulkan.so
-DVulkan_INCLUDE_DIRS=${TERMUX_PREFIX}/include
"
termux_step_post_get_source() {
git fetch --unshallow
git checkout "${_COMMIT}"
git submodule update --init --recursive --depth=1
git clean -ffxd
local version=$(git log -1 --format=%cs | sed -e "s|-||g")
if [[ "${version}" != "${TERMUX_PKG_VERSION}" ]]; then
termux_error_exit <<- EOL
Version mismatch detected!
build.sh: ${TERMUX_PKG_VERSION}
git repo: ${version}
EOL
fi
local s=$(find . -type f ! -path '*/.git/*' -print0 | xargs -0 sha256sum | LC_ALL=C sort | sha256sum)
if [[ "${s}" != "${TERMUX_PKG_SHA256} "* ]]; then
termux_error_exit "Checksum mismatch for source files"
fi
}
termux_step_pre_configure() {
termux_setup_cmake
termux_setup_ninja
termux_setup_protobuf
CXXFLAGS+=" -std=c++17"
LDFLAGS+=" $("${TERMUX_SCRIPTDIR}/packages/libprotobuf/interface_link_libraries.sh")"
LDFLAGS+=" -lutf8_range -lutf8_validity"
LDFLAGS+=" -landroid -ljnigraphics -llog"
mv -v "${TERMUX_PREFIX}"/lib/libprotobuf.so{,.tmp}
}
termux_step_post_make_install() {
# the build system can only build static or shared
# at a given time
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+="
-DNCNN_BUILD_TOOLS=ON
-DNCNN_SHARED_LIB=ON
"
termux_step_configure
termux_step_make
termux_step_make_install
pushd python
pip install --no-deps . --prefix "${TERMUX_PREFIX}"
popd
mv -v "${TERMUX_PREFIX}"/lib/libprotobuf.so{.tmp,}
return
# below are testing tools that should not be packaged
# as they can be >100MB
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+="
-DNCNN_BUILD_BENCHMARK=ON
-DNCNN_BUILD_EXAMPLES=ON
-DNCNN_BUILD_TESTS=ON
-DNCNN_SHARED_LIB=OFF
"
termux_step_configure
termux_step_make
local tools_dir="${TERMUX_PREFIX}/lib/ncnn"
local benchmarks=$(find benchmark -mindepth 1 -maxdepth 1 -type f | sort)
for benchmark in ${benchmarks}; do
case "$(basename "${benchmark}")" in
*[Cc][Mm]ake*) continue ;;
*.cpp*) continue ;;
*.md) continue ;;
*.*) install -v -Dm644 "${benchmark}" -t "${tools_dir}/benchmark" ;;
*) install -v -Dm755 "${benchmark}" -t "${tools_dir}/benchmark" ;;
esac
done
local examples=$(find examples -mindepth 1 -maxdepth 1 -type f | sort)
for example in ${examples}; do
case "$(basename "${example}")" in
*[Cc][Mm]ake*) continue ;;
*.cpp*) continue ;;
*.*) install -v -Dm644 "${example}" -t "${tools_dir}/examples" ;;
*) install -v -Dm755 "${example}" -t "${tools_dir}/examples" ;;
esac
done
local tests=$(find tests -mindepth 1 -maxdepth 1 -type f | sort)
for test in ${tests}; do
case "$(basename "${test}")" in
*[Cc][Mm]ake*) continue ;;
*.cpp*) continue ;;
*.h) continue ;;
*.py) continue ;;
*) install -v -Dm755 "${test}" -t "${tools_dir}/tests" ;;
esac
done
}
termux_step_post_massage() {
rm -f lib/libprotobuf.so
}