mjbots / rpi_bazel

Rasbperry pi bazel cross compile rules
Other
48 stars 16 forks source link

Build Boost shared libraries and source for Raspberry Pi on Ubuntu #3

Open terrisgit opened 5 years ago

terrisgit commented 5 years ago

I am trying to build boost using this project and rules_foreign_cc. See https://github.com/bazelbuild/rules_foreign_cc/issues/297 .

I am using --config=pi.

On OSX I get the following error:

ERROR: /private/var/tmp/_bazel_terris/edf155d50c43cc61a3e8b69da84398f0/external/rpi_bazel/tools/cc_toolchain/BUILD:20:1: in cc_toolchain_suite rule @rpi_bazel//tools/cc_toolchain:toolchain: cc_toolchain_suite '@rpi_bazel//tools/cc_toolchain:toolchain' does not contain a toolchain for cpu 'armeabihf'
jpieper commented 5 years ago

Yeah, unfortunately I wouldn't expect this to work on OS X at all. It is limited to Linux at this point.

terrisgit commented 5 years ago

I saw this in #2 - maybe add it to the README? So yep.. this works with the master branch:

bazel build --compiler=clang test bazel build --config=pi --compiler=clang test

terrisgit commented 5 years ago
ERROR: /media/sf_smart/pe-compute/test/BUILD:1:1: Linking of rule '//test:test' failed (Exit 1) clang-clang failed: error executing command external/rpi_bazel/tools/cc_toolchain/wrapper/clang-clang -o bazel-out/armeabihf-fastbuild/bin/test/test '-Wl,-rpath,$ORIGIN/../_solib_armeabihf/' ... (remaining 19 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
ld.lld: error: bazel-out/armeabihf-fastbuild/bin/_solib_armeabihf/_U_S_Sboost_Clog___Uboost_Slog_Slib/libboost_atomic.so.1.65.0 is incompatible with armelf_linux_eabi
terrisgit commented 5 years ago

Using the "file" command, I determined the .so files are not built for ARM. So sadly the toolchain is not getting passed to Boost's b2 builder.

ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=0555073ad8791b8aeab0e746c6aa67d920194e3e, with debug_info, not stripped

jpieper commented 5 years ago

Are you using a system version of bazel or the 0.26.1 that is downloaded?

terrisgit commented 5 years ago

0.26.1 downloaded

terrisgit commented 5 years ago

The toolchain doesn't appear to work with CMake either.

The BUILD file is here: https://github.com/dev-guy/vsomeip-bazel/blob/master/vsomeip/BUILD

The key issue seems to be:

/tmp/tmp.X5xqrpaTj2/CMakeFiles/CMakeTmp/external/org_llvm_clang/bin/clang: No such file or directory

How to stop Bazel from deleting files in /tmp too early?

_____ BEGIN BUILD LOGS _____
Bazel external C/C++ Rules #0.0.8. Building library 'vsomeip'
Environment:______________EXT_BUILD_ROOT=/home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp
INSTALLDIR=/home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/bazel-out/k8-fastbuild/bin/vsomeip/vsomeip
PWD=/home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp
BUILD_TMPDIR=/tmp/tmp.X5xqrpaTj2
TMPDIR=/tmp
EXT_BUILD_DEPS=/home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/bazel_foreign_cc_deps_vsomeip
SHLVL=2
BUILD_LOG=bazel-out/k8-fastbuild/bin/vsomeip/vsomeip/logs/CMake.log
BUILD_SCRIPT=bazel-out/k8-fastbuild/bin/vsomeip/vsomeip/logs/CMake_script.sh
PATH=/home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp:/home/terris/.pyenv/plugins/pyenv-virtualenv/shims:/home/terris/.pyenv/shims:/home/terris/.pyenv/bin:/home/terris/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/terris/.bazel/bin:/home/terris/bin
_=/usr/bin/env
__________________________-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/external/rpi_bazel/tools/cc_toolchain/wrapper/clang-clang
-- Check for working C compiler: /home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/external/rpi_bazel/tools/cc_toolchain/wrapper/clang-clang -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/external/rpi_bazel/tools/cc_toolchain/wrapper/clang-clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /tmp/tmp.X5xqrpaTj2/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_eb9d2/fast"
    /usr/bin/make -f CMakeFiles/cmTC_eb9d2.dir/build.make CMakeFiles/cmTC_eb9d2.dir/build
    make[1]: Entering directory '/tmp/tmp.X5xqrpaTj2/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_eb9d2.dir/testCCompiler.c.o
    /home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/external/rpi_bazel/tools/cc_toolchain/wrapper/clang-clang   -nostdinc++ -isystem /home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/external/org_llvm_libcxx/include -isystem /home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/external/org_llvm_libcxxabi/include -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -fPIE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -fstack-protector -Wall -fno-omit-frame-pointer -no-canonical-prefixes    -o CMakeFiles/cmTC_eb9d2.dir/testCCompiler.c.o   -c /tmp/tmp.X5xqrpaTj2/CMakeFiles/CMakeTmp/testCCompiler.c
    /home/terris/.cache/bazel/_bazel_terris/0679beeba7657bf10887278727d0e849/sandbox/linux-sandbox/207/execroot/pecomp/external/rpi_bazel/tools/cc_toolchain/wrapper/clang-clang: line 17: /tmp/tmp.X5xqrpaTj2/CMakeFiles/CMakeTmp/external/org_llvm_clang/bin/clang: No such file or directory
    CMakeFiles/cmTC_eb9d2.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_eb9d2.dir/testCCompiler.c.o' failed
    make[1]: *** [CMakeFiles/cmTC_eb9d2.dir/testCCompiler.c.o] Error 127
    make[1]: Leaving directory '/tmp/tmp.X5xqrpaTj2/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_eb9d2/fast' failed
    make: *** [cmTC_eb9d2/fast] Error 2
terrisgit commented 5 years ago

In case you want to help https://github.com/dev-guy/pi-bazel-boost-vsomeip

terrisgit commented 5 years ago

If you have a moment, could you please verify .bazelrc and WORKSPACE are OK? They are brief. I'm not sure I have things in the correct order.

jpieper commented 5 years ago

I didn't see anything obviously wrong with your WORKSPACE, but I admit to not really having any experience with merging the more hermetic approach that mjbots/rpi_bazel and mjbots/bazel_deps takes with rules_foreign_cc. I'd recommend just making a simple BUILD.bazel file for your library and not messing with cmake at all. There are plenty of examples in https://github.com/mjbots/bazel_deps to choose from.

terrisgit commented 5 years ago

My goal, which will probably fail, is for Bazel to integrate with cmake and b2 projects until they see the light and convert to Bazel, which is unlikely until Bazel embraces my goal (yes it’s a little recursive). I do not seek a work around. As far as practicality goes, we abandoned Bazel just for raspberry pi builds. It was inevitable. IMX is much worse.

terrisgit commented 5 years ago

Also, if you want to convert GENIVI/vsomeip , I would have one less reason to use cmake. I'm skeptical that you can use boost and avoid b2, but I'm willing to go along. I have managed to use a lot of open source projects like spdlog in Bazel without resorting to calling out to cmake but vsomeip has been particularly troublesome because it depends on boost and I just don't know enough about Bazel yet.

jpieper commented 5 years ago

For all the complexity in GENIVI/vsomeip's CMakelist.txt, it looks like the bazel-ification could boil down to just listing the right glob for .cpp and .h, and possibly a bit of include path munging. My brief skim didn't show any more complex build steps like pre-processing. For these purposes, you don't care about documentation or tests.

terrisgit commented 5 years ago

Thanks! I am working on converting my project and will then try to get vsomeip working. Thanks for the other projects that are dependencies of my app and in some cases vsomeip. I’m not sure how vsomeip will find the boost include files but that’s my general ignorance of Bazel...