bazel-contrib / bazel-contrib/rules_foreign_cc
Allow build pure cmake projects without ninja toolchains
- Dominant language
- Starlark
- Stars
- 737
- Forks
- 270
- PR merge metrics
- No merged PRs in 30d
Description
## The problem
Cannot build a pure cmake project without ninja toolchain.
## How to reproduce
1. Take a linux on aarch64/arm64. There is no ninja toolchain for that platform (linux/arm64).
2. Take bazel-central-registry at 648c68bd8db53a5ebc22f65031e7ff4b75e629cc.
3. Take [cmake_hello_world_lib/binary from examples](https://github.com/bazelbuild/rules_foreign_cc/tree/b7074f111e835a2e4c817220f843669ff969d24c/examples/cmake_hello_world_lib/binary):
1. Put it into a separate directory.
2. Add `MODULE.bazel` and empty `WORKSPACE`.
4. Try to build a `:binary` target.
Output for step 1:
```bash
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
$ uname -a
Linux mydevtools 5.15.0-60-generic #66-Ubuntu SMP Fri Jan 20 14:34:57 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
```
After step 3 your tree would look like this:
```bash
$ tree
.
├── BUILD.bazel
├── CMakeLists.txt
├── MODULE.bazel
├── WORKSPACE
└── src
├── CMakeLists.txt
├── hello.c
├── hello.h
└── main.c
1 directory, 8 files
$ cat MODULE.bazel
module(
name = "example",
version = "0.1",
)
bazel_dep(name = "rules_cc", version = "0.0.6")
bazel_dep(name = "rules_foreign_cc", version = "0.9.0")
```
Running the build produces an error:
```bash
$ bazel build :binary
ERROR: /home/ubuntu/Home/projects/examples/bazel-cmake-hello-world/BUILD.bazel:12:6: While resolving toolchains for target //:libhello: No matching toolchains found for types @rules_foreign_cc~0.9.0//toolchains:ninja_toolchain.
To debug, rerun with --toolchain_resolution_debug='@rules_foreign_cc~0.9.0//toolchains:ninja_toolchain'
If platforms or toolchains are a new concept for you, we'd encourage reading https://bazel.build/concepts/platforms-intro.
ERROR: Analysis of target '//:binary' failed; build aborted:
INFO: Elapsed time: 0.338s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
```
## Expected behavour
[examples/cmake_hello_world_lib/binary](https://github.com/bazelbuild/rules_foreign_cc/tree/b7074f111e835a2e4c817220f843669ff969d24c/examples/cmake_hello_world_lib/binary) just works.
Contributor guide
Research direction
Reproduce the failure using examples/cmake_hello_world_lib/binary, its BUILD.bazel, CMakeLists.txt files, and the provided ARM64 environment. Start by examining how the example resolves the ninja_toolchain, then verify that the pure CMake example builds without a matching ninja toolchain.】【。
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100