> ## 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

<Steps titleSize="h3">
  <Step title="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.

    <Tabs>
      <Tab title="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>

      <Tab title="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.
      </Tab>
    </Tabs>
  </Step>

  <Step title="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.
  </Step>
</Steps>

## Caching and Remote Execution

The [Bazel cache](/docs/bazel/cache) 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](/docs/bazel/execution) 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

<CardGroup cols={2}>
  <Card title="Bazel cache from GitHub Actions" href="/docs/bazel/cache#github-actions-example">
    Turn on Bazel caching in your Namespace runner profile. Your workflow needs no changes.
  </Card>

  <Card title="Cross-platform builds" href="/docs/bazel/execution#example-linux-host-to-macos-workers">
    Drive a macOS or iOS build from a Linux host by routing actions to macOS workers.
  </Card>

  <Card title="GitHub Actions on GitHub-hosted runners" href="/docs/bazel/cache#bazel-cache-from-github-hosted-runners">
    Reach the Namespace cache from GitHub's own runners, to try it before moving your runners.
  </Card>

  <Card title="Bazel from a Devbox" href="/docs/bazel/cache#running-bazel-from-a-devbox">
    Enable Bazel caching when creating a Devbox, and builds use it with no further setup.
  </Card>
</CardGroup>
