Name Date Size #Lines LOC

..--

.bazelci/H25-Apr-2025-5446

.bcr/H25-Apr-2025-2219

cc/H25-Apr-2025-13,54011,997

examples/H25-Apr-2025-785620

tests/H25-Apr-2025-3,8243,031

third_party/H25-Apr-2025-599513

tools/migration/H25-Apr-2025-7,9327,164

.gitignoreH A D25-Apr-20258 11

AUTHORSH A D25-Apr-2025299 107

BUILDH A D25-Apr-2025644 2619

CODEOWNERSH A D25-Apr-202547 21

CONTRIBUTING.mdH A D25-Apr-20251.1 KiB2920

ISSUE_TEMPLATE.mdH A D25-Apr-20252 KiB5735

LICENSEH A D25-Apr-202511.1 KiB202169

METADATAH A D25-Apr-2025599 2018

MODULE.bazelH A D25-Apr-2025475 1611

MODULE_LICENSE_APACHE2HD25-Apr-20250

OWNERSH A D25-Apr-202529 21

README.mdH A D25-Apr-20253.1 KiB9160

WORKSPACEH A D25-Apr-20253.5 KiB10082

renovate.jsonH A D25-Apr-202549 65

README.md

1# C++ rules for Bazel
2
3* Postsubmit [![Build status](https://badge.buildkite.com/f03592ae2d7d25a2abc2a2ba776e704823fa17fd3e061f5103.svg?branch=main)](https://buildkite.com/bazel/rules-cc)
4* Postsubmit + Current Bazel Incompatible flags [![Build status](https://badge.buildkite.com/5ba709cc33e5855078a1f8570adcf8e0a78ea93591bc0b4e81.svg?branch=master)](https://buildkite.com/bazel/rules-cc-plus-bazelisk-migrate)
5
6This repository contains a Starlark implementation of C++ rules in Bazel.
7
8The 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/).
9
10For the list of C++ rules, see the Bazel
11[documentation](https://docs.bazel.build/versions/main/be/overview.html).
12
13# Getting Started
14
15There is no need to use rules from this repository just yet. If you want to use
16`rules_cc` anyway, add the following to your `WORKSPACE` file:
17
18```starlark
19load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
20
21http_archive(
22    name = "rules_cc",
23    urls = ["https://github.com/bazelbuild/rules_cc/archive/refs/tags/<VERSION>.tar.gz"],
24    sha256 = "...",
25)
26```
27
28Then, in your `BUILD` files, import and use the rules:
29
30```starlark
31load("@rules_cc//cc:defs.bzl", "cc_library")
32
33cc_library(
34    ...
35)
36```
37
38# Using the rules_cc toolchain
39
40This repo contains an auto-detecting toolchain that expects to find tools installed on your host machine.
41This is non-hermetic, and may have varying behaviors depending on the versions of tools found.
42
43There are third-party contributed hermetic toolchains you may want to investigate:
44
45- LLVM: <https://github.com/grailbio/bazel-toolchain>
46- GCC (Linux only): <https://github.com/aspect-build/gcc-toolchain>
47- zig cc: <https://github.com/uber/hermetic_cc_toolchain>
48
49If you'd like to use the cc toolchain defined in this repo, add this to
50your WORKSPACE after you include rules_cc:
51
52```bzl
53load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")
54
55rules_cc_dependencies()
56
57rules_cc_toolchains()
58```
59
60# Migration Tools
61
62This repository also contains migration tools that can be used to migrate your
63project for Bazel incompatible changes.
64
65## Legacy fields migrator
66
67Script that migrates legacy crosstool fields into features
68([incompatible flag](https://github.com/bazelbuild/bazel/issues/6861),
69[tracking issue](https://github.com/bazelbuild/bazel/issues/5883)).
70
71TLDR:
72
73```
74bazel run @rules_cc//tools/migration:legacy_fields_migrator -- \
75  --input=my_toolchain/CROSSTOOL \
76  --inline
77```
78
79# Contributing
80
81Bazel and `rules_cc` are the work of many contributors. We appreciate your help!
82
83To contribute, please read the contribution guidelines: [CONTRIBUTING.md](https://github.com/bazelbuild/rules_cc/blob/main/CONTRIBUTING.md).
84
85Note that the `rules_cc` use the GitHub issue tracker for bug reports and feature requests only.
86For asking questions see:
87
88* [Stack Overflow](https://stackoverflow.com/questions/tagged/bazel)
89* [`rules_cc` mailing list](https://groups.google.com/forum/#!forum/cc-bazel-discuss)
90* Slack channel `#cc` on [slack.bazel.build](https://slack.bazel.build)
91