2019-01-04 14:14:30 +00:00
# C++ rules for Bazel
2021-10-26 21:15:49 +00:00
* Postsubmit [![Build status ](https://badge.buildkite.com/f03592ae2d7d25a2abc2a2ba776e704823fa17fd3e061f5103.svg?branch=main )](https://buildkite.com/bazel/rules-cc)
2019-10-31 19:01:27 +00:00
* Postsubmit + Current Bazel Incompatible flags [![Build status ](https://badge.buildkite.com/5ba709cc33e5855078a1f8570adcf8e0a78ea93591bc0b4e81.svg?branch=master )](https://buildkite.com/bazel/rules-cc-plus-bazelisk-migrate)
2019-01-15 16:54:09 +00:00
2023-07-19 22:32:02 +00:00
This repository contains a Starlark implementation of C++ rules in Bazel.
2019-01-04 14:14:30 +00:00
The rules are being incrementally converted from their native implementations in the [Bazel source tree ](https://source.bazel.build/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/cpp/ ).
For the list of C++ rules, see the Bazel
2021-10-26 21:15:49 +00:00
[documentation ](https://docs.bazel.build/versions/main/be/overview.html ).
2019-01-04 14:14:30 +00:00
# Getting Started
There is no need to use rules from this repository just yet. If you want to use
2019-12-12 05:49:12 +00:00
`rules_cc` anyway, add the following to your `WORKSPACE` file:
2019-01-04 14:14:30 +00:00
2020-02-03 06:25:33 +00:00
```starlark
2019-01-04 14:14:30 +00:00
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2019-12-12 05:49:12 +00:00
2019-01-04 14:14:30 +00:00
http_archive(
name = "rules_cc",
2023-01-11 12:32:58 +00:00
urls = ["https://github.com/bazelbuild/rules_cc/archive/refs/tags/< VERSION > .tar.gz"],
sha256 = "...",
2019-01-04 14:14:30 +00:00
)
```
2019-12-12 05:49:12 +00:00
Then, in your `BUILD` files, import and use the rules:
2019-01-04 14:14:30 +00:00
2020-02-03 06:25:33 +00:00
```starlark
2019-06-18 07:21:29 +00:00
load("@rules_cc//cc:defs.bzl", "cc_library")
2019-12-12 05:49:12 +00:00
2019-01-04 14:14:30 +00:00
cc_library(
...
)
```
2021-05-27 20:39:15 +00:00
# Using the rules_cc toolchain
2023-07-19 22:32:02 +00:00
This repo contains an auto-detecting toolchain that expects to find tools installed on your host machine.
This is non-hermetic, and may have varying behaviors depending on the versions of tools found.
There are third-party contributed hermetic toolchains you may want to investigate:
2024-08-14 21:57:09 +00:00
- LLVM: < https: // github . com / bazel-contrib / toolchains_llvm >
- GCC (Linux only): < https: // github . com / f0rmiga / gcc-toolchain >
2023-07-19 22:32:02 +00:00
- zig cc: < https: // github . com / uber / hermetic_cc_toolchain >
If you'd like to use the cc toolchain defined in this repo, add this to
2021-05-27 20:39:15 +00:00
your WORKSPACE after you include rules_cc:
```bzl
load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")
rules_cc_dependencies()
rules_cc_toolchains()
```
2019-01-04 14:14:30 +00:00
# Migration Tools
This repository also contains migration tools that can be used to migrate your
project for Bazel incompatible changes.
2019-01-11 14:18:10 +00:00
## Legacy fields migrator
Script that migrates legacy crosstool fields into features
([incompatible flag](https://github.com/bazelbuild/bazel/issues/6861),
2019-01-14 17:06:11 +00:00
[tracking issue ](https://github.com/bazelbuild/bazel/issues/5883 )).
2019-01-11 14:18:10 +00:00
TLDR:
2019-12-12 05:49:12 +00:00
```
bazel run @rules_cc//tools/migration:legacy_fields_migrator -- \
--input=my_toolchain/CROSSTOOL \
--inline
```
2019-02-26 13:10:49 +00:00
# Contributing
2019-12-12 05:49:12 +00:00
Bazel and `rules_cc` are the work of many contributors. We appreciate your help!
2019-02-26 13:10:49 +00:00
2021-10-26 21:15:49 +00:00
To contribute, please read the contribution guidelines: [CONTRIBUTING.md ](https://github.com/bazelbuild/rules_cc/blob/main/CONTRIBUTING.md ).
2019-02-26 13:10:49 +00:00
2019-12-12 05:49:12 +00:00
Note that the `rules_cc` use the GitHub issue tracker for bug reports and feature requests only.
2019-02-26 13:10:49 +00:00
For asking questions see:
* [Stack Overflow ](https://stackoverflow.com/questions/tagged/bazel )
2019-12-12 05:49:12 +00:00
* [`rules_cc` mailing list ](https://groups.google.com/forum/#!forum/cc-bazel-discuss )
2019-06-15 06:38:07 +00:00
* Slack channel `#cc` on [slack.bazel.build ](https://slack.bazel.build )