Reputation: 76
I am currently writing a c++ project. My goal was to use bazel to download and compile all external dependencies required to build the project.
Many c++ libraries use cmake instead of bazel. Luckily I found the rules_foreign_cc
to help me with that.
Alas, I run into an issue I can't seem to solve: I have to compile the soplex library, that in turn depends on gmp and zlib.
I am able to compile zlib using the standard cc_library
, and use a configure_make
rule to compile gmp. But when it comes to soplex, the cmake
rule only considers the zlib dependency and completely ignores gmp.
Some information about my system:
I'm on Ubuntu with ldd 2.35
. I'm also using g++ 11.4.0
with -std=c++17
.
These are the relevant file. Let me know if I missed something.
# soplex.BUILD.bazel
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
make(
name = "soplex",
lib_source = ":all_srcs",
lib_name = "libsoplex",
cache_entries = {
"GMP": "on",
},
deps = ["@zlib", "@gmp//:gmpxx"],
visibility = ["//visibility:public"],
)
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:private"],
)
# zlib.BUILD.bazel
cc_library("zlib",
# ...
)
# gmp.BUILD.bazel
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")
configure_make(
name = "gmp",
configure_options = ["--with-pic"],
lib_name = "libgmp",
lib_source = ":all_srcs",
visibility = ["//visibility:public"],
)
configure_make(
name = "gmpxx",
configure_options = ["--enable-cxx"],
env = {
"CXX": "g++",
"CXXFLAGS": "-lstdc++",
},
lib_name = "libgmpxx",
lib_source = ":all_srcs",
visibility = ["//visibility:public"],
deps = [":gmp"],
)
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:private"],
)
I am able to import and use the gmpxx.h
header in my project.
But when compiling soplex, this is the log it produces:
BUILD_SCRIPT=bazel-out/k8-fastbuild/bin/external/soplex/libsoplex_foreign_cc/build_script.sh
EXT_BUILD_ROOT=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear
BUILD_LOG=bazel-out/k8-fastbuild/bin/external/soplex/libsoplex_foreign_cc/CMake.log
PWD=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear
BUILD_WRAPPER_SCRIPT=bazel-out/k8-fastbuild/bin/external/soplex/libsoplex_foreign_cc/wrapper_build_script.sh
TMPDIR=/tmp
EXT_BUILD_DEPS=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex.ext_build_deps
BUILD_TMPDIR=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex.build_tmpdir
SHLVL=2
INSTALLDIR=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex
PATH=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear:/home/user/.cache/bazelisk/downloads/bazelbuild/bazel-6.3.2-linux-x86_64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
_=/usr/bin/env
__________________________
+ /home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/external/cmake-3.23.2-linux-x86_64/bin/cmake -DGMP=on -DCMAKE_TOOLCHAIN_FILE=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex.build_tmpdir/crosstool_bazel.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex '-DCMAKE_PREFIX_PATH=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex.ext_build_deps;external/zlib/zlib/include;bazel-out/k8-fastbuild/bin/external/zlib/zlib/include;;bazel-out/k8-fastbuild/bin/external/gmp/libgmpx/include;' -DCMAKE_RANLIB= -DCMAKE_MAKE_PROGRAM=/home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make/bin/make -G 'Unix Makefiles' /home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/external/soplex
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/gcc - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex.ext_build_deps/lib/libzlib.a (found version "1.2.13")
-- Could NOT find GMP (missing: GMP_INCLUDE_DIRS GMP_LIBRARIES)
-- SoPlex with Boost CPP multiprecision libraries.
-- Support PAPILO: OFF
-- Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least version "1.65.0")
-- The C compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/bazel-out/k8-fastbuild/bin/external/soplex/libsoplex.build_tmpdir
+ /home/user/.cache/bazel/_bazel_user/25f2f505a2e1449afdd4b81b94594aa0/sandbox/linux-sandbox/125/execroot/dlinear/external/cmake-3.23.2-linux-x86_64/bin/cmake --build . --config Release
[ 0%] Built target soplex_cleanup_config
-- Compiling without git information
-- Git hash: NoGitInfo
[ 0%] Built target soplex_update_githash
I tried different configurations, like manually editing the CMAKE_PREFIX_PATH
in the cache_entries
or adding build_data = ["@gmp:gmpxx"]
but it does not seem to work.
What should I do?
Upvotes: 2
Views: 542