---
title: "Build with Bazel (legacy)"
description: "The legacy `lim xcode rbe` path: build a Bazel iOS workspace on a dedicated Xcode sandbox, then run or share the app."
sidebar:
  order: 3
---

If your iOS app builds with Bazel (`rules_apple`, `rules_swift`), point it at Limrun's remote build execution (RBE) backend instead of syncing sources. Bazel keeps running on your laptop or CI runner, and every Apple action (Swift compilation, asset catalogs, codesigning, bundling) runs on Limrun's Macs. Linux, Windows, and macOS clients all work, and none of them needs Xcode.

:::warning
`lim xcode rbe` is the legacy way to build with Bazel on Limrun. For new workspaces, use [`lim bazel setup`](/bazel/build-on-limrun): it builds iOS and Android targets on Limrun's build plane, needs no sandbox or tunnel, and shares one cache across your organization. This page stays for existing `lim xcode rbe` setups and for the flows that still need it: attaching a simulator to the build sandbox and uploading builds as assets.
:::

The loop has three steps:

1. **Start the RBE endpoint** with `lim xcode rbe`. It provisions an Xcode sandbox, starts the remote execution stack on it, and bridges it to a local port.
2. **Run the printed build command.** Bazel sends actions through the tunnel, and results land in the remote cache.
3. **Run, upload, or preview** the built app: install it on an attached simulator, or publish it as an asset.

## Start the endpoint

You need the `lim` CLI and an API key; the [Quickstart](/quickstart) sets up both. From the root of your Bazel workspace (the directory with `MODULE.bazel` or `WORKSPACE`), start the endpoint:

```bash
lim xcode rbe
```

The command sets everything up and prints the exact build command for your workspace, for example:

```bash
bazelisk --digest_function=sha256 build --config=limrun //App
```

Run it. The tunnel keeps running in the background, so from here on you only build.

`lim xcode rbe` did three things:

- Provisioned an Xcode sandbox, or reused your most recent one, and started the RBE stack on it.
- Opened a tunnel so the endpoint is reachable at `grpc://127.0.0.1:8980`. Change the port with `--port`.
- Generated a `.limrun/` directory in your workspace with the `--config=limrun` Bazel configuration matched to the sandbox's Xcode version, and wired a `try-import` into your `.bazelrc`.

To build with another installed Xcode, pass `--xcode-version <major>` for the newest GA release of that major, or `--xcode-version <major.minor>` to pin that exact version, which may be a beta. See [Xcode and tool versions](/ios/xcode-and-tools#choose-the-xcode-version).

Do not hand-edit `.limrun/`; the next `lim xcode rbe` regenerates it. To add your own flags to the Limrun build path, put them in `user.limrun.bazelrc` at the workspace root. The generated config imports it last, so your `build:limrun --...` lines win and survive regeneration.

:::note
Keep `--digest_function=sha256` in front of `build`, exactly as the printed command has it. The Limrun cache is SHA256-only while Bazel 9 defaults to BLAKE3, and the flag is a startup flag, so it cannot live inside `--config=limrun`.
:::

## Run it on a simulator

`lim xcode rbe` is build-only until you attach a simulator. Attach one at startup with `--ios`, or at any point later:

```bash
lim xcode rbe --ios      # attach at startup; torn down on --stop
# or later:
lim ios create --attach  # attach to the running RBE instance
```

With a simulator attached, every successful `--config=limrun` build installs and relaunches the app on it. There is no separate install step, and attaching also installs the last successful build immediately.

## Upload builds as assets

To publish builds to [Asset Storage](/platform/asset-storage) for [PR previews](/ci/pr-previews), installs on other simulators, or CI artifacts, arm uploads when you start the tunnel:

```bash
lim xcode rbe --auto-upload preview/my-app --upload-ttl 24h
```

Every successful build then refreshes the `preview/my-app` asset, with no post-build step. Upload results are written to `.limrun/rbe.log`. To upload a single build after the fact instead:

```bash
lim xcode rbe upload preview/my-app --ttl 24h
```

TTLs are optional Go durations (`24h`, `30m`). Each upload without one pushes the asset's expiry to 14 days from that upload. Anyone in your organization can then open the build in a browser at `https://console.limrun.com/preview?asset=preview/my-app&platform=ios`.

To build on every pull request from CI, see the Bazel workflow in [GitHub Actions recipes](/ci/github-actions). For preview comments on pull requests, [`limrun-inc/ios-preview-action`](https://github.com/limrun-inc/ios-preview-action) detects a Bazel workspace and does the build, upload, comment, and cleanup in one step; see [PR previews](/ci/pr-previews).

## Stop the endpoint

Stop the tunnel and the remote stack, then delete the sandbox when you are done with it:

```bash
lim xcode rbe --stop                  # stops the tunnel and the remote stack (~20s)
lim xcode delete <xcode-instance-id>  # delete the sandbox
```

The tunnel runs as a background process by default. Pass `--no-daemon` to keep it in the foreground, for example while debugging.

## Limits and behavior

- **The built `.ipa` does not land on your machine.** The generated config carries `--remote_download_outputs=minimal`. Bazel prints its usual `Target //App:App up-to-date: .../App.ipa` line, but the artifact stays in the sandbox's cache, where auto-install and uploads read it. If you need the file locally, add `--remote_download_outputs=toplevel` to the build command.
- **Run `lim xcode rbe` from the workspace root**, not a subdirectory. It writes `.limrun/` there and fails otherwise.
- **Re-run after an Xcode change.** The generated config pins the sandbox's Xcode version. After a fleet upgrade or an `--xcode-version` switch, run `lim xcode rbe --stop` and then `lim xcode rbe` to refresh it.
- **Changing `--auto-upload` needs a restart.** The CLI refuses to re-arm a running tunnel with a different upload configuration rather than silently ignoring it. Run `--stop`, then start again.

## Next steps

**[PR previews](/ci/pr-previews)**

Post a live preview link on every pull request, for Bazel and xcodebuild projects alike.

**[Run a simulator](/ios/run-simulator)**

Drive the simulator your build installs onto: taps, screenshots, recordings, logs.

**[Guide: Bazel from Claude Code on the web](/guides/ios-bazel-claude-code-web)**

Change a Bazel template app with a cloud agent and review it in a pull request.

**[Build with Xcode](/ios/build-with-xcode)**

The `xcodebuild` path for projects without Bazel.
