> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Speed up your Bazel builds with Namespace

Remote caching and remote execution for [Bazel](https://bazel.build), on Namespace
compute and storage. Reuse action results across CI, local, and Devbox builds, and
run the actions themselves on workers that Namespace keeps running, so a build does
not wait for capacity to come up.

## Getting Started

### 1. Configure access

Generate a `bazelrc` that points Bazel at Namespace. Start with the cache, and add
remote execution when you want the actions to run on Namespace compute too.

> [tab] Cache only
>
> ```bash theme={null}
> nsc bazel setup --remote=false --bazelrc=~/.namespace.bazelrc
> ```
>
> This command provisions a remote Bazel cache, if needed, and writes a bazelrc with the relevant configuration options.

> [tab] Remote Execution
>
> ```bash theme={null}
> nsc bazel setup --bazelrc=~/.namespace.bazelrc
> ```
>
> This command provisions the execution cluster if needed, and writes a bazelrc with the remote executor, remote cache, and credentials.

### 2. Run Bazel

```bash theme={null}
bazel --bazelrc=~/.namespace.bazelrc build //...
```

You can pass multiple `--bazelrc` flags if you need to combine Namespace's generated
configuration with your existing project configuration. Bazel reads the files in the
order it is given them, and where two files set the same option, the last one read
wins. See [bazelrc files](https://bazel.build/run/bazelrc) for the full order, which
also covers the workspace and home rc files Bazel picks up on its own.

## Caching and Remote Execution

The [Bazel cache](https://namespace.so/docs/bazel/cache.md) shares action results across invocations and
machines. It applies to any action Bazel can cache, and the saving is largest where
compilation is slow, such as Rust and C++ codebases. The cache is shared, so CI and
local builds reuse each other's results.

[Remote Execution](https://namespace.so/docs/bazel/execution.md) runs the actions themselves on Namespace
compute, scaling a build across many workers for high parallelism. Its workers keep
low-latency access to the cache, so remotely executed actions read and write the
same artifacts as everything else. Actions can also be routed to workers on a
different platform than the machine running Bazel, which is how a Linux host can
drive a macOS build.

## Common setups

> [card] [Bazel cache from GitHub Actions](https://namespace.so/docs/bazel/cache.md#github-actions-example)
>
> Turn on Bazel caching in your Namespace runner profile. Your workflow needs no changes.

> [card] [Cross-platform builds](https://namespace.so/docs/bazel/execution.md#example-linux-host-to-macos-workers)
>
> Drive a macOS or iOS build from a Linux host by routing actions to macOS workers.

> [card] [GitHub Actions on GitHub-hosted runners](https://namespace.so/docs/bazel/cache.md#bazel-cache-from-github-hosted-runners)
>
> Reach the Namespace cache from GitHub's own runners, to try it before moving your runners.

> [card] [Bazel from a Devbox](https://namespace.so/docs/bazel/cache.md#running-bazel-from-a-devbox)
>
> Enable Bazel caching when creating a Devbox, and builds use it with no further setup.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.