bazel-contrib / rules_foreign_cc

Build rules for interfacing with "foreign" (non-Bazel) build systems (CMake, configure-make, GNU Make, boost, ninja, Meson)
https://bazel-contrib.github.io/rules_foreign_cc
Apache License 2.0
680 stars 249 forks source link

cmake debug build failed #1041

Open liuluheng opened 1 year ago

liuluheng commented 1 year ago

cmake debug build will add d suffix by default, which is not consistent with the library name. for example

with thrift cmake rule as follows https://github.com/apache/brpc/blob/master/bazel/third_party/thrift/thrift.BUILD#L23

run

bazel build -c dbg //some/target/depend/on/thrift

will get

INFO: Found 1 target...
WARNING: Remote Cache: Expected output external/org_apache_thrift/thrift/lib/libthrift.a was not created locally.
ERROR: .cache/bazel/5f6cfd791ed6436cd7d0a9ad06515f99/external/org_apache_thrift/BUILD.bazel:23:6: output 'external/org_apache_thrift/thrift/lib/libthrift.a' was not created
ERROR: .cache/bazel/5f6cfd791ed6436cd7d0a9ad06515f99/external/org_apache_thrift/BUILD.bazel:23:6: output 'external/org_apache_thrift/thrift/lib/libthriftnb.a' was not created
ERROR: .cache/bazel/5f6cfd791ed6436cd7d0a9ad06515f99/external/org_apache_thrift/BUILD.bazel:23:6: output 'external/org_apache_thrift/thrift/lib/libthriftz.a' was not created
ERROR: .cache/bazel/5f6cfd791ed6436cd7d0a9ad06515f99/external/org_apache_thrift/BUILD.bazel:23:6: Foreign Cc - CMake: Building thrift failed: not all outputs were created or valid
Target //some/target/depend/on/thrift failed to build
Use --verbose_failures to see the command lines of failed build steps.

to solve this i passed -DCMAKE_DEBUG_POSTFIX=\"\" to the cmake attr generate_args

but i think cmake rule should handle this by default

XiaochenCui commented 6 days ago

Hi, @liuluheng,

I'm facing the same issue:
bazel build //src/server:main succeeds, but bazel build //src/server:main -c dbg fails.

Even using -DCMAKE_DEBUG_POSTFIX="" doesn’t solve the problem.

Here’s the error I encountered:

ERROR: /home/xiaochen/code/small-db-v2/BUILD:55:6: output 'spdlog/lib/libspdlog.a' was not created  
ERROR: /home/xiaochen/code/small-db-v2/BUILD:55:6: Foreign Cc - CMake: Building spdlog failed: not all outputs were created or valid  

Do you know how to troubleshoot this? I'd like to understand Bazel's behavior, such as where it searches for the output files.

Here are my Bazel build files:


Update:
I had to explicitly set out_static_libs because spdlog doesn’t care about CMAKE_DEBUG_POSTFIX.

cmake(
    name = "spdlog",
    build_args = ["-j"],
    lib_source = "@spdlog//:all",
    out_static_libs = select({
        "//conditions:default": ["libspdlog.a"],

        # spdlog doesn't care about CMAKE_DEBUG_POSTFIX, so we have to adapt to it.
        ":debug": ["libspdlogd.a"],
    }),
    visibility = ["//visibility:public"],
)

config_setting(
    name = "debug",
    values = {"compilation_mode": "dbg"},
)