bazel-contrib / bazel-contrib/rules_foreign_cc

Issues with transitive includes

Open
#959 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
737
Forks
270
PR merge metrics
No merged PRs in 30d

Description

I am trying to build and use https://github.com/microsoft/LightGBM

`WORKSPACE`:
```python3
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_foreign_cc",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

# This sets up some common toolchains for building targets. For more details, please see
# https://bazelbuild.github.io/rules_foreign_cc/0.9.0/flatten.html#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()

all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""

LIGHTGBM_VERSION = "3.2.1"

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository", "git_repository")
new_git_repository(
name = "lightgbm",
build_file_content = all_content,
remote = "https://github.com/microsoft/LightGBM.git",
# branch = "",
# tag = "v{}".format(LIGHTGBM_VERSION),
commit = "b8e38ec1eb8020052d5b39e31e9f2cb6366fb873",
init_submodules = True,
)
```

Then in `BUILD`:
```python3
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

package(default_visibility = ["//visibility:public"])

cmake(
name = "lightgbm",
lib_source = "@lightgbm//:all",
cache_entries = {
"USE_OPENMP": "OFF",
"BUILD_STATIC_LIB": "ON",
},
generate_args = ["-GNinja"],
out_static_libs = ["lib_lightgbm.a"],
)

cc_library(
name = "mytest",
srcs = ["mytest.cc"],
deps = ["lightgbm"],
)
```

lightgbm targt itself compiles and produces a static library, no issues.

The issue is actually using it from my libraries / binaries.

`mytest.cc`:

```cpp
#include
```

When building `//:mytest` it fails

trying to include some of its header files, due to transitive includes it fails to find transitive dependency:

```
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from bazel-out/k8-fastbuild/bin/extra/lightgbm/lightgbm/include/LightGBM/config.h:16,
from bazel-out/k8-fastbuild/bin/extra/lightgbm/lightgbm/include/LightGBM/boosting.h:8,
from mytest.cc:1:
bazel-out/k8-fastbuild/bin/extra/lightgbm/lightgbm/include/LightGBM/utils/common.h:35:10: fatal error: LightGBM/../../external_libs/fmt/include/fmt/format.h: No such file or directory
35 | #include "../../../external_libs/fmt/include/fmt/format.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

I tried modifying it for example to do `#include `, still no luck.

Any ideas / help would be appreciated.

Contributor guide

Open the contributing guide

Research direction

Start with the WORKSPACE and BUILD examples, then reproduce `//:mytest` with `--sandbox_debug`. Trace the `lightgbm` cmake target and the transitive include reported from `LightGBM/utils/common.h`; done means the `mytest.cc` consumer builds successfully with the generated static library.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.