{"id":13450666,"url":"https://github.com/bazelbuild/bazel-toolchains","last_synced_at":"2025-05-16T09:06:10.765Z","repository":{"id":22522714,"uuid":"95790423","full_name":"bazelbuild/bazel-toolchains","owner":"bazelbuild","description":"Repository that hosts Bazel toolchain configs for remote execution and related support tools.","archived":false,"fork":false,"pushed_at":"2025-01-29T14:36:34.000Z","size":1967,"stargazers_count":191,"open_issues_count":50,"forks_count":97,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-12T04:50:01.321Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bazelbuild.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-29T15:13:48.000Z","updated_at":"2025-03-08T16:51:31.000Z","dependencies_parsed_at":"2023-12-21T19:05:51.599Z","dependency_job_id":"c5c0e82b-6cfd-45da-ad64-5403e793768d","html_url":"https://github.com/bazelbuild/bazel-toolchains","commit_stats":null,"previous_names":[],"tags_count":128,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-toolchains","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-toolchains/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-toolchains/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-toolchains/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bazelbuild","download_url":"https://codeload.github.com/bazelbuild/bazel-toolchains/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501558,"owners_count":22081528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:00:37.139Z","updated_at":"2025-05-16T09:06:05.758Z","avatar_url":"https://github.com/bazelbuild.png","language":"Go","readme":"Bazel CI\n:---:\n[![Build status](https://badge.buildkite.com/940075452c1c5ff91dc832664c4c8f05e6ec736916688cd894.svg?branch=master)](https://buildkite.com/bazel/bazel-toolchains-postsubmit)\n\n# bazel-toolchains\n\nhttps://github.com/bazelbuild/bazel-toolchains is a repository where Google\nhosts the source code for a CLI tool that can be used to generate Bazel toolchain configs. These\nconfigs are required to configure Bazel to issue commands that will execute inside a Docker\ncontainer via a remote execution environment.\n\nThese toolchain configs include:\n* C/C++ CROSSTOOL file,\n* BUILD file with toolchain rules, and\n* wrapper scripts.\n\n# rbe_configs_gen - CLI Tool to Generate Configs\n\n[rbe_configs_gen](https://github.com/bazelbuild/bazel-toolchains/blob/master/cmd/rbe_configs_gen/rbe_configs_gen.go) is\na CLI tool written in Go that can be used to generate toolchain configs for a given combination\nof Bazel release and docker image. The output of the tool are toolchain configs in one or more of\nthe following formats:\n* Tarball\n* Config files copied directly to a local directory\n\nrbe_configs_gen requires [docker](https://docs.docker.com/get-docker/) to be installed locally and\ninternet access to work.\n\nConfig users are recommended to use the CLI tool to generate and self host their own configs.\nPre-generated configs will be provided for new releases of Bazel \u0026 the [RBE Ubuntu 16.04](https://console.cloud.google.com/marketplace/details/google/rbe-ubuntu16-04)\nwithout any SLOs. See [Pre-generated Configs](#pre-generated-configs) section below for details.\n\nThe rest of this section describes how to use the rbe_configs_gen tool.\n\n## Building\n\n### Building using Docker on Linux (Recommended)\n\nUse the [official Golang docker image](https://hub.docker.com/_/golang) to build the rbe_configs_gen\nbinary using Go 1.16. This avoids having to install the Go toolchain locally but requires\n[docker](https://docs.docker.com/get-docker/).\n\n1. Clone this repository and set it as the working directory:\n\n```bash\n$ git clone https://github.com/bazelbuild/bazel-toolchains.git\n$ cd bazel-toolchains\n```\n\n2. Run the following command:\n\n```bash\n$ docker run --rm -v $PWD:/srcdir -w /srcdir golang:1.16 go build -o rbe_configs_gen ./cmd/rbe_configs_gen/rbe_configs_gen.go\n```\n\n3. Run `rbe_configs_gen` as follows to see the flags it accepts:\n\n```\n$ ./rbe_configs_gen --help\n```\n\n### Building Locally\n\n1. Install [Go](https://golang.org/dl/) for your platform if necessary. Tested to work with Go 1.16.\n\n2. Clone this repository\n\n```bash\n$ git clone https://github.com/bazelbuild/bazel-toolchains.git\n$ cd bazel-toolchains\n```\n\n3. Build the rbe_configs_gen executable\n```\n# Use -o rbe_configs_gen.exe on Windows\n$ go build -o rbe_configs_gen ./cmd/rbe_configs_gen/rbe_configs_gen.go\n```\n\n4. Run `rbe_configs_gen` as follows to see the flags it accepts:\n\n```\n# On Linux\n$ ./rbe_configs_gen --help\n\n# On Windows\n$ rbe_configs_gen.exe\n```\n\n\n## Generating Configs\n\n### Latest Bazel Version and Output Tarball\n\nIf you'd like to generate toolchain configs for the latest available Bazel release and the toolchain\ncontainer l.gcr.io/google/rbe-ubuntu16-04:latest and produce a tarball with the generated configs\nrun:\n\n```bash\n$ ./rbe_configs_gen \\\n    --toolchain_container=l.gcr.io/google/rbe-ubuntu16-04:latest \\\n    --output_tarball=rbe_default.tar \\\n    --exec_os=linux \\\n    --target_os=linux\n```\n\nThe `exec_os` and `target_os` correspond to the Bazel\n[execution \u0026 target platforms](https://docs.bazel.build/versions/master/platforms.html)\nrespectively.\n\nYou should see a tarball file `rbe_default.tar` locally containing the generated configs.\n\n### Specific Bazel Version and Output Directory\n\nIf you'd like to generate toolchain configs for a specific Bazel release, e.g., Bazel 4.0.0 (tested\nfor versions \u003e= 3.7.2) and the toolchain container l.gcr.io/google/rbe-ubuntu16-04:latest and\ncopy the generated configs to path `configs/path` relative to a source repository at\n`/path/to/source/repo` run:\n\n```bash\n$ ./rbe_configs_gen \\\n    --bazel_version=4.0.0 \\\n    --toolchain_container=l.gcr.io/google/rbe-ubuntu16-04:latest \\\n    --output_src_root=/path/to/source/repo \\\n    --output_config_path=configs/path \\\n    --exec_os=linux \\\n    --target_os=linux\n```\n\n`/path/to/source/repo` should be the directory containing a Bazel `WORKSPACE` file. The toolchain\nconfigs will be extracted to `/path/to/source/repo/configs/path`.\n\nThe `exec_os` and `target_os` correspond to the Bazel\n[execution \u0026 target platforms](https://docs.bazel.build/versions/master/platforms.html)\nrespectively.\n\n## Using Configs\n\n### .bazelrc\n\nCopy/import a `.bazelrc` file from [here](https://github.com/bazelbuild/bazel-toolchains/tree/master/bazelrc).\nPick the file that has the highest Bazel version in the filename that's less than or equal to the\nBazel version you're using.\n\n### Option 1: Same Source Repository (Recommended)\n\nIf you [copied the generated configs](#specific-bazel-version-and-output-directory) to the source\nrepository where the rest of your code lives, and assuming the configs were copied to the path\n`configs/path` (i.e., the value specified to the flag `--output_config_path` when running\n`rbe_configs_gen`) relative to the directory containing the Bazel `WORKSPACE` file, all you need to\ndo is replace all occurences of `@rbe_default//` in your [`.bazelrc` file](#bazelrc) with `//configs/path`.\n\n### Option 2: Remote Github Repository\n\nIf you extract the contents of a\n[generated toolchain configs tarball](#specific-bazel-version-and-output-directory) into the root of\na Github repository e.g. `github.com/example/configs-repo` where this repository hosting the configs\nis different from the source repository where you'd like to use the configs, include the following\nin your `WORKSPACE`:\n\n```python\n\nload(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")\n\ngit_repository(\n    name = \"rbe_default\",\n    # Replace this with the actual commit id of the Github repo you'd like to pin to.\n    commit = \"471da0273050b88d77529484ff89741ff586f9f5\",\n    remote = \"https://github.com/example/configs-repo.git\",\n)\n\n```\n\n### Option 3: Remote Tarball Archive\n\nThen, assuming you've upload the toolchain configs tarball to a remote location available at the\nURL `https://example.com/rbe-default.tar`, include the following in your `WORKSPACE` file:\n\n```python\n\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nhttp_archive(\n    name = \"rbe_default\",\n    sha256 = \"\u003creplace this with the 64 character sha256 digest of the configs tarball\u003e\",\n    urls = [\"https://example.com/rbe-default.tar\"],\n)\n\n```\n\n### Custom Execution Properties\n\nCertain remote execution backends support custom options such as selecting the VM machine type\nremote actions run on, configuring certain docker properties if the remote actions are executed in\ndocker containers such as network access, privileged execution, allocated memory, etc. Bazel passes\non any property specified to the `exec_properties` attribute to a\n[platform](https://docs.bazel.build/versions/master/be/platform.html#platform) definition to the\nunderlying remote execution system.\n\nIf you're using RBE, continue reading to see how to specify custom execution properties.\n\nFirst, in your `WORKSPACE` file, import the latest commit of this repository (replace the commit ID\nand sha256 digest with latest commit if necessary):\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nhttp_archive(\n\tname = \"bazel_toolchains\",\n\turls = [\"https://github.com/bazelbuild/bazel-toolchains/archive/dac71231098d891e5c4b74a2078fe9343feef510.tar.gz\"],\n\tstrip_prefix = \"bazel-toolchains-dac71231098d891e5c4b74a2078fe9343feef510\",\n\tsha256 = \"56d5370eb99559b4c74f334f81bc8a298f728bd16d5a4333c865c2ad10fae3bc\",\n)\n\nload(\"@bazel_toolchains//repositories:repositories.bzl\", bazel_toolchains_repositories = \"repositories\")\nbazel_toolchains_repositories()\n```\n\nThen declare a custom platform in a `BUILD` file. For now, let's assume this is the `BUILD` file at\nthe root of your source repository (i.e., the `BUILD` file \u0026 `WORKSPACE` file are in the same\ndirectory):\n\n```python\n\nload(\"@bazel_toolchains//rules/exec_properties:exec_properties.bzl\", \"create_rbe_exec_properties_dict\")\n\nplatform(\n\tname = \"custom_platform\",\n    # Inherit from the platform target generated by 'rbe_configs_gen' assuming the generated configs\n    # were imported as a Bazel external repository named 'rbe_default'. If you extracted the\n    # generated configs elsewhere in your source repository, replace the following with the label\n    # to the 'platform' target in the generated configs.\n\tparents = [\"@rbe_default//config:platform\"],\n    # Example custom execution property instructing RBE to use e2-standard-2 GCE VMs.\n\texec_properties = create_rbe_exec_properties_dict(\n\t\tgce_machine_type = \"e2-standard-2\",\n\t),\n)\n\n```\n\nSee [here](https://github.com/bazelbuild/bazel-toolchains/blob/dac71231098d891e5c4b74a2078fe9343feef510/rules/exec_properties/exec_properties.bzl#L143)\nfor a list of parameters accepted by `create_rbe_exec_properties_dict`.\n\nFinally, in your `.bazelrc` file, replace all options specifying a platform target with\nthe above custom platform target instead. So for example, if your `.bazelrc` previously looked like\n\n```bash\n...\nbuild:remote --extra_execution_platforms=@rbe_default//config:platform\nbuild:remote --host_platform=@rbe_default//config:platform\nbuild:remote --platforms=@rbe_default//config:platform\n...\n```\n\nIt should now look like\n\n```bash\nbuild:remote --extra_execution_platforms=//:custom_platform\nbuild:remote --host_platform=//:custom_platform\nbuild:remote --platforms=//:custom_platform\n```\n\n# Pre-generated Configs\n\nPre-generated configs tarballs will be generated for every Bazel release starting with 4.0.0 \u0026 the\nlatest available [Ubuntu 16.04 Clang + JDK](https://l.gcr.io/google/rbe-ubuntu16-04:latest) container and\nuploaded to GCS.\n\n**IMPORTANT**: Ensure you read \u0026 agree with the terms of the `LICENSE` file included in the\nconfigs tarball before using pre-generated configs.\n\nBasically, never depend directly on any of the URLs mentioned below to download toolchain configs in\nproduction because they may break without warning. Pre-generated configs are only provided as a\nconvenience for experimenting with configuring Bazel for remote builds. Further, there are no\nguarantees on how long after a new release of Bazel or the Ubuntu 16.04 container mentioned above\nthe corresponding pre-generated configs will be available. It's strongly recommended to generate and\nhost your own toolchain configs by running the `rbe_config_gen` tool and test the functionality and\ncorrectness of the configs yourself before using them in production. Alternatively, you could also\ncopy pre-generated configs and host it in a location you control after verifying correctness before\nusing them in production.\n\nSee [here](#bazelrc) for instructions on how to initialize your `.bazelrc` file.\n\n## Latest Bazel and Latest Ubuntu 16.04 Container\n\n1. Examine the contents of the JSON manifest of the latest configs.\n\n```bash\n$ curl https://storage.googleapis.com/rbe-toolchain/bazel-configs/rbe-ubuntu1604/latest/manifest.json\n{\n \"bazel_version\": \"4.0.0\",\n \"toolchain_container\": \"l.gcr.io/google/rbe-ubuntu16-04:latest\",\n \"image_digest\": \"f6568d8168b14aafd1b707019927a63c2d37113a03bcee188218f99bd0327ea1\",\n \"exec_os\": \"Linux\",\n \"configs_tarball_digest\": \"c0d428774cbe70d477e1d07581d863f8dbff4ba6a66d20502d7118354a814bea\",\n \"upload_time\": \"2021-02-18T06:02:32.997892223-08:00\"\n}\n```\n\n1. The manifest indicates the configs are for Bazel 4.0.0, generated for the container\n   `l.gcr.io/google/rbe-ubuntu16-04@sha256:f6568d8168b14aafd1b707019927a63c2d37113a03bcee188218f99bd0327ea1`\n   and the sha256 digest of the uploaded configs tarball is `c0d428774cbe70d477e1d07581d863f8dbff4ba6a66d20502d7118354a814bea`.\n   To use these configs, add the following to your Bazel `WORKSPACE` file:\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nhttp_archive(\n    name = \"rbe_default\",\n    # Change the sha256 digest to the value of the `configs_tarball_digest` in the manifest you\n    # got when you ran the curl command above.\n    sha256 = \"c0d428774cbe70d477e1d07581d863f8dbff4ba6a66d20502d7118354a814bea\",\n    urls = [\"https://storage.googleapis.com/rbe-toolchain/bazel-configs/rbe-ubuntu1604/latest/rbe_default.tar\"],\n)\n```\n\n## Specific Bazel and Latest Ubuntu 16.04 Container\n\n1. Say you'd like to use configs for Bazel 4.0.0 specifically.\n\n1. Check if a manifest exists for the Bazel version you're interested in (version should be \u003e=\n   4.0.0).\n\n```bash\n# Replace \"bazel_4.0.0\" in the URL below with whatever \"bazel_\u003cversion\u003e\" you'd like to you.\n$ curl https://storage.googleapis.com/rbe-toolchain/bazel-configs/bazel_4.0.0/rbe-ubuntu1604/latest/manifest.json\n{\n \"bazel_version\": \"4.0.0\",\n \"toolchain_container\": \"l.gcr.io/google/rbe-ubuntu16-04:latest\",\n \"image_digest\": \"f6568d8168b14aafd1b707019927a63c2d37113a03bcee188218f99bd0327ea1\",\n \"exec_os\": \"Linux\",\n \"configs_tarball_digest\": \"c0d428774cbe70d477e1d07581d863f8dbff4ba6a66d20502d7118354a814bea\",\n \"upload_time\": \"2021-02-18T06:02:32.997892223-08:00\"\n}\n```\n\n1. The manifest confirms the configs are for Bazel 4.0.0, generated for the container\n   `l.gcr.io/google/rbe-ubuntu16-04@sha256:f6568d8168b14aafd1b707019927a63c2d37113a03bcee188218f99bd0327ea1`\n   and the sha256 digest of the uploaded configs tarball is `c0d428774cbe70d477e1d07581d863f8dbff4ba6a66d20502d7118354a814bea`.\n   To use these configs, add the following to your Bazel `WORKSPACE` file:\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nhttp_archive(\n    name = \"rbe_default\",\n    # Change the sha256 digest to the value of the `configs_tarball_digest` in the manifest you\n    # got when you ran the curl command above.\n    sha256 = \"c0d428774cbe70d477e1d07581d863f8dbff4ba6a66d20502d7118354a814bea\",\n    # Change \"bazel_4.0.0\" in the URL below with whatever \"bazel_\u003cversion\u003e\" you downloaded the\n    # manifest for in the previous step.\n    urls = [\"https://storage.googleapis.com/rbe-toolchain/bazel-configs/bazel_4.0.0/rbe-ubuntu1604/latest/rbe_default.tar\"],\n)\n```\n\n# Where is rbe_autoconfig?\n\nThe [rbe_autoconfig](https://github.com/bazelbuild/bazel-toolchains/blob/4.0.0/rules/rbe_repo.bzl#L896)\nBazel repository rule used to generate \u0026 use toolchain configs has been deprecated with release\n[v4.0.0](https://github.com/bazelbuild/bazel-toolchains/releases/tag/4.0.0) of this repository\nbeing the last release that supports rbe_autoconfig. Release v4.0.0 supports Bazel versions up to\n[4.0.0](https://github.com/bazelbuild/bazel/releases/tag/4.0.0).\n","funding_links":[],"categories":["Go","Tooling"],"sub_categories":["Toolchains"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazelbuild%2Fbazel-toolchains","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbazelbuild%2Fbazel-toolchains","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazelbuild%2Fbazel-toolchains/lists"}