AI-OP / edge-brain

Simple examples of using bazel to cross compile AI applicaions for armv7hf devices.
Apache License 2.0
25 stars 8 forks source link

`bazel build //examples/hello_opencv:hello-opencv` fail #9

Open lordheartnk opened 3 years ago

lordheartnk commented 3 years ago
root@docker-desktop:/home/github/edge-brain# bazel build //examples/hello_opencv:hello-open
cv --experimental_repo_remote_exec
DEBUG: Rule 'rules_foreign_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "21c2640365de0f2cfba1a179ae772d7a150e50541ba7d0d75139fa3c895e87eb"
DEBUG: Repository rules_foreign_cc instantiated at:
  /home/github/edge-brain/WORKSPACE:27:13: in <toplevel>
Repository rule http_archive defined at:
  /root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
DEBUG: /root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/external/rules_foreign_cc/workspace_definitions.bzl:15:10: WARNING: This branch is deprecated and no longer recieving updates. Please update to `main` or choose a specific commit to pin in your workspace.
DEBUG: Rule 'org_tensorflow' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "582c8d236cb079023657287c318ff26adb239002", shallow_since = "1607737042 -0800" and dropping ["tag"]
DEBUG: Repository org_tensorflow instantiated at:
  /home/github/edge-brain/WORKSPACE:56:15: in <toplevel>
Repository rule git_repository defined at:
  /root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/external/bazel_tools/tools/build_defs/repo/git.bzl:199:33: in <toplevel>
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
INFO: Build options --cpu and --crosstool_top have changed, discarding analysis cache.
DEBUG: Rule 'rules_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "66af5b045d30b49a61faaf063ba5da7e47b9b393e3d64b40035f66ec1ade8f34"
DEBUG: Repository rules_cc instantiated at:
  /home/github/edge-brain/WORKSPACE:21:13: in <toplevel>
Repository rule http_archive defined at:
  /root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
DEBUG: Rule 'opencv' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "d5fd2f0155ffad366f9ac912dfd6d189a7a6a98e", shallow_since = "1602451567 +0000" and dropping ["tag"]
DEBUG: Repository opencv instantiated at:
  /home/github/edge-brain/WORKSPACE:38:19: in <toplevel>
Repository rule new_git_repository defined at:
  /root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/external/bazel_tools/tools/build_defs/repo/git.bzl:186:37: in <toplevel>
INFO: Analyzed target //examples/hello_opencv:hello-opencv (0 packages loaded, 6696 targets configured).
INFO: Found 1 target...
ERROR: /home/github/edge-brain/third_party/BUILD:39:15: CcCmakeMakeRule third_party/opencv_cmake/include failed: (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
nrules_foreign_cc:BazelEnvironment:______________nBUILD_SCRIPT=bazel-out/k8-fastbuild/bin/third_party/opencv_cmake/logs/CMake_script.sh
EXT_BUILD_ROOT=/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__
BUILD_LOG=bazel-out/k8-fastbuild/bin/third_party/opencv_cmake/logs/CMake.log
PWD=/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__
TMPDIR=/tmp
EXT_BUILD_DEPS=/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.ext_build_deps
BUILD_TMPDIR=/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.build_tmpdir
SHLVL=2
INSTALLDIR=/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake
PATH=/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__:/root/.cache/bazelisk/downloads/bazelbuild/bazel-4.0.0-linux-x86_64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
__________________________n-- The CXX compiler identification is GNU 9.3.0
-- The C compiler identification is GNU 9.3.0
-- Check for working CXX compiler: /usr/bin/gcc
-- Check for working CXX compiler: /usr/bin/gcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

    "/usr/bin/gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.build_tmpdir/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make cmTC_602d6/fast && /usr/bin/make -f CMakeFiles/cmTC_602d6.dir/build.make CMakeFiles/cmTC_602d6.dir/build
    make[1]: Entering directory '/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.build_tmpdir/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_602d6.dir/testCXXCompiler.cxx.o
    /usr/bin/gcc    -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi  -fPIE   -o CMakeFiles/cmTC_602d6.dir/testCXXCompiler.cxx.o -c /root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.build_tmpdir/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    gcc: error: unrecognized command line option '-mthumb'
    make[1]: *** [CMakeFiles/cmTC_602d6.dir/build.make:66: CMakeFiles/cmTC_602d6.dir/testCXXCompiler.cxx.o] Error 1
    make[1]: Leaving directory '/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.build_tmpdir/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_602d6/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:109 (enable_language)

-- Configuring incomplete, errors occurred!
See also "/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.build_tmpdir/CMakeFiles/CMakeOutput.log".
See also "/root/.cache/bazel/_bazel_root/0dc1deb1e924a05e40a70b012b8bbd7d/sandbox/processwrapper-sandbox/243/execroot/__main__/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake.build_tmpdir/CMakeFiles/CMakeError.log".
n_____Printing#!/usr/bin/env bash
function children_to_path() {
if [ -d $EXT_BUILD_DEPS/bin ]; then
local tools=$(find $EXT_BUILD_DEPS/bin -maxdepth 1 -mindepth 1)
for tool in $tools;
do
if  [[ -d "$tool" ]] || [[ -L "$tool" ]]; then
export PATH=$PATH:$tool
fi
done
fi
}
function replace_in_files() {
if [ -d "$1" ]; then
find -L $1 -type f   \( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \)   -exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
fi
}
printf """"
printf ""Bazel external C/C++ Rules. Building library 'opencv_cmake'\n""
printf """"
set -e

export EXT_BUILD_ROOT=$(pwd)
export INSTALLDIR=$EXT_BUILD_ROOT/bazel-out/k8-fastbuild/bin/third_party/opencv_cmake
export BUILD_TMPDIR=${INSTALLDIR}.build_tmpdir
export EXT_BUILD_DEPS=${INSTALLDIR}.ext_build_deps
export PATH="$EXT_BUILD_ROOT:$PATH"
mkdir -p $INSTALLDIR
mkdir -p $BUILD_TMPDIR
mkdir -p $EXT_BUILD_DEPS
printf ""Environment:______________\n""
env
printf ""__________________________\n""
children_to_path $EXT_BUILD_DEPS/bin
export PATH="$EXT_BUILD_DEPS/bin:$PATH"
cd $BUILD_TMPDIR
export INSTALL_PREFIX="opencv_cmake"
CC="/usr/bin/gcc" CXX="/usr/bin/gcc" CFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -fno-canonical-system-headers -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\"" CXXFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\"" ASMFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -fno-canonical-system-headers -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\"" cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_SHARED_LINKER_FLAGS="-shared -fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -pass-exit-codes -lstdc++ -lm" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -pass-exit-codes -lstdc++ -lm" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_TOOLCHAIN_FILE="$EXT_BUILD_ROOT/external/opencv/platforms/linux/arm-gnueabi.toolchain.cmake" -DBUILD_LIST="calib3d,core,features2d,flann,highgui,imgcodecs,imgproc,video,videoio" -DBUILD_TESTS="OFF" -DBUILD_PERF_TESTS="OFF" -DBUILD_EXAMPLES="OFF" -DBUILD_SHARED_LIBS="OFF" -DWITH_ITT="OFF" -DWITH_TIFF="OFF" -DWITH_JASPER="OFF" -DWITH_WEBP="OFF" -DBUILD_PNG="ON" -DBUILD_JPEG="ON" -DBUILD_ZLIB="ON" -DOPENCV_SKIP_VISIBILITY_HIDDEN="ON" -DOPENCV_SKIP_PYTHON_LOADER="ON" -DBUILD_opencv_python="OFF" -DENABLE_CCACHE="OFF" -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB=""  $EXT_BUILD_ROOT/external/opencv
make -j4
make install
cp $BUILD_TMPDIR/$INSTALL_PREFIX/lib/opencv4/3rdparty/*.a  $BUILD_TMPDIR/$INSTALL_PREFIX/lib/
cp -rf $BUILD_TMPDIR/$INSTALL_PREFIX/include/opencv4/opencv2 $BUILD_TMPDIR/$INSTALL_PREFIX/include/
cp -L -r --no-target-directory "$BUILD_TMPDIR/$INSTALL_PREFIX" "$INSTALLDIR"
replace_in_files $INSTALLDIR $BUILD_TMPDIR \${EXT_BUILD_DEPS}
replace_in_files $INSTALLDIR $EXT_BUILD_DEPS \${EXT_BUILD_DEPS}
mkdir -p $EXT_BUILD_ROOT/bazel-out/k8-fastbuild/bin/third_party/copy_opencv_cmake/opencv_cmake
cp -L -r --no-target-directory "$INSTALLDIR" "$EXT_BUILD_ROOT/bazel-out/k8-fastbuild/bin/third_party/copy_opencv_cmake/opencv_cmake"
touch $EXT_BUILD_ROOT/bazel-out/k8-fastbuild/bin/third_party/empty_opencv_cmake.txt
Target //examples/hello_opencv:hello-opencv failed to build
Use --verbose_failures to see the command lines of failed build steps.

INFO: Elapsed time: 0.854s, Critical Path: 0.48soreign_cc:
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
SunAriesCN commented 3 years ago

Thank to @Duan-JM, we found that the third_party/BUILD is only considered about the arm-gnueabi for OpenCV compilation. It seems I can fix it by introducing a config option about platform.